Skip to content

Commit 655afbd

Browse files
committed
Keep Config options for disabling compiled-out features
This patch keeps config options for disabling default-enabled wasmtime features, even when those features are disabled via crate feature flags. That way, these wasm features can be disabled by libraries even if the crate-level features are later enabled by some other crate in the build-tree. Specifically, the following `wasmtime::Config` methods are now enabled regardless of compile-time features (removed dependency on the GC feature): 1. `Config::wasm_reference_types`. 2. `Config::wasm_function_references`. The following methods are available on the `wasmtime::Config` type, regardless of the enabled crate features but will lead to runtime errors when constructing a `wasmtime::Engine`: 1. `Config::wasm_threads`. 2. `Config::wasm_gc`. 3. `Config::wasm_component_model`. 4. `Config::wasm_component_model_async`. Finally, `Config::parallel_compilation` is defined regardless of whether or not the parallel compilation feature is enabled. However, without the corresponding crate feature, this config option is a no-op. fixes #10454
1 parent 04eee21 commit 655afbd

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

crates/wasmtime/src/config.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ impl Config {
423423
/// WebAssembly will execute and what compute resources will be allotted to
424424
/// it. If Wasmtime doesn't support exactly what you'd like just yet, please
425425
/// feel free to open an issue!
426+
///
427+
/// This feature is `false` by default.
426428
#[cfg(feature = "async")]
427429
pub fn async_support(&mut self, enable: bool) -> &mut Self {
428430
self.async_support = enable;
@@ -837,13 +839,11 @@ impl Config {
837839
/// Embeddings of Wasmtime are able to build their own custom threading
838840
/// scheme on top of the core wasm threads proposal, however.
839841
///
840-
/// The default value for this option is whether the `threads`
841-
/// crate feature of Wasmtime is enabled or not. By default this crate
842-
/// feature is enabled.
842+
/// This feature is enabled by default as long as the `threads` crate feature
843+
/// (enabled by default) is also enabled.
843844
///
844845
/// [threads]: https://github.com/webassembly/threads
845846
/// [wasi-threads]: https://github.com/webassembly/wasi-threads
846-
#[cfg(feature = "threads")]
847847
pub fn wasm_threads(&mut self, enable: bool) -> &mut Self {
848848
self.wasm_feature(WasmFeatures::THREADS, enable);
849849
self
@@ -865,7 +865,6 @@ impl Config {
865865
/// and thus may cause `Engine::new` fail if the `bulk_memory` feature is disabled.
866866
///
867867
/// [proposal]: https://github.com/webassembly/reference-types
868-
#[cfg(feature = "gc")]
869868
pub fn wasm_reference_types(&mut self, enable: bool) -> &mut Self {
870869
self.wasm_feature(WasmFeatures::REFERENCE_TYPES, enable);
871870
self
@@ -884,7 +883,6 @@ impl Config {
884883
/// This feature is `false` by default.
885884
///
886885
/// [proposal]: https://github.com/WebAssembly/function-references
887-
#[cfg(feature = "gc")]
888886
pub fn wasm_function_references(&mut self, enable: bool) -> &mut Self {
889887
self.wasm_feature(WasmFeatures::FUNCTION_REFERENCES, enable);
890888
self
@@ -916,7 +914,6 @@ impl Config {
916914
/// progress and generally not ready for primetime.**
917915
///
918916
/// [proposal]: https://github.com/WebAssembly/gc
919-
#[cfg(feature = "gc")]
920917
pub fn wasm_gc(&mut self, enable: bool) -> &mut Self {
921918
self.wasm_feature(WasmFeatures::GC, enable);
922919
self
@@ -1100,12 +1097,10 @@ impl Config {
11001097
/// [`Component`](crate::component::Component) instead of
11011098
/// [`Module`](crate::Module) for example anyway.
11021099
///
1103-
/// The default value for this option is whether the `component-model`
1104-
/// crate feature of Wasmtime is enabled or not. By default this crate
1105-
/// feature is enabled.
1100+
/// This feature is enabled by default as long as the `component-model` crate
1101+
/// feature (enabled by default) is also enabled.
11061102
///
11071103
/// [proposal]: https://github.com/webassembly/component-model
1108-
#[cfg(feature = "component-model")]
11091104
pub fn wasm_component_model(&mut self, enable: bool) -> &mut Self {
11101105
self.wasm_feature(WasmFeatures::COMPONENT_MODEL, enable);
11111106
self
@@ -1118,7 +1113,6 @@ impl Config {
11181113
/// Please note that Wasmtime's support for this feature is _very_ incomplete.
11191114
///
11201115
/// [proposal]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Async.md
1121-
#[cfg(feature = "component-model-async")]
11221116
pub fn wasm_component_model_async(&mut self, enable: bool) -> &mut Self {
11231117
self.wasm_feature(WasmFeatures::COMPONENT_MODEL_ASYNC, enable);
11241118
self
@@ -1837,8 +1831,8 @@ impl Config {
18371831
/// Disabling this will result in a single thread being used to compile
18381832
/// the wasm bytecode.
18391833
///
1840-
/// By default parallel compilation is enabled.
1841-
#[cfg(feature = "parallel-compilation")]
1834+
/// This feature is enabled by default as long as the `parallel-compilation`
1835+
/// crate feature (enabled by default) is also enabled.
18421836
pub fn parallel_compilation(&mut self, parallel: bool) -> &mut Self {
18431837
self.parallel_compilation = parallel;
18441838
self
@@ -2165,6 +2159,26 @@ impl Config {
21652159
bail!("wmemcheck (memory checker) was requested but is not enabled in this build");
21662160
}
21672161

2162+
#[cfg(not(feature = "component-model"))]
2163+
if features.component_model() {
2164+
bail!("component-model support was requested but is not enabled in this build (requires the `component-model` crate feature)");
2165+
}
2166+
2167+
#[cfg(not(feature = "component-model-async"))]
2168+
if features.component_model_async() {
2169+
bail!("component-model-async support was requested but is not enabled in this build (requires the `component-model-async` crate feature)");
2170+
}
2171+
2172+
#[cfg(not(feature = "gc"))]
2173+
if features.gc_types() || features.gc() {
2174+
bail!("gc support was requested but is not enabled in this build (requires the `gc` crate feature)");
2175+
}
2176+
2177+
#[cfg(not(feature = "threads"))]
2178+
if features.threads() {
2179+
bail!("threads support was requested but is not enabled in this build (requires the `threads` crate feature)");
2180+
}
2181+
21682182
let mut tunables = Tunables::default_for_target(&self.compiler_target())?;
21692183

21702184
// If no target is explicitly specified then further refine `tunables`

0 commit comments

Comments
 (0)