diff --git a/Cargo.toml b/Cargo.toml index f61a2029a..1412d92bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ publish = false autoexamples = false [dependencies] -wasmer = { version = "0.16.2", path = "lib/api" } +wasmer = { version = "0.16.2", path = "lib/api", default-features = false } wasmer-compiler = { version = "0.16.2", path = "lib/compiler" } wasmer-compiler-cranelift = { version = "0.16.2", path = "lib/compiler-cranelift", optional = true } wasmer-compiler-singlepass = { version = "0.16.2", path = "lib/compiler-singlepass", optional = true } @@ -53,33 +53,34 @@ anyhow = "1.0.28" test-utils = { path = "tests/lib/test-utils" } [features] -# Don't add the backend features in default, please add them on the Makefile +# Don't add the compiler features in default, please add them on the Makefile # since we might want to autoconfigure them depending on the availability on the host. -default = ["wast", "wasi", "compiler-cranelift", "cache"] +default = ["wat", "wast", "wasi", "cranelift", "cache"] cache = ["wasmer-cache"] wast = ["wasmer-wast"] wasi = ["wasmer-wasi"] +wat = ["wasmer/wat"] compiler = ["wasmer-jit/compiler"] experimental-io-devices = [ "wasmer-wasi-experimental-io-devices", "wasi" ] -compiler-singlepass = [ - "test-utils/compiler-singlepass", - "wasmer/compiler-singlepass", +singlepass = [ "wasmer-compiler-singlepass", + "test-utils/singlepass", + "wasmer/singlepass", "compiler", ] -compiler-cranelift = [ - "test-utils/compiler-cranelift", - "wasmer/compiler-cranelift", +cranelift = [ "wasmer-compiler-cranelift", + "test-utils/cranelift", + "wasmer/cranelift", "compiler", ] -compiler-llvm = [ - "test-utils/compiler-llvm", - "wasmer/compiler-llvm", +llvm = [ "wasmer-compiler-llvm", + "test-utils/llvm", + "wasmer/llvm", "compiler", ] diff --git a/build.rs b/build.rs index aa85f428b..e05c17299 100644 --- a/build.rs +++ b/build.rs @@ -10,7 +10,7 @@ use std::path::PathBuf; use std::process::Command; use test_generator::{ build_ignores_from_textfile, test_directory, test_directory_module, wast_processor, - with_backends, with_test_module, Testsuite, + with_features, with_test_module, Testsuite, }; fn is_truthy_env(name: &str) -> bool { @@ -34,7 +34,7 @@ fn main() -> anyhow::Result<()> { }; let backends = vec!["singlepass", "cranelift", "llvm"]; - with_backends(&mut spectests, &backends, |mut spectests| { + with_features(&mut spectests, &backends, |mut spectests| { with_test_module(&mut spectests, "spec", |spectests| { let _spec_tests = test_directory(spectests, "tests/wast/spec", wast_processor)?; test_directory_module( diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index 061ab4e22..67f4a53ca 100644 --- a/lib/api/Cargo.toml +++ b/lib/api/Cargo.toml @@ -37,26 +37,17 @@ anyhow = "1.0.28" maintenance = { status = "actively-developed" } [features] -default = ["wat", "default-compiler-cranelift"] +default = ["wat", "cranelift"] compiler = ["wasmer-jit/compiler"] -compiler-singlepass = [ +singlepass = [ "wasmer-compiler-singlepass", "compiler", ] -compiler-cranelift = [ +cranelift = [ "wasmer-compiler-cranelift", "compiler", ] -compiler-llvm = [ +llvm = [ "wasmer-compiler-llvm", "compiler", ] -default-compiler-singlepass = [ - "compiler-singlepass" -] -default-compiler-cranelift = [ - "compiler-cranelift" -] -default-compiler-llvm = [ - "compiler-llvm" -] diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index 0feb0a91f..18616ada9 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -35,14 +35,32 @@ pub use wasmer_jit::{ DeserializeError, InstantiationError, LinkError, RuntimeError, SerializeError, }; -#[cfg(feature = "compiler-singlepass")] -pub use wasmer_compiler_singlepass::SinglepassConfig; +// The compilers are mutually exclusive +#[cfg(any( + all(feature = "llvm", any(feature = "cranelift", feature = "singlepass")), + all(feature = "cranelift", feature = "singlepass") +))] +compile_error!( + r#"The `singlepass`, `cranelift` and `llvm` features are mutually exclusive. +If you wish to use more than one compiler, you can simply import it from it's own crate. Eg.: -#[cfg(feature = "compiler-cranelift")] -pub use wasmer_compiler_cranelift::CraneliftConfig; +``` +use wasmer::{Store, Engine}; +use wasmer_compiler_singlepass::SinglepassConfig; -#[cfg(feature = "compiler-llvm")] -pub use wasmer_compiler_llvm::LLVMConfig; +let engine = Engine::new(SinglepassConfig::default()); +let store = Store::new_config(&engine); +```"# +); + +#[cfg(feature = "singlepass")] +pub use wasmer_compiler_singlepass::SinglepassConfig as DefaultCompilerConfig; + +#[cfg(feature = "cranelift")] +pub use wasmer_compiler_cranelift::CraneliftConfig as DefaultCompilerConfig; + +#[cfg(feature = "llvm")] +pub use wasmer_compiler_llvm::LLVMConfig as DefaultCompilerConfig; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/lib/api/src/store.rs b/lib/api/src/store.rs index cd8d5a114..58dba7f86 100644 --- a/lib/api/src/store.rs +++ b/lib/api/src/store.rs @@ -26,37 +26,10 @@ impl Store { Arc::ptr_eq(&a.engine, &b.engine) } - #[cfg(any( - feature = "default-compiler-singlepass", - feature = "default-compiler-cranelift", - feature = "default-compiler-llvm", - ))] - pub fn default_compiler_config() -> impl CompilerConfig { - #[cfg(any( - all( - feature = "default-compiler-llvm", - any( - feature = "default-compiler-cranelift", - feature = "default-compiler-singlepass" - ) - ), - all( - feature = "default-compiler-cranelift", - feature = "default-compiler-singlepass" - ) - ))] - compile_error!( - "The `default-compiler-X` features are mutually exclusive. Please choose just one" - ); - - #[cfg(feature = "default-compiler-cranelift")] - return wasmer_compiler_cranelift::CraneliftConfig::default(); - - #[cfg(feature = "default-compiler-llvm")] - return wasmer_compiler_llvm::LLVMConfig::default(); - - #[cfg(feature = "default-compiler-singlepass")] - return wasmer_compiler_singlepass::SinglepassConfig::default(); + #[cfg(feature = "compiler")] + fn new_config(config: impl CompilerConfig) -> Self { + let tunables = Tunables::for_target(config.target().triple()); + Self::new(&Engine::new(&config, tunables)) } } @@ -67,16 +40,11 @@ impl PartialEq for Store { } // We only implement default if we have assigned a default compiler -#[cfg(any( - feature = "default-compiler-singlepass", - feature = "default-compiler-cranelift", - feature = "default-compiler-llvm", -))] +#[cfg(feature = "compiler")] impl Default for Store { fn default() -> Store { - let config = Self::default_compiler_config(); - let tunables = Tunables::for_target(config.target().triple()); - Store::new(&Engine::new(&config, tunables)) + let config = crate::DefaultCompilerConfig::default(); + Store::new_config(config) } } diff --git a/src/store.rs b/src/store.rs index f533e7ead..009e749c9 100644 --- a/src/store.rs +++ b/src/store.rs @@ -79,11 +79,11 @@ impl StoreOptions { return Compiler::from_str(&backend); } else { // Auto mode, we choose the best compiler for that platform - if cfg!(feature = "compiler-cranelift") && cfg!(target_arch = "x86_64") { + if cfg!(feature = "cranelift") && cfg!(target_arch = "x86_64") { return Ok(Compiler::Cranelift); - } else if cfg!(feature = "compiler-singlepass") && cfg!(target_arch = "x86_64") { + } else if cfg!(feature = "singlepass") && cfg!(target_arch = "x86_64") { return Ok(Compiler::Singlepass); - } else if cfg!(feature = "compiler-llvm") { + } else if cfg!(feature = "llvm") { return Ok(Compiler::LLVM); } else { bail!("There are no available compilers for your architecture") @@ -95,26 +95,22 @@ impl StoreOptions { #[allow(unused_variables)] fn get_config(&self, compiler: Compiler) -> Result> { let config: Box = match compiler { - #[cfg(feature = "compiler-singlepass")] + #[cfg(feature = "singlepass")] Compiler::Singlepass => { - let config = SinglepassConfig::default(); + let config = wasmer_compiler_singlepass::SinglepassConfig::default(); Box::new(config) } - #[cfg(feature = "compiler-cranelift")] + #[cfg(feature = "cranelift")] Compiler::Cranelift => { - let config = CraneliftConfig::default(); + let config = wasmer_compiler_cranelift::CraneliftConfig::default(); Box::new(config) } - #[cfg(feature = "compiler-llvm")] + #[cfg(feature = "llvm")] Compiler::LLVM => { - let config = LLVMConfig::default(); + let config = wasmer_compiler_llvm::LLVMConfig::default(); Box::new(config) } - #[cfg(not(all( - feature = "compiler-singlepass", - feature = "compiler-cranelift", - feature = "compiler-llvm", - )))] + #[cfg(not(all(feature = "singlepass", feature = "cranelift", feature = "llvm",)))] compiler => bail!( "The `{}` compiler is not included in this binary.", compiler.to_string() diff --git a/tests/lib/test-generator/src/lib.rs b/tests/lib/test-generator/src/lib.rs index 90fc8f79e..3da80eedf 100644 --- a/tests/lib/test-generator/src/lib.rs +++ b/tests/lib/test-generator/src/lib.rs @@ -167,13 +167,13 @@ pub fn with_test_module( Ok(result) } -pub fn with_backends( +pub fn with_features( mut out: &mut Testsuite, - backends: &[&str], + features: &[&str], f: impl Fn(&mut Testsuite) -> anyhow::Result<()> + Copy, ) -> anyhow::Result<()> { - for compiler in backends.iter() { - writeln!(out.buffer, "#[cfg(feature=\"compiler-{}\")]", compiler)?; + for compiler in features.iter() { + writeln!(out.buffer, "#[cfg(feature=\"{}\")]", compiler)?; writeln!(out.buffer, "#[cfg(test)]")?; writeln!(out.buffer, "#[allow(non_snake_case)]")?; with_test_module(&mut out, &compiler, f)?; diff --git a/tests/lib/test-utils/Cargo.toml b/tests/lib/test-utils/Cargo.toml index 4ddd80656..c3787696a 100644 --- a/tests/lib/test-utils/Cargo.toml +++ b/tests/lib/test-utils/Cargo.toml @@ -16,15 +16,15 @@ wasmer-compiler-llvm = { path = "../../../lib/compiler-llvm", version = "0.16.2" [features] compiler = [] -compiler-singlepass = [ +singlepass = [ "wasmer-compiler-singlepass", "compiler", ] -compiler-cranelift = [ +cranelift = [ "wasmer-compiler-cranelift", "compiler", ] -compiler-llvm = [ +llvm = [ "wasmer-compiler-llvm", "compiler", ] diff --git a/tests/lib/test-utils/src/lib.rs b/tests/lib/test-utils/src/lib.rs index 93cad17ac..4a9dd834c 100644 --- a/tests/lib/test-utils/src/lib.rs +++ b/tests/lib/test-utils/src/lib.rs @@ -11,21 +11,21 @@ pub fn get_compiler_config_from_str( let target = Target::default(); match compiler_name { - #[cfg(feature = "compiler-singlepass")] + #[cfg(feature = "singlepass")] "singlepass" => { let mut singlepass_config = wasmer_compiler_singlepass::SinglepassConfig::new(features, target); singlepass_config.enable_nan_canonicalization = try_nan_canonicalization; Box::new(singlepass_config) } - #[cfg(feature = "compiler-cranelift")] + #[cfg(feature = "cranelift")] "cranelift" => { let mut cranelift_config = wasmer_compiler_cranelift::CraneliftConfig::new(features, target); cranelift_config.enable_nan_canonicalization = try_nan_canonicalization; Box::new(cranelift_config) } - #[cfg(feature = "compiler-llvm")] + #[cfg(feature = "llvm")] "llvm" => { let mut llvm_config = wasmer_compiler_llvm::LLVMConfig::new(features, target); llvm_config.enable_nan_canonicalization = try_nan_canonicalization;