Skip to content

Commit

Permalink
Autodetect default backend, add features for architecture type
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark McCaskey committed Nov 22, 2019
1 parent c3f93f1 commit 31437a1
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"]
Expand All @@ -84,20 +87,23 @@ 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 = [
"wasmer-llvm-backend",
"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 = [
"wasmer-singlepass-backend",
"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"]
Expand Down
5 changes: 3 additions & 2 deletions lib/middleware-common-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-core-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion lib/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
38 changes: 38 additions & 0 deletions lib/runtime/build.rs
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 31437a1

Please sign in to comment.