Skip to content

Commit 88bab50

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 methods are available on the `wasmtime::Config` type, regardless of the enabled crate features: 1. `Config::wasm_threads`. 2. `Config::wasm_reference_types`. 3. `Config::wasm_component_model`. 4. `Config::parallel_compilation`. Of these, enabling any of the first three while the corresponding crate feature is disabled will lead to a runtime error when constructing the `wasmtime::Engine`. Enabling the last one, parallel compilation, will simply do nothing. fixes #10454
1 parent 04eee21 commit 88bab50

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

crates/wasmtime/src/config.rs

+24-12
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
@@ -857,15 +857,14 @@ impl Config {
857857
///
858858
/// Note that the reference types proposal depends on the bulk memory proposal.
859859
///
860-
/// This feature is `true` by default.
860+
/// This feature is enabled by default.
861861
///
862862
/// # Errors
863863
///
864864
/// The validation of this feature are deferred until the engine is being built,
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
@@ -1100,12 +1099,10 @@ impl Config {
11001099
/// [`Component`](crate::component::Component) instead of
11011100
/// [`Module`](crate::Module) for example anyway.
11021101
///
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.
1102+
/// This feature is enabled by default as long as the `component-model` crate
1103+
/// feature (enabled by default) is also enabled.
11061104
///
11071105
/// [proposal]: https://github.com/webassembly/component-model
1108-
#[cfg(feature = "component-model")]
11091106
pub fn wasm_component_model(&mut self, enable: bool) -> &mut Self {
11101107
self.wasm_feature(WasmFeatures::COMPONENT_MODEL, enable);
11111108
self
@@ -1837,8 +1834,8 @@ impl Config {
18371834
/// Disabling this will result in a single thread being used to compile
18381835
/// the wasm bytecode.
18391836
///
1840-
/// By default parallel compilation is enabled.
1841-
#[cfg(feature = "parallel-compilation")]
1837+
/// This feature is enabled by default as long as the `parallel-compilation`
1838+
/// crate feature (enabled by default) is also enabled.
18421839
pub fn parallel_compilation(&mut self, parallel: bool) -> &mut Self {
18431840
self.parallel_compilation = parallel;
18441841
self
@@ -2165,6 +2162,21 @@ impl Config {
21652162
bail!("wmemcheck (memory checker) was requested but is not enabled in this build");
21662163
}
21672164

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

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

0 commit comments

Comments
 (0)