Skip to content

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

add canonical names flag to wasmtime CLI (#14344)

Yanca3b393e30a0
diff --git a/crates/c-api/include/wasmtime/config.h b/crates/c-api/include/wasmtime/config.h
index 6ca54636ed..79f6f1d486 100644
--- a/crates/c-api/include/wasmtime/config.h
+++ b/crates/c-api/include/wasmtime/config.h
@@ -917,6 +917,15 @@ WASMTIME_CONFIG_PROP(void, wasm_component_model_map, bool)
*/
WASMTIME_CONFIG_PROP(void, wasm_component_model_implements, bool)
+/**
+ * \brief Configures whether the WebAssembly component-model canonical names
+ * 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_canonical_names.
+ */
+WASMTIME_CONFIG_PROP(void, wasm_component_model_canonical_names, 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 ff39f4e209..56d2d718dd 100644
--- a/crates/c-api/src/component/component.rs
+++ b/crates/c-api/src/component/component.rs
@@ -26,6 +26,14 @@ pub extern "C" fn wasmtime_config_wasm_component_model_implements_set(
c.config.wasm_component_model_implements(enable);
}
+#[unsafe(no_mangle)]
+pub extern "C" fn wasmtime_config_wasm_component_model_canonical_names_set(
+ c: &mut wasm_config_t,
+ enable: bool,
+) {
+ c.config.wasm_component_model_canonical_names(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 dc4912eb5d..69d8637fee 100644
--- a/crates/cli-flags/src/lib.rs
+++ b/crates/cli-flags/src/lib.rs
@@ -529,6 +529,9 @@ wasmtime_option_group! {
/// Component model support for `(implements ...)`, corresponds to the
/// 🏷️ emoji in the upstream spec.
pub component_model_implements: Option<bool>,
+ /// Component model support for canonical names, corresponds to the
+ /// πŸ”— emoji in the upstream spec.
+ pub component_model_canonical_names: Option<bool>,
/// Whether or not any concurrency infrastructure in Wasmtime is
/// enabled or not.
pub concurrency_support: Option<bool>,
@@ -1348,6 +1351,7 @@ impl CommonOptions {
("component-model", component_model_map, wasm_component_model_map)
("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_memory64, wasm_component_model_memory64)
("threads", threads, wasm_threads)
("gc", gc, wasm_gc)
@@ -1522,6 +1526,9 @@ impl CommonOptions {
features.contains(WasmFeatures::CM_FIXED_LENGTH_LISTS),
),
component_model_implements: Some(features.contains(WasmFeatures::CM_IMPLEMENTS)),
+ component_model_canonical_names: Some(
+ features.contains(WasmFeatures::CM_CANON_NAMES),
+ ),
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 e41dbf6579..4c4980df9c 100644
--- a/crates/fuzzing/src/generators/config.rs
+++ b/crates/fuzzing/src/generators/config.rs
@@ -149,6 +149,7 @@ impl Config {
component_model_memory64,
component_model_fixed_length_lists,
component_model_implements,
+ component_model_canonical_names,
simd,
exceptions,
legacy_exceptions: _,
@@ -179,6 +180,8 @@ impl Config {
self.module_config.component_model_fixed_length_lists =
component_model_fixed_length_lists.unwrap_or(false);
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.stack_switching = stack_switching.unwrap_or(false);
self.wasmtime.branch_hinting = branch_hinting.unwrap_or(false);
@@ -337,6 +340,8 @@ impl Config {
cfg.wasm.component_model_fixed_length_lists =
Some(self.module_config.component_model_fixed_length_lists);
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.custom_page_sizes = Some(self.module_config.config.custom_page_sizes_enabled);
cfg.wasm.epoch_interruption = Some(self.wasmtime.epoch_interruption);
cfg.wasm.extended_const = Some(self.module_config.config.extended_const_enabled);
diff --git a/crates/fuzzing/src/generators/module.rs b/crates/fuzzing/src/generators/module.rs
index 3cfcca2264..749329f1ae 100644
--- a/crates/fuzzing/src/generators/module.rs
+++ b/crates/fuzzing/src/generators/module.rs
@@ -26,6 +26,7 @@ pub struct ModuleConfig {
pub component_model_memory64: bool,
pub component_model_fixed_length_lists: bool,
pub component_model_implements: bool,
+ pub component_model_canonical_names: 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_memory64: false,
component_model_fixed_length_lists: false,
component_model_implements: false,
+ component_model_canonical_names: 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 53ef7f04e9..8729b35bb1 100644
--- a/crates/test-util/src/wasmtime_wast.rs
+++ b/crates/test-util/src/wasmtime_wast.rs
@@ -50,6 +50,7 @@ pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) {
component_model_memory64,
component_model_fixed_length_lists,
component_model_implements,
+ component_model_canonical_names,
nan_canonicalization,
simd,
exceptions,
@@ -85,6 +86,7 @@ pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) {
let component_model_memory64 = component_model_memory64.unwrap_or(false);
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 nan_canonicalization = nan_canonicalization.unwrap_or(false);
let relaxed_simd = relaxed_simd.unwrap_or(false);
let legacy_exceptions = legacy_exceptions.unwrap_or(false);
@@ -131,6 +133,7 @@ pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) {
.wasm_component_model_memory64(component_model_memory64)
.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_exceptions(exceptions)
.wasm_stack_switching(stack_switching)
.cranelift_nan_canonicalization(nan_canonicalization);
diff --git a/crates/test-util/src/wast.rs b/crates/test-util/src/wast.rs
index cf9186bb4f..ca3102aa3a 100644
--- a/crates/test-util/src/wast.rs
+++ b/crates/test-util/src/wast.rs
@@ -252,6 +252,7 @@ fn component_test_config(test: &Path) -> TestConfig {
ret.reference_types = Some(true);
ret.multi_memory = Some(true);
ret.component_model_implements = Some(true);
+ ret.component_model_canonical_names = Some(true);
ret.bulk_memory = Some(true);
ret.component_model_async = Some(true);
ret.component_model_more_async_builtins = Some(true);
@@ -347,6 +348,7 @@ macro_rules! foreach_config_option {
component_model_memory64
component_model_fixed_length_lists
component_model_implements
+ component_model_canonical_names
simd
gc_types
exceptions
diff --git a/crates/wasmtime/src/config.rs b/crates/wasmtime/src/config.rs
index 75d6fad07e..b8635634ea 100644
--- a/crates/wasmtime/src/config.rs
+++ b/crates/wasmtime/src/config.rs
@@ -1399,6 +1399,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_canonical_names(&mut self, enable: bool) -> &mut Self {
+ self.wasm_features(WasmFeatures::CM_CANON_NAMES, enable);
+ self
+ }
+
/// Configures whether the [Exception-handling proposal][proposal] is enabled or not.
///
/// This is `true` by default.
@@ -2433,7 +2443,8 @@ impl Config {
| WasmFeatures::CM_MAP
| WasmFeatures::CM64
| WasmFeatures::CM_FIXED_LENGTH_LISTS
- | WasmFeatures::CM_IMPLEMENTS;
+ | WasmFeatures::CM_IMPLEMENTS
+ | WasmFeatures::CM_CANON_NAMES;
#[allow(unused_mut, reason = "easier to avoid #[cfg]")]
let mut unsupported = !features_known_to_wasmtime;