mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-13 05:48:45 +00:00
Make compiler config even simpler
This commit is contained in:
25
Cargo.toml
25
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",
|
||||
]
|
||||
|
||||
|
||||
4
build.rs
4
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(
|
||||
|
||||
@@ -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"
|
||||
]
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
24
src/store.rs
24
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<Box<dyn CompilerConfig>> {
|
||||
let config: Box<dyn CompilerConfig> = 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()
|
||||
|
||||
@@ -167,13 +167,13 @@ pub fn with_test_module<T>(
|
||||
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)?;
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user