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        compact_imports,
44        component_model_async,
45        component_model_more_async_builtins,
46        component_model_async_stackful,
47        component_model_threading,
48        component_model_error_context,
49        component_model_gc,
50        component_model_map,
51        component_model_memory64,
52        component_model_fixed_length_lists,
53        component_model_implements,
54        component_model_canonical_names,
55        component_model_accessors,
56        nan_canonicalization,
57        simd,
58        exceptions,
59        legacy_exceptions,
60        stack_switching,
61        custom_descriptors,
62        gc_types,
63
64        hogs_memory: _,
65        spec_test: _,
66    } = *test_config;
67    // Note that all of these proposals/features are currently default-off to
68    // ensure that we annotate all tests accurately with what features they
69    // need, even in the future when features are stabilized.
70    let bulk_memory = bulk_memory.unwrap_or(false);
71    let memory64 = memory64.unwrap_or(false);
72    let custom_page_sizes = custom_page_sizes.unwrap_or(false);
73    let multi_memory = multi_memory.unwrap_or(false);
74    let threads = threads.unwrap_or(false);
75    let shared_everything_threads = shared_everything_threads.unwrap_or(false);
76    let gc = gc.unwrap_or(false);
77    let tail_call = tail_call.unwrap_or(false);
78    let extended_const = extended_const.unwrap_or(false);
79    let wide_arithmetic = wide_arithmetic.unwrap_or(false);
80    let branch_hinting = branch_hinting.unwrap_or(false);
81    let compact_imports = compact_imports.unwrap_or(false);
82    let component_model_async = component_model_async.unwrap_or(false);
83    let component_model_more_async_builtins = component_model_more_async_builtins.unwrap_or(false);
84    let component_model_async_stackful = component_model_async_stackful.unwrap_or(false);
85    let component_model_threading = component_model_threading.unwrap_or(false);
86    let component_model_error_context = component_model_error_context.unwrap_or(false);
87    let component_model_gc = component_model_gc.unwrap_or(false);
88    let component_model_map = component_model_map.unwrap_or(false);
89    let component_model_memory64 = component_model_memory64.unwrap_or(false);
90    let component_model_fixed_length_lists = component_model_fixed_length_lists.unwrap_or(false);
91    let component_model_implements = component_model_implements.unwrap_or(false);
92    let component_model_canonical_names = component_model_canonical_names.unwrap_or(false);
93    let component_model_accessors = component_model_accessors.unwrap_or(false);
94    let nan_canonicalization = nan_canonicalization.unwrap_or(false);
95    let relaxed_simd = relaxed_simd.unwrap_or(false);
96    let legacy_exceptions = legacy_exceptions.unwrap_or(false);
97    let stack_switching = stack_switching.unwrap_or(false);
98
99    // Some proposals in wasm depend on previous proposals. For example the gc
100    // proposal depends on function-references which depends on reference-types.
101    // To avoid needing to enable all of them at once implicitly enable
102    // downstream proposals once the end proposal is enabled (e.g. when enabling
103    // gc that also enables function-references and reference-types).
104    let function_references = gc || function_references.unwrap_or(false);
105    let reference_types =
106        function_references || component_model_async || reference_types.unwrap_or(false);
107    let simd = relaxed_simd || simd.unwrap_or(false);
108
109    let exceptions = stack_switching || exceptions.unwrap_or(false);
110    let gc_types = gc || exceptions || reference_types || gc_types.unwrap_or(false);
111
112    // Not implemented in Wasmtime yet.
113    let _custom_descriptors = custom_descriptors.unwrap_or(false);
114
115    config
116        .wasm_bulk_memory(bulk_memory)
117        .wasm_multi_memory(multi_memory)
118        .wasm_threads(threads)
119        .wasm_shared_everything_threads(shared_everything_threads)
120        .wasm_memory64(memory64)
121        .wasm_function_references(function_references)
122        .wasm_gc(gc)
123        .wasm_reference_types(reference_types)
124        .wasm_relaxed_simd(relaxed_simd)
125        .wasm_simd(simd)
126        .wasm_tail_call(tail_call)
127        .wasm_custom_page_sizes(custom_page_sizes)
128        .wasm_extended_const(extended_const)
129        .wasm_wide_arithmetic(wide_arithmetic)
130        .wasm_branch_hinting(branch_hinting)
131        .wasm_compact_imports(compact_imports)
132        .wasm_component_model_async(component_model_async)
133        .wasm_component_model_more_async_builtins(component_model_more_async_builtins)
134        .wasm_component_model_async_stackful(component_model_async_stackful)
135        .wasm_component_model_threading(component_model_threading)
136        .wasm_component_model_error_context(component_model_error_context)
137        .wasm_component_model_gc(component_model_gc)
138        .wasm_component_model_map(component_model_map)
139        .wasm_component_model_memory64(component_model_memory64)
140        .wasm_component_model_fixed_length_lists(component_model_fixed_length_lists)
141        .wasm_component_model_implements(component_model_implements)
142        .wasm_component_model_canonical_names(component_model_canonical_names)
143        .wasm_component_model_accessors(component_model_accessors)
144        .wasm_exceptions(exceptions)
145        .wasm_stack_switching(stack_switching)
146        .gc_support(gc_types)
147        .cranelift_nan_canonicalization(nan_canonicalization);
148    #[expect(deprecated, reason = "forwarding legacy-exceptions")]
149    config.wasm_legacy_exceptions(legacy_exceptions);
150}