diff --git a/Cargo.lock b/Cargo.lock index 37410c3568b..9db25328286 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1353,6 +1353,7 @@ dependencies = [ "wasmer-middleware-common-tests 0.10.2", "wasmer-runtime 0.10.2", "wasmer-runtime-core 0.10.2", + "wasmer-runtime-core-tests 0.10.2", "wasmer-singlepass-backend 0.10.2", "wasmer-wasi 0.10.2", "wasmer-wasi-tests 0.10.2", diff --git a/Cargo.toml b/Cargo.toml index 8724d91d4a3..48c4cfce51e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ wasmer-kernel-loader = { path = "lib/kernel-loader", optional = true } wasmer-dev-utils = { path = "lib/dev-utils", optional = true } wasmer-wasi-tests = { path = "lib/wasi-tests", optional = true } wasmer-middleware-common-tests = { path = "lib/middleware-common-tests", optional = true } +wasmer-runtime-core-tests = { path = "lib/runtime-core-tests", optional = true } wasmer-emscripten-tests = { path = "lib/emscripten-tests", optional = true } [workspace] @@ -73,8 +74,10 @@ serde = { version = "1", features = ["derive"] } # used by the plugin example typetag = "0.1" # used by the plugin example [features] -default = ["fast-tests", "wasi", "backend-cranelift"] +default = ["fast-tests", "wasi", "x86_64"] "loader-kernel" = ["wasmer-kernel-loader"] +aarch64 = ["backend-singlepass"] +x86_64 = ["backend-cranelift"] debug = ["wasmer-runtime-core/debug"] trace = ["wasmer-runtime-core/trace"] extra-debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] @@ -84,6 +87,7 @@ backend-cranelift = [ "wasmer-runtime-core/backend-cranelift", "wasmer-runtime/cranelift", "wasmer-middleware-common-tests/clif", + "wasmer-runtime-core-tests/backend-cranelift", "wasmer-wasi-tests/clif" ] backend-llvm = [ @@ -91,6 +95,7 @@ backend-llvm = [ "wasmer-runtime-core/backend-llvm", "wasmer-runtime/llvm", "wasmer-middleware-common-tests/llvm", + "wasmer-runtime-core-tests/backend-llvm", "wasmer-wasi-tests/llvm" ] backend-singlepass = [ @@ -98,6 +103,7 @@ backend-singlepass = [ "wasmer-runtime-core/backend-singlepass", "wasmer-runtime/singlepass", "wasmer-middleware-common-tests/singlepass", + "wasmer-runtime-core-tests/backend-singlepass", "wasmer-wasi-tests/singlepass" ] wasi = ["wasmer-wasi"] diff --git a/lib/middleware-common-tests/Cargo.toml b/lib/middleware-common-tests/Cargo.toml index 5eb36d95905..d598f165c85 100644 --- a/lib/middleware-common-tests/Cargo.toml +++ b/lib/middleware-common-tests/Cargo.toml @@ -10,12 +10,13 @@ publish = false [dependencies] wasmer-runtime-core = { path = "../runtime-core", version = "0.10.2" } wasmer-middleware-common = { path = "../middleware-common", version = "0.10.2" } -wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2" } +wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2", optional = true } wasmer-llvm-backend = { path = "../llvm-backend", version = "0.10.2", optional = true } wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.10.2", optional = true } [features] -clif = [] +default = ["clif"] +clif = ["wasmer-clif-backend"] llvm = ["wasmer-llvm-backend"] singlepass = ["wasmer-singlepass-backend"] diff --git a/lib/runtime-core-tests/Cargo.toml b/lib/runtime-core-tests/Cargo.toml index 0191d0e827f..b71ed2bb0d3 100644 --- a/lib/runtime-core-tests/Cargo.toml +++ b/lib/runtime-core-tests/Cargo.toml @@ -15,7 +15,7 @@ wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.10.2" wasmer-llvm-backend = { path = "../llvm-backend", version = "0.10.2", optional = true } [features] -default = ["backend-cranelift"] +default = [] backend-cranelift = ["wasmer-clif-backend"] backend-singlepass = ["wasmer-singlepass-backend"] backend-llvm = ["wasmer-llvm-backend"] diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index 902ea37ac38..8574d60a5c4 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -34,7 +34,7 @@ path = "../llvm-backend" optional = true [features] -default = ["cranelift", "default-backend-cranelift"] +default = ["cranelift"] cranelift = ["wasmer-clif-backend"] cache = ["cranelift"] debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] diff --git a/lib/runtime/build.rs b/lib/runtime/build.rs new file mode 100644 index 00000000000..8f986c7546b --- /dev/null +++ b/lib/runtime/build.rs @@ -0,0 +1,38 @@ +//! This build script sets the default compiler using special output. +//! +//! See https://doc.rust-lang.org/cargo/reference/build-scripts.html +//! for details. + +/// This function tells Cargo which default backend to use +fn set_default_backend() { + // we must use this rather than `cfg` because the build.rs executes on the + // compiling system. This method works with cross compilation too. + match std::env::var("CARGO_CFG_TARGET_ARCH") + .expect("compilation target env var") + .as_ref() + { + "x86_64" => { + println!("cargo:rustc-cfg=feature=\"default-backend-cranelift\""); + } + "aarch64" => { + println!("cargo:rustc-cfg=feature=\"default-backend-singlepass\""); + } + other => { + println!("cargo:warning=compiling for untested architecture: \"{}\"! Attempting to use LLVM", other); + println!("cargo:rustc-cfg=feature=\"default-backend-llvm\""); + } + } +} + +/// This function checks if the user specified a default backend +fn has_default_backend() -> bool { + std::env::var("CARGO_FEATURE_DEFAULT_BACKEND_SINGLEPASS").is_ok() + || std::env::var("CARGO_FEATURE_DEFAULT_BACKEND_CRANELIFT").is_ok() + || std::env::var("CARGO_FEATURE_DEFAULT_BACKEND_LLVM").is_ok() +} + +fn main() { + if !has_default_backend() { + set_default_backend(); + } +}