Skip to main content

wasmtime_test_util/
wasmtime_wast.rs

1use crate::wast;
2use wasmtime::Config;
3
4/// Helper method to apply `wast_config` to `config`.
5pub fn apply_wast_config(config: &mut Config, wast_config: &wast::WastConfig) {
6    use wasmtime_environ::TripleExt;
7    use wast::{Collector, Compiler};
8
9    config.strategy(match wast_config.compiler {
10        Compiler::CraneliftNative | Compiler::CraneliftPulley => wasmtime::Strategy::Cranelift,
11        Compiler::Winch => wasmtime::Strategy::Winch,
12    });
13    if let Compiler::CraneliftPulley = wast_config.compiler {
14        config
15            .target(&target_lexicon::Triple::pulley_host().to_string())
16            .unwrap();
17    }
18    config.collector(match wast_config.collector {
19        Collector::Auto => wasmtime::Collector::Auto,
20        Collector::Null => wasmtime::Collector::Null,
21        Collector::DeferredReferenceCounting => wasmtime::Collector::DeferredReferenceCounting,
22        Collector::Copying => wasmtime::Collector::Copying,
23    });
24}
25
26/// Helper method to apply `test_config` to `config`.
27pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) {
28    let wast::TestConfig {
29        bulk_memory,
30        memory64,
31        custom_page_sizes,
32        multi_memory,
33        threads,
34        shared_everything_threads,
35        gc,
36        function_references,
37        relaxed_simd,
38        reference_types,
39        tail_call,
40        extended_const,
41        wide_arithmetic,
42        branch_hinting,
43        component_model_async,
44        component_model_more_async_builtins,
45        component_model_async_stackful,
46        component_model_threading,
47        component_model_error_context,
48        component_model_gc,
49        component_model_map,
50        component_model_memory64,
51        component_model_fixed_length_lists,
52        component_model_implements,
53        nan_canonicalization,
54        simd,
55        exceptions,
56        legacy_exceptions,
57        stack_switching,
58        custom_descriptors,
59
60        hogs_memory: _,
61        gc_types: _,
62        spec_test: _,
63    } = *test_config;
64    // Note that all of these proposals/features are currently default-off to
65    // ensure that we annotate all tests accurately with what features they
66    // need, even in the future when features are stabilized.
67    let bulk_memory = bulk_memory.unwrap_or(false);
68    let memory64 = memory64.unwrap_or(false);
69    let custom_page_sizes = custom_page_sizes.unwrap_or(false);
70    let multi_memory = multi_memory.unwrap_or(false);
71    let threads = threads.unwrap_or(false);
72    let shared_everything_threads = shared_everything_threads.unwrap_or(false);
73    let gc = gc.unwrap_or(false);
74    let tail_call = tail_call.unwrap_or(false);
75    let extended_const = extended_const.unwrap_or(false);
76    let wide_arithmetic = wide_arithmetic.unwrap_or(false);
77    let branch_hinting = branch_hinting.unwrap_or(false);
78    let component_model_async = component_model_async.unwrap_or(false);
79    let component_model_more_async_builtins = component_model_more_async_builtins.unwrap_or(false);
80    let component_model_async_stackful = component_model_async_stackful.unwrap_or(false);
81    let component_model_threading = component_model_threading.unwrap_or(false);
82    let component_model_error_context = component_model_error_context.unwrap_or(false);
83    let component_model_gc = component_model_gc.unwrap_or(false);
84    let component_model_map = component_model_map.unwrap_or(false);
85    let component_model_memory64 = component_model_memory64.unwrap_or(false);
86    let component_model_fixed_length_lists = component_model_fixed_length_lists.unwrap_or(false);
87    let component_model_implements = component_model_implements.unwrap_or(false);
88    let nan_canonicalization = nan_canonicalization.unwrap_or(false);
89    let relaxed_simd = relaxed_simd.unwrap_or(false);
90    let legacy_exceptions = legacy_exceptions.unwrap_or(false);
91    let stack_switching = stack_switching.unwrap_or(false);
92
93    // Some proposals in wasm depend on previous proposals. For example the gc
94    // proposal depends on function-references which depends on reference-types.
95    // To avoid needing to enable all of them at once implicitly enable
96    // downstream proposals once the end proposal is enabled (e.g. when enabling
97    // gc that also enables function-references and reference-types).
98    let function_references = gc || function_references.unwrap_or(false);
99    let reference_types = function_references || reference_types.unwrap_or(false);
100    let simd = relaxed_simd || simd.unwrap_or(false);
101
102    let exceptions = stack_switching || exceptions.unwrap_or(false);
103
104    // Not implemented in Wasmtime yet.
105    let _custom_descriptors = custom_descriptors.unwrap_or(false);
106
107    config
108        .wasm_bulk_memory(bulk_memory)
109        .wasm_multi_memory(multi_memory)
110        .wasm_threads(threads)
111        .wasm_shared_everything_threads(shared_everything_threads)
112        .wasm_memory64(memory64)
113        .wasm_function_references(function_references)
114        .wasm_gc(gc)
115        .wasm_reference_types(reference_types)
116        .wasm_relaxed_simd(relaxed_simd)
117        .wasm_simd(simd)
118        .wasm_tail_call(tail_call)
119        .wasm_custom_page_sizes(custom_page_sizes)
120        .wasm_extended_const(extended_const)
121        .wasm_wide_arithmetic(wide_arithmetic)
122        .wasm_branch_hinting(branch_hinting)
123        .wasm_component_model_async(component_model_async)
124        .wasm_component_model_more_async_builtins(component_model_more_async_builtins)
125        .wasm_component_model_async_stackful(component_model_async_stackful)
126        .wasm_component_model_threading(component_model_threading)
127        .wasm_component_model_error_context(component_model_error_context)
128        .wasm_component_model_gc(component_model_gc)
129        .wasm_component_model_map(component_model_map)
130        .wasm_component_model_memory64(component_model_memory64)
131        .wasm_component_model_fixed_length_lists(component_model_fixed_length_lists)
132        .wasm_component_model_implements(component_model_implements)
133        .wasm_exceptions(exceptions)
134        .wasm_stack_switching(stack_switching)
135        .cranelift_nan_canonicalization(nan_canonicalization);
136    #[expect(deprecated, reason = "forwarding legacy-exceptions")]
137    config.wasm_legacy_exceptions(legacy_exceptions);
138}