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