Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/test-util/src/wasmtime_wast.rs
3069 views
1
use crate::wast;
2
use wasmtime::Config;
3
4
/// Helper method to apply `wast_config` to `config`.
5
pub 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`.
26
pub 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
component_model_fixed_length_lists,
47
nan_canonicalization,
48
simd,
49
exceptions,
50
legacy_exceptions,
51
stack_switching,
52
custom_descriptors,
53
54
hogs_memory: _,
55
gc_types: _,
56
spec_test: _,
57
} = *test_config;
58
// Note that all of these proposals/features are currently default-off to
59
// ensure that we annotate all tests accurately with what features they
60
// need, even in the future when features are stabilized.
61
let memory64 = memory64.unwrap_or(false);
62
let custom_page_sizes = custom_page_sizes.unwrap_or(false);
63
let multi_memory = multi_memory.unwrap_or(false);
64
let threads = threads.unwrap_or(false);
65
let shared_everything_threads = shared_everything_threads.unwrap_or(false);
66
let gc = gc.unwrap_or(false);
67
let tail_call = tail_call.unwrap_or(false);
68
let extended_const = extended_const.unwrap_or(false);
69
let wide_arithmetic = wide_arithmetic.unwrap_or(false);
70
let component_model_async = component_model_async.unwrap_or(false);
71
let component_model_async_builtins = component_model_async_builtins.unwrap_or(false);
72
let component_model_async_stackful = component_model_async_stackful.unwrap_or(false);
73
let component_model_threading = component_model_threading.unwrap_or(false);
74
let component_model_error_context = component_model_error_context.unwrap_or(false);
75
let component_model_gc = component_model_gc.unwrap_or(false);
76
let component_model_fixed_length_lists = component_model_fixed_length_lists.unwrap_or(false);
77
let nan_canonicalization = nan_canonicalization.unwrap_or(false);
78
let relaxed_simd = relaxed_simd.unwrap_or(false);
79
let legacy_exceptions = legacy_exceptions.unwrap_or(false);
80
let stack_switching = stack_switching.unwrap_or(false);
81
82
// Some proposals in wasm depend on previous proposals. For example the gc
83
// proposal depends on function-references which depends on reference-types.
84
// To avoid needing to enable all of them at once implicitly enable
85
// downstream proposals once the end proposal is enabled (e.g. when enabling
86
// gc that also enables function-references and reference-types).
87
let function_references = gc || function_references.unwrap_or(false);
88
let reference_types = function_references || reference_types.unwrap_or(false);
89
let simd = relaxed_simd || simd.unwrap_or(false);
90
91
let exceptions = stack_switching || exceptions.unwrap_or(false);
92
93
// Not implemented in Wasmtime yet.
94
let _custom_descriptors = custom_descriptors.unwrap_or(false);
95
96
config
97
.wasm_multi_memory(multi_memory)
98
.wasm_threads(threads)
99
.wasm_shared_everything_threads(shared_everything_threads)
100
.wasm_memory64(memory64)
101
.wasm_function_references(function_references)
102
.wasm_gc(gc)
103
.wasm_reference_types(reference_types)
104
.wasm_relaxed_simd(relaxed_simd)
105
.wasm_simd(simd)
106
.wasm_tail_call(tail_call)
107
.wasm_custom_page_sizes(custom_page_sizes)
108
.wasm_extended_const(extended_const)
109
.wasm_wide_arithmetic(wide_arithmetic)
110
.wasm_component_model_async(component_model_async)
111
.wasm_component_model_async_builtins(component_model_async_builtins)
112
.wasm_component_model_async_stackful(component_model_async_stackful)
113
.wasm_component_model_threading(component_model_threading)
114
.wasm_component_model_error_context(component_model_error_context)
115
.wasm_component_model_gc(component_model_gc)
116
.wasm_component_model_fixed_length_lists(component_model_fixed_length_lists)
117
.wasm_exceptions(exceptions)
118
.wasm_stack_switching(stack_switching)
119
.cranelift_nan_canonicalization(nan_canonicalization);
120
#[expect(deprecated, reason = "forwarding legacy-exceptions")]
121
config.wasm_legacy_exceptions(legacy_exceptions);
122
}
123
124