Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Add accessors flag to wasmtime CLI (#14497)

Ben Visness4b3cef0268cf
diff --git a/crates/c-api/include/wasmtime/config.h b/crates/c-api/include/wasmtime/config.h
index 591901c46f..d20b7916d4 100644
--- a/crates/c-api/include/wasmtime/config.h
+++ b/crates/c-api/include/wasmtime/config.h
@@ -934,6 +934,15 @@ WASMTIME_CONFIG_PROP(void, wasm_component_model_implements, bool)
*/
WASMTIME_CONFIG_PROP(void, wasm_component_model_canonical_names, bool)
+/**
+ * \brief Configures whether the WebAssembly component-model accessors
+ * (`[get]` and `[set]`) support will be enabled for compilation.
+ *
+ * For more information see the Rust documentation at
+ * https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.wasm_component_model_accessors.
+ */
+WASMTIME_CONFIG_PROP(void, wasm_component_model_accessors, bool)
+
#endif // WASMTIME_FEATURE_COMPONENT_MODEL
#ifdef WASMTIME_FEATURE_COMPONENT_MODEL_ASYNC
diff --git a/crates/c-api/src/component/component.rs b/crates/c-api/src/component/component.rs
index 56d2d718dd..cc71dc0d2c 100644
--- a/crates/c-api/src/component/component.rs
+++ b/crates/c-api/src/component/component.rs
@@ -34,6 +34,14 @@ pub extern "C" fn wasmtime_config_wasm_component_model_canonical_names_set(
c.config.wasm_component_model_canonical_names(enable);
}
+#[unsafe(no_mangle)]
+pub extern "C" fn wasmtime_config_wasm_component_model_accessors_set(
+ c: &mut wasm_config_t,
+ enable: bool,
+) {
+ c.config.wasm_component_model_accessors(enable);
+}
+
#[unsafe(no_mangle)]
#[cfg(feature = "component-model-async")]
pub extern "C" fn wasmtime_config_wasm_component_model_async_set(
diff --git a/crates/cli-flags/src/lib.rs b/crates/cli-flags/src/lib.rs
index 67d3b5be7e..89b02b0db5 100644
--- a/crates/cli-flags/src/lib.rs
+++ b/crates/cli-flags/src/lib.rs
@@ -534,6 +534,9 @@ wasmtime_option_group! {
/// Component model support for canonical names, corresponds to the
/// πŸ”— emoji in the upstream spec.
pub component_model_canonical_names: Option<bool>,
+ /// Component model support for `[get]` and `[set]` accessors,
+ /// corresponds to the πŸ“‘ emoji in the upstream spec.
+ pub component_model_accessors: Option<bool>,
/// Whether or not any concurrency infrastructure in Wasmtime is
/// enabled or not.
pub concurrency_support: Option<bool>,
@@ -1358,6 +1361,7 @@ impl CommonOptions {
("component-model", component_model_fixed_length_lists, wasm_component_model_fixed_length_lists)
("component-model", component_model_implements, wasm_component_model_implements)
("component-model", component_model_canonical_names, wasm_component_model_canonical_names)
+ ("component-model", component_model_accessors, wasm_component_model_accessors)
("component-model", component_model_memory64, wasm_component_model_memory64)
("threads", threads, wasm_threads)
("gc", gc, wasm_gc)
@@ -1536,6 +1540,7 @@ impl CommonOptions {
component_model_canonical_names: Some(
features.contains(WasmFeatures::CM_CANON_NAMES),
),
+ component_model_accessors: Some(features.contains(WasmFeatures::CM_ACCESSORS)),
component_model_map: Some(features.contains(WasmFeatures::CM_MAP)),
component_model_memory64: Some(features.contains(WasmFeatures::CM64)),
component_model_more_async_builtins: Some(
diff --git a/crates/fuzzing/src/generators/config.rs b/crates/fuzzing/src/generators/config.rs
index cd0630b4b9..db08be6a17 100644
--- a/crates/fuzzing/src/generators/config.rs
+++ b/crates/fuzzing/src/generators/config.rs
@@ -151,6 +151,7 @@ impl Config {
component_model_fixed_length_lists,
component_model_implements,
component_model_canonical_names,
+ component_model_accessors,
simd,
exceptions,
legacy_exceptions: _,
@@ -183,6 +184,7 @@ impl Config {
self.module_config.component_model_implements = component_model_implements.unwrap_or(false);
self.module_config.component_model_canonical_names =
component_model_canonical_names.unwrap_or(false);
+ self.module_config.component_model_accessors = component_model_accessors.unwrap_or(false);
self.module_config.stack_switching = stack_switching.unwrap_or(false);
self.wasmtime.branch_hinting = branch_hinting.unwrap_or(false);
@@ -344,6 +346,7 @@ impl Config {
cfg.wasm.component_model_implements = Some(self.module_config.component_model_implements);
cfg.wasm.component_model_canonical_names =
Some(self.module_config.component_model_canonical_names);
+ cfg.wasm.component_model_accessors = Some(self.module_config.component_model_accessors);
cfg.wasm.custom_page_sizes = Some(self.module_config.config.custom_page_sizes_enabled);
cfg.wasm.compact_imports = Some(self.module_config.config.compact_imports_enabled);
cfg.wasm.epoch_interruption = Some(self.wasmtime.epoch_interruption);
diff --git a/crates/fuzzing/src/generators/module.rs b/crates/fuzzing/src/generators/module.rs
index 0f52f40976..896b047bcc 100644
--- a/crates/fuzzing/src/generators/module.rs
+++ b/crates/fuzzing/src/generators/module.rs
@@ -27,6 +27,7 @@ pub struct ModuleConfig {
pub component_model_fixed_length_lists: bool,
pub component_model_implements: bool,
pub component_model_canonical_names: bool,
+ pub component_model_accessors: bool,
pub legacy_exceptions: bool,
pub shared_memory: bool,
pub stack_switching: bool,
@@ -91,6 +92,7 @@ impl<'a> Arbitrary<'a> for ModuleConfig {
component_model_fixed_length_lists: false,
component_model_implements: false,
component_model_canonical_names: false,
+ component_model_accessors: false,
legacy_exceptions: false,
shared_memory: false,
stack_switching: false,
diff --git a/crates/test-util/src/wasmtime_wast.rs b/crates/test-util/src/wasmtime_wast.rs
index b34099eaac..e204102c56 100644
--- a/crates/test-util/src/wasmtime_wast.rs
+++ b/crates/test-util/src/wasmtime_wast.rs
@@ -52,6 +52,7 @@ pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) {
component_model_fixed_length_lists,
component_model_implements,
component_model_canonical_names,
+ component_model_accessors,
nan_canonicalization,
simd,
exceptions,
@@ -89,6 +90,7 @@ pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) {
let component_model_fixed_length_lists = component_model_fixed_length_lists.unwrap_or(false);
let component_model_implements = component_model_implements.unwrap_or(false);
let component_model_canonical_names = component_model_canonical_names.unwrap_or(false);
+ let component_model_accessors = component_model_accessors.unwrap_or(false);
let nan_canonicalization = nan_canonicalization.unwrap_or(false);
let relaxed_simd = relaxed_simd.unwrap_or(false);
let legacy_exceptions = legacy_exceptions.unwrap_or(false);
@@ -138,6 +140,7 @@ pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) {
.wasm_component_model_fixed_length_lists(component_model_fixed_length_lists)
.wasm_component_model_implements(component_model_implements)
.wasm_component_model_canonical_names(component_model_canonical_names)
+ .wasm_component_model_accessors(component_model_accessors)
.wasm_exceptions(exceptions)
.wasm_stack_switching(stack_switching)
.gc_support(gc_types)
diff --git a/crates/test-util/src/wast.rs b/crates/test-util/src/wast.rs
index 204fceb5e0..4cd01e447a 100644
--- a/crates/test-util/src/wast.rs
+++ b/crates/test-util/src/wast.rs
@@ -266,6 +266,7 @@ fn component_test_config(test: &Path) -> TestConfig {
ret.multi_memory = Some(true);
ret.component_model_implements = Some(true);
ret.component_model_canonical_names = Some(true);
+ ret.component_model_accessors = Some(true);
ret.bulk_memory = Some(true);
ret.component_model_async = Some(true);
ret.component_model_more_async_builtins = Some(true);
@@ -363,6 +364,7 @@ macro_rules! foreach_config_option {
component_model_fixed_length_lists
component_model_implements
component_model_canonical_names
+ component_model_accessors
simd
gc_types
exceptions
diff --git a/crates/wasmtime/src/config.rs b/crates/wasmtime/src/config.rs
index 98726d426c..45657093e5 100644
--- a/crates/wasmtime/src/config.rs
+++ b/crates/wasmtime/src/config.rs
@@ -1430,6 +1430,16 @@ impl Config {
self
}
+ /// This corresponds to the πŸ“‘ emoji in the component model specification.
+ ///
+ /// Please note that Wasmtime's support for this feature is a work in
+ /// progress.
+ #[cfg(feature = "component-model")]
+ pub fn wasm_component_model_accessors(&mut self, enable: bool) -> &mut Self {
+ self.wasm_features(WasmFeatures::CM_ACCESSORS, enable);
+ self
+ }
+
/// Configures whether the [Exception-handling proposal][proposal] is enabled or not.
///
/// This is `true` by default, except when using [`Strategy::Winch`] where
@@ -2467,7 +2477,8 @@ impl Config {
| WasmFeatures::CM64
| WasmFeatures::CM_FIXED_LENGTH_LISTS
| WasmFeatures::CM_IMPLEMENTS
- | WasmFeatures::CM_CANON_NAMES;
+ | WasmFeatures::CM_CANON_NAMES
+ | WasmFeatures::CM_ACCESSORS;
#[allow(unused_mut, reason = "easier to avoid #[cfg]")]
let mut unsupported = !features_known_to_wasmtime;