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    });
23}
24
25/// Helper method to apply `test_config` to `config`.
26pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) {
27    let wast::TestConfig {
28        memory64,
29        custom_page_sizes,
30        multi_memory,
31        threads,
32        shared_everything_threads,
33        gc,
34        function_references,
35        relaxed_simd,
36        reference_types,
37        tail_call,
38        extended_const,
39        wide_arithmetic,
40        component_model_async,
41        component_model_async_builtins,
42        component_model_async_stackful,
43        component_model_threading,
44        component_model_error_context,
45        component_model_gc,
46        nan_canonicalization,
47        simd,
48        exceptions,
49        legacy_exceptions,
50        stack_switching,
51        custom_descriptors,
52
53        hogs_memory: _,
54        gc_types: _,
55        spec_test: _,
56    } = *test_config;
57    // Note that all of these proposals/features are currently default-off to
58    // ensure that we annotate all tests accurately with what features they
59    // need, even in the future when features are stabilized.
60    let memory64 = memory64.unwrap_or(false);
61    let custom_page_sizes = custom_page_sizes.unwrap_or(false);
62    let multi_memory = multi_memory.unwrap_or(false);
63    let threads = threads.unwrap_or(false);
64    let shared_everything_threads = shared_everything_threads.unwrap_or(false);
65    let gc = gc.unwrap_or(false);
66    let tail_call = tail_call.unwrap_or(false);
67    let extended_const = extended_const.unwrap_or(false);
68    let wide_arithmetic = wide_arithmetic.unwrap_or(false);
69    let component_model_async = component_model_async.unwrap_or(false);
70    let component_model_async_builtins = component_model_async_builtins.unwrap_or(false);
71    let component_model_async_stackful = component_model_async_stackful.unwrap_or(false);
72    let component_model_threading = component_model_threading.unwrap_or(false);
73    let component_model_error_context = component_model_error_context.unwrap_or(false);
74    let component_model_gc = component_model_gc.unwrap_or(false);
75    let nan_canonicalization = nan_canonicalization.unwrap_or(false);
76    let relaxed_simd = relaxed_simd.unwrap_or(false);
77    let legacy_exceptions = legacy_exceptions.unwrap_or(false);
78    let stack_switching = stack_switching.unwrap_or(false);
79
80    // Some proposals in wasm depend on previous proposals. For example the gc
81    // proposal depends on function-references which depends on reference-types.
82    // To avoid needing to enable all of them at once implicitly enable
83    // downstream proposals once the end proposal is enabled (e.g. when enabling
84    // gc that also enables function-references and reference-types).
85    let function_references = gc || function_references.unwrap_or(false);
86    let reference_types = function_references || reference_types.unwrap_or(false);
87    let simd = relaxed_simd || simd.unwrap_or(false);
88
89    let exceptions = stack_switching || exceptions.unwrap_or(false);
90
91    // Not implemented in Wasmtime yet.
92    let _custom_descriptors = custom_descriptors.unwrap_or(false);
93
94    config
95        .wasm_multi_memory(multi_memory)
96        .wasm_threads(threads)
97        .wasm_shared_everything_threads(shared_everything_threads)
98        .wasm_memory64(memory64)
99        .wasm_function_references(function_references)
100        .wasm_gc(gc)
101        .wasm_reference_types(reference_types)
102        .wasm_relaxed_simd(relaxed_simd)
103        .wasm_simd(simd)
104        .wasm_tail_call(tail_call)
105        .wasm_custom_page_sizes(custom_page_sizes)
106        .wasm_extended_const(extended_const)
107        .wasm_wide_arithmetic(wide_arithmetic)
108        .wasm_component_model_async(component_model_async)
109        .wasm_component_model_async_builtins(component_model_async_builtins)
110        .wasm_component_model_async_stackful(component_model_async_stackful)
111        .wasm_component_model_threading(component_model_threading)
112        .wasm_component_model_error_context(component_model_error_context)
113        .wasm_component_model_gc(component_model_gc)
114        .wasm_exceptions(exceptions)
115        .wasm_stack_switching(stack_switching)
116        .cranelift_nan_canonicalization(nan_canonicalization);
117    #[expect(deprecated, reason = "forwarding legacy-exceptions")]
118    config.wasm_legacy_exceptions(legacy_exceptions);
119}