diff --git a/crates/cranelift/Cargo.toml b/crates/cranelift/Cargo.toml index 18f7df833476..635a4eec91e8 100644 --- a/crates/cranelift/Cargo.toml +++ b/crates/cranelift/Cargo.toml @@ -34,12 +34,6 @@ wasmtime-versioned-export-macros = { workspace = true } itertools = "0.12" pulley-interpreter = { workspace = true, optional = true } -# On 32-bit platforms where Cranelift currently doesn't have any supported host -# unconditionally enable the `pulley` feature of the Cranelift backend to ensure -# that it's possible to run wasm code by default. -[target.'cfg(target_pointer_width = "32")'.dependencies] -cranelift-codegen = { workspace = true, features = ['pulley'] } - [features] all-arch = ["cranelift-codegen/all-arch"] host-arch = ["cranelift-codegen/host-arch"] diff --git a/crates/wasmtime/Cargo.toml b/crates/wasmtime/Cargo.toml index 6c5016d980a6..21b1f80daf8b 100644 --- a/crates/wasmtime/Cargo.toml +++ b/crates/wasmtime/Cargo.toml @@ -23,7 +23,7 @@ wasmtime-jit-debug = { workspace = true, features = ["gdb_jit_int", "perf_jitdum wasmtime-jit-icache-coherence = { workspace = true, optional = true } wasmtime-cache = { workspace = true, optional = true } wasmtime-fiber = { workspace = true, optional = true } -wasmtime-cranelift = { workspace = true, optional = true } +wasmtime-cranelift = { workspace = true, optional = true, features = ['pulley'] } wasmtime-winch = { workspace = true, optional = true } wasmtime-component-macro = { workspace = true, optional = true } wasmtime-component-util = { workspace = true, optional = true } @@ -31,7 +31,7 @@ wasmtime-slab = { workspace = true, optional = true } wasmtime-versioned-export-macros = { workspace = true } wasmtime-wmemcheck = { workspace = true, optional = true } wasmtime-math = { workspace = true } -pulley-interpreter = { workspace = true, optional = true } +pulley-interpreter = { workspace = true } target-lexicon = { workspace = true } wasmparser = { workspace = true } wasm-encoder = { workspace = true, optional = true } @@ -98,14 +98,6 @@ rustix = { workspace = true, optional = true } [target.'cfg(target_arch = "s390x")'.dependencies] psm = { workspace = true, optional = true } -# On 32-bit platforms where Cranelift currently doesn't have any supported host -# unconditionally pull in the `pulley-interpreter` crate. Runtime support is -# enabled via `build.rs` which prints `feature="pulley"` by default here and -# compilation support, if enabled via the `cranelift` feature, is handled in the -# `wasmtime-cranelift` crate enabling Pulley on 32-bit platforms. -[target.'cfg(target_pointer_width = "32")'.dependencies] -pulley-interpreter = { workspace = true } - [dev-dependencies] env_logger = { workspace = true } proptest = { workspace = true } @@ -165,7 +157,12 @@ winch = ["dep:wasmtime-winch", "std"] # targets will be available. When paired with the `runtime` feature, the Pulley # interpreter will be built into the runtime and you can interpret WebAssembly # modules that have been compiled to Pulley bytecode. -pulley = ["dep:pulley-interpreter", "wasmtime-cranelift?/pulley"] +pulley = [ + # Note that this is intentionally empty. This feature is dynamically activated + # in `build.rs` as well when the host platform does not have Cranelift support + # for example. That means that dependencies for pulley need to be already + # activated anyway. +] # Enables support for incremental compilation cache to be enabled in `Config`. incremental-cache = ["wasmtime-cranelift?/incremental-cache", "std"] @@ -257,7 +254,7 @@ runtime = [ "dep:psm", "dep:rustix", "rustix/mm", - "pulley-interpreter?/interp", + "pulley-interpreter/interp", ] # Enable support for garbage collection-related things. @@ -325,7 +322,7 @@ std = [ 'object/std', 'once_cell', 'wasmtime-fiber?/std', - 'pulley-interpreter?/std', + 'pulley-interpreter/std', 'wasmtime-math/std', # technically this isn't necessary but once you have the standard library you # probably want things to go fast in which case you've probably got signal diff --git a/crates/wasmtime/build.rs b/crates/wasmtime/build.rs index 6edb8ea8f2d8..d353b69b5228 100644 --- a/crates/wasmtime/build.rs +++ b/crates/wasmtime/build.rs @@ -4,15 +4,26 @@ fn main() { #[cfg(feature = "runtime")] build_c_helpers(); - // Flag pulley as enabled unconditionally on 32-bit targets to ensure that - // wasm is runnable by default like it is on other 64-bit native platforms. - // Note that this doesn't actually enable the Cargo feature, it just changes - // the cfg's passed to the crate, so for example care is still taken in - // `Cargo.toml` to handle pulley-specific dependencies on 32-bit platforms. - let target_pointer_width = std::env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap(); - if target_pointer_width == "32" { - println!("cargo:rustc-cfg=feature=\"pulley\""); + // Determine whether Pulley will be enabled and used for this target. + match std::env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() { + // These targets use Cranelift by default as they have backends in + // Cranelift. Pulley can still be used on an opt-in basis, but it's not + // otherwise explicitly enabled here. + "x86_64" | "riscv64" | "s390x" | "aarch64" => {} + + // All other targets at this time use Pulley by default. That means + // that the pulley feature is "enabled" here and the default target is + // pulley. Note that by enabling the feature here it doesn't actually + // enable the Cargo feature, it just passes a cfg to rustc. That means + // that conditional dependencies enabled in `Cargo.toml` (or other + // features) by `pulley` aren't activated, which is why the `pulley` + // feature of this crate depends on nothing else. + _ => { + println!("cargo:rustc-cfg=feature=\"pulley\""); + println!("cargo:rustc-cfg=default_target_pulley"); + } } + println!("cargo:rustc-check-cfg=cfg(default_target_pulley)"); } #[cfg(feature = "runtime")] diff --git a/crates/wasmtime/src/config.rs b/crates/wasmtime/src/config.rs index 8360a1313429..e12653b5f34a 100644 --- a/crates/wasmtime/src/config.rs +++ b/crates/wasmtime/src/config.rs @@ -2059,17 +2059,9 @@ impl Config { return target; } - // Without an explicitly configured target the goal is then to select - // some default which can reasonably run code on this host. If pulley is - // enabled and the host has no support at all in the cranelift/winch - // backends then pulley becomes the default target. This means, for - // example, that 32-bit platforms will default to running pulley at this - // time. - let any_compiler_support = cfg!(target_arch = "x86_64") - || cfg!(target_arch = "aarch64") - || cfg!(target_arch = "riscv64") - || cfg!(target_arch = "s390x"); - if !any_compiler_support && cfg!(feature = "pulley") { + // If the `build.rs` script determined that this platform uses pulley by + // default, then use Pulley. + if cfg!(default_target_pulley) { return target_lexicon::Triple::pulley_host(); }