diff --git a/crates/c-api/include/wasmtime/config.h b/crates/c-api/include/wasmtime/config.h index bafdb85e2631..4788ea9bb145 100644 --- a/crates/c-api/include/wasmtime/config.h +++ b/crates/c-api/include/wasmtime/config.h @@ -382,8 +382,6 @@ wasmtime_config_cache_config_load(wasm_config_t *, const char *); #endif // WASMTIME_FEATURE_CACHE -#ifdef WASMTIME_FEATURE_COMPILER - /** * \brief Configures the target triple that this configuration will produce * machine code for. @@ -398,6 +396,8 @@ wasmtime_config_cache_config_load(wasm_config_t *, const char *); */ WASMTIME_CONFIG_PROP(wasmtime_error_t *, target, const char *) +#ifdef WASMTIME_FEATURE_COMPILER + /** * \brief Enables a target-specific flag in Cranelift. * diff --git a/crates/c-api/include/wasmtime/engine.h b/crates/c-api/include/wasmtime/engine.h index 6b666bf5f983..4695b59271f9 100644 --- a/crates/c-api/include/wasmtime/engine.h +++ b/crates/c-api/include/wasmtime/engine.h @@ -35,6 +35,12 @@ WASM_API_EXTERN wasm_engine_t *wasmtime_engine_clone(wasm_engine_t *engine); */ WASM_API_EXTERN void wasmtime_engine_increment_epoch(wasm_engine_t *engine); +/** + * \brief Returns whether this engine is using the Pulley interpreter to execute + * WebAssembly code. + */ +WASM_API_EXTERN bool wasmtime_engine_is_pulley(wasm_engine_t *engine); + #ifdef __cplusplus } // extern "C" #endif diff --git a/crates/c-api/src/config.rs b/crates/c-api/src/config.rs index 8618407b30da..52009ce97229 100644 --- a/crates/c-api/src/config.rs +++ b/crates/c-api/src/config.rs @@ -249,7 +249,6 @@ pub extern "C" fn wasmtime_config_native_unwind_info_set(c: &mut wasm_config_t, } #[no_mangle] -#[cfg(any(feature = "cranelift", feature = "winch"))] pub unsafe extern "C" fn wasmtime_config_target_set( c: &mut wasm_config_t, target: *const c_char, diff --git a/crates/c-api/src/engine.rs b/crates/c-api/src/engine.rs index e8cea19e7571..d4c43f0778be 100644 --- a/crates/c-api/src/engine.rs +++ b/crates/c-api/src/engine.rs @@ -47,3 +47,8 @@ pub extern "C" fn wasmtime_engine_clone(engine: &wasm_engine_t) -> Box bool { + engine.engine.is_pulley() +} diff --git a/crates/cli-flags/src/lib.rs b/crates/cli-flags/src/lib.rs index f819f8d544ca..db0832e206f8 100644 --- a/crates/cli-flags/src/lib.rs +++ b/crates/cli-flags/src/lib.rs @@ -568,10 +568,8 @@ impl CommonOptions { collector => config.collector(collector), _ => err, } - match_feature! { - ["cranelift" : &self.target] - target => config.target(target)?, - _ => err, + if let Some(target) = &self.target { + config.target(target)?; } match_feature! { ["cranelift" : self.codegen.cranelift_debug_verifier] diff --git a/crates/wasmtime/src/config.rs b/crates/wasmtime/src/config.rs index 31de2c06803f..07dbd6be8246 100644 --- a/crates/wasmtime/src/config.rs +++ b/crates/wasmtime/src/config.rs @@ -126,6 +126,7 @@ impl core::hash::Hash for ModuleVersionStrategy { pub struct Config { #[cfg(any(feature = "cranelift", feature = "winch"))] compiler_config: CompilerConfig, + target: Option, #[cfg(feature = "gc")] collector: Collector, profiling_strategy: ProfilingStrategy, @@ -171,7 +172,6 @@ pub struct Config { #[derive(Debug, Clone)] struct CompilerConfig { strategy: Option, - target: Option, settings: HashMap, flags: HashSet, #[cfg(all(feature = "incremental-cache", feature = "cranelift"))] @@ -185,7 +185,6 @@ impl CompilerConfig { fn new() -> Self { Self { strategy: Strategy::Auto.not_auto(), - target: None, settings: HashMap::new(), flags: HashSet::new(), #[cfg(all(feature = "incremental-cache", feature = "cranelift"))] @@ -230,6 +229,7 @@ impl Config { tunables: ConfigTunables::default(), #[cfg(any(feature = "cranelift", feature = "winch"))] compiler_config: CompilerConfig::default(), + target: None, #[cfg(feature = "gc")] collector: Collector::default(), #[cfg(feature = "cache")] @@ -305,9 +305,8 @@ impl Config { /// # Errors /// /// This method will error if the given target triple is not supported. - #[cfg(any(feature = "cranelift", feature = "winch"))] pub fn target(&mut self, target: &str) -> Result<&mut Self> { - self.compiler_config.target = + self.target = Some(target_lexicon::Triple::from_str(target).map_err(|e| anyhow::anyhow!(e))?); Ok(self) @@ -2053,10 +2052,10 @@ impl Config { } /// Returns the configured compiler target for this `Config`. - fn compiler_target(&self) -> target_lexicon::Triple { + pub(crate) fn compiler_target(&self) -> target_lexicon::Triple { // If a target is explicitly configured, always use that. #[cfg(any(feature = "cranelift", feature = "winch"))] - if let Some(target) = self.compiler_config.target.clone() { + if let Some(target) = self.target.clone() { return target; } @@ -2256,7 +2255,7 @@ impl Config { // specified (which indicates no feature inference) and the target // matches the host. let target_for_builder = - if self.compiler_config.target.is_none() && target == target_lexicon::Triple::host() { + if self.target.is_none() && target == target_lexicon::Triple::host() { None } else { Some(target.clone()) diff --git a/crates/wasmtime/src/engine.rs b/crates/wasmtime/src/engine.rs index 7f8669c16bca..5575e8c12b3a 100644 --- a/crates/wasmtime/src/engine.rs +++ b/crates/wasmtime/src/engine.rs @@ -16,7 +16,7 @@ use object::SectionKind; use std::{fs::File, path::Path}; use wasmparser::WasmFeatures; use wasmtime_environ::obj; -use wasmtime_environ::{FlagValue, ObjectKind, Tunables}; +use wasmtime_environ::{FlagValue, ObjectKind, TripleExt, Tunables}; mod serialization; @@ -223,13 +223,7 @@ impl Engine { /// Returns the target triple which this engine is compiling code for /// and/or running code for. pub(crate) fn target(&self) -> target_lexicon::Triple { - // If a compiler is configured, use that target. - #[cfg(any(feature = "cranelift", feature = "winch"))] - return self.compiler().triple().clone(); - - // ... otherwise it's the native target - #[cfg(not(any(feature = "cranelift", feature = "winch")))] - return target_lexicon::Triple::host(); + return self.config().compiler_target(); } /// Verify that this engine's configuration is compatible with loading @@ -258,7 +252,6 @@ impl Engine { #[cfg(any(feature = "cranelift", feature = "winch"))] { use target_lexicon::Triple; - use wasmtime_environ::TripleExt; let compiler = self.compiler(); @@ -529,6 +522,17 @@ impl Engine { )), } } + + /// Returns whether this [`Engine`] is configured to execute with Pulley, + /// Wasmtime's interpreter. + /// + /// Note that Pulley is the default for host platforms that do not have a + /// Cranelift backend to support them. For example at the time of this + /// writing 32-bit x86 is not supported in Cranelift so the + /// `i686-unknown-linux-gnu` target would by default return `true` here. + pub fn is_pulley(&self) -> bool { + self.target().is_pulley() + } } #[cfg(any(feature = "cranelift", feature = "winch"))]