A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Don't implicitly enable Pulley on all platforms (#15226)
Alex Crichtonc7dda86cec9d
diff --git a/cranelift/codegen/Cargo.toml b/cranelift/codegen/Cargo.tomlindex 0ad70aa176..605ba3d1ff 100644--- a/cranelift/codegen/Cargo.toml+++ b/cranelift/codegen/Cargo.toml@@ -94,7 +94,12 @@ x86 = []arm64 = []s390x = []riscv64 = []-pulley = [+pulley = ["pulley-fallback"]++# Enable the Pulley ISA targets only when the target machine has no native+# Cranelift backend. Note that pulley deps are still pulled in unconditionally,+# but they're unused should the target machine have a native backend.+pulley-fallback = ["dep:pulley-interpreter","pulley-interpreter/encode","pulley-interpreter/disas",diff --git a/cranelift/codegen/build.rs b/cranelift/codegen/build.rsindex 0e73a9f6d1..4aacd1152d 100644--- a/cranelift/codegen/build.rs+++ b/cranelift/codegen/build.rs@@ -32,6 +32,11 @@ fn main() {let all_arch = env::var("CARGO_FEATURE_ALL_ARCH").is_ok();let all_native_arch = env::var("CARGO_FEATURE_ALL_NATIVE_ARCH").is_ok();+ let miri = env::var("CARGO_CFG_MIRI").is_ok();+ let pulley_fallback = env::var("CARGO_FEATURE_PULLEY_FALLBACK").is_ok();++ let target_name = target_triple.split('-').next().unwrap();+ let host_isa = meta::isa_from_arch(&target_name).ok();let mut isas = meta::isa::Isa::all().iter()@@ -47,16 +52,24 @@ fn main() {}).collect::<Vec<_>>();+ // If so requested, pulley isn't already enabled, and the host backend for+ // this host architecture doesn't exist, then enable pulley.+ if pulley_fallback && !isas.contains(&meta::isa::Isa::Pulley64) && (host_isa.is_none() || miri)+ {+ println!("cargo:rustc-cfg=feature=\"pulley\"");+ isas.push(meta::isa::Isa::Pulley32);+ isas.push(meta::isa::Isa::Pulley64);+ }+// Don't require host isa if under 'all-arch' feature.- let host_isa = env::var("CARGO_FEATURE_HOST_ARCH").is_ok() && !all_native_arch;-- if isas.is_empty() || host_isa {- // Try to match native target.- let target_name = target_triple.split('-').next().unwrap();- if let Ok(isa) = meta::isa_from_arch(&target_name) {- println!("cargo:rustc-cfg=feature=\"{isa}\"");- isas.push(isa);- }+ let host_arch = env::var("CARGO_FEATURE_HOST_ARCH").is_ok() && !all_native_arch;++ // Try to match native target.+ if (isas.is_empty() || host_arch)+ && let Some(isa) = host_isa+ {+ println!("cargo:rustc-cfg=feature=\"{isa}\"");+ isas.push(isa);}let cur_dir = env::current_dir().expect("Can't access current working directory");diff --git a/cranelift/codegen/meta/src/isa/mod.rs b/cranelift/codegen/meta/src/isa/mod.rsindex 655b14a9c5..e2ef578454 100644--- a/cranelift/codegen/meta/src/isa/mod.rs+++ b/cranelift/codegen/meta/src/isa/mod.rs@@ -33,7 +33,7 @@ impl Isa {match arch {"aarch64" => Some(Isa::Arm64),"s390x" => Some(Isa::S390x),- x if ["x86_64", "i386", "i586", "i686"].contains(&x) => Some(Isa::X86),+ "x86_64" => Some(Isa::X86),"riscv64" | "riscv64gc" | "riscv64imac" => Some(Isa::Riscv64),"pulley32" => Some(Isa::Pulley32),"pulley64" => Some(Isa::Pulley64),diff --git a/crates/cranelift/Cargo.toml b/crates/cranelift/Cargo.tomlindex c434a0879d..e54568003f 100644--- a/crates/cranelift/Cargo.toml+++ b/crates/cranelift/Cargo.toml@@ -49,4 +49,5 @@ features = [all-arch = ["cranelift-codegen/all-arch"]host-arch = ["cranelift-codegen/host-arch"]pulley = ["cranelift-codegen/pulley", "dep:pulley-interpreter"]+pulley-fallback = ["cranelift-codegen/pulley-fallback"]trace-log = ["cranelift-codegen/trace-log"]diff --git a/crates/wasmtime/Cargo.toml b/crates/wasmtime/Cargo.tomlindex 3d5fd5756a..f1172866ef 100644--- a/crates/wasmtime/Cargo.toml+++ b/crates/wasmtime/Cargo.toml@@ -21,7 +21,7 @@ wasmtime-jit-debug = { workspace = true, optional = true }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, features = ['pulley'] }+wasmtime-cranelift = { workspace = true, optional = true, features = ['pulley-fallback'] }wasmtime-unwinder = { workspace = true, optional = true }wasmtime-winch = { workspace = true, optional = true }wasmtime-component-macro = { workspace = true, optional = true }@@ -178,11 +178,17 @@ 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.+#+# If Wasmtime is compiled for a target that does not have a native Cranelift+# backend then this feature need not be explicitly enabled to use Pulley.+# Wasmtime makes a dynamic decision based on the target platform whether to use+# Pulley or not. To guarantee the ability to compile for Pulley, such as a+# pre-compilation target, then this feature should be enabled.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.+ # Note that pulley dependencies are intentionally non-optional and not enabled+ # here. The crate dependencies are always pulled in and `build.rs` decides+ # whether they're used or not.+ "wasmtime-cranelift?/pulley",]# Enables support for incremental compilation cache to be enabled in `Config`.diff --git a/crates/wasmtime/build.rs b/crates/wasmtime/build.rsindex 105e3e04ab..d2b5966cda 100644--- a/crates/wasmtime/build.rs+++ b/crates/wasmtime/build.rs@@ -90,7 +90,10 @@ fn main() {// 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.+ // why the Pulley runtime dependencies are unconditional and Cranelift's+ // Pulley backends are activated via the `pulley-fallback` feature of+ // `wasmtime-cranelift`, which performs basically the same host check in+ // `cranelift-codegen`'s build script.let default_target_pulley = !has_host_compiler_backend || miri;custom_cfg("default_target_pulley", default_target_pulley);if default_target_pulley {