diff --git a/Cargo.toml b/Cargo.toml index 4651ee2eb01..95a9e4782ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ autoexamples = false [dependencies] wasmer = { version = "=2.3.0", path = "lib/api", default-features = false } -wasmer-compiler = { version = "=2.3.0", path = "lib/compiler", features = ["engine_compilation"] } +wasmer-compiler = { version = "=2.3.0", path = "lib/compiler", features = ["compiler"] } wasmer-compiler-cranelift = { version = "=2.3.0", path = "lib/compiler-cranelift", optional = true } wasmer-compiler-singlepass = { version = "=2.3.0", path = "lib/compiler-singlepass", optional = true } wasmer-compiler-llvm = { version = "=2.3.0", path = "lib/compiler-llvm", optional = true } @@ -64,7 +64,7 @@ glob = "0.3" rustc_version = "0.4" [dev-dependencies] -wasmer = { version = "=2.3.0", path = "lib/api", default-features = false, features = ["default-cranelift"] } +wasmer = { version = "=2.3.0", path = "lib/api", default-features = false, features = ["cranelift"] } anyhow = "1.0" criterion = "0.3" lazy_static = "1.4" diff --git a/Makefile b/Makefile index 34a7b0e184b..e99f00317c2 100644 --- a/Makefile +++ b/Makefile @@ -359,7 +359,7 @@ check-wasmer-wasm: check-capi: capi-setup RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) check $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml \ - --no-default-features --features wat,compilation,wasi,middlewares $(capi_compiler_features) + --no-default-features --features wat,compiler,wasi,middlewares $(capi_compiler_features) build-wasmer: $(CARGO_BINARY) build $(CARGO_TARGET) --release --manifest-path lib/cli/Cargo.toml $(compiler_features) --bin wasmer @@ -421,50 +421,50 @@ build-docs-capi: capi-setup # when generating the documentation, we rename it to its # crate's name. Then we restore the lib's name. sed "$(SEDI)" -e 's/name = "wasmer" # ##lib.name##/name = "wasmer_c_api" # ##lib.name##/' lib/c-api/Cargo.toml - RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) doc $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --no-deps --features wat,compilation,cranelift,wasi + RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) doc $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --no-deps --features wat,compiler,cranelift,wasi sed "$(SEDI)" -e 's/name = "wasmer_c_api" # ##lib.name##/name = "wasmer" # ##lib.name##/' lib/c-api/Cargo.toml build-capi: capi-setup RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features wat,compilation,wasi,middlewares $(capi_compiler_features) + --no-default-features --features wat,compiler,wasi,middlewares $(capi_compiler_features) build-capi-singlepass: capi-setup RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features wat,compilation,singlepass,wasi,middlewares + --no-default-features --features wat,compiler,singlepass,wasi,middlewares build-capi-singlepass-universal: capi-setup RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features wat,compilation,singlepass,wasi,middlewares + --no-default-features --features wat,compiler,singlepass,wasi,middlewares build-capi-cranelift: capi-setup RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features wat,compilation,cranelift,wasi,middlewares + --no-default-features --features wat,compiler,cranelift,wasi,middlewares build-capi-cranelift-universal: capi-setup RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features wat,compilation,cranelift,wasi,middlewares + --no-default-features --features wat,compiler,cranelift,wasi,middlewares build-capi-llvm: capi-setup RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features wat,compilation,llvm,wasi,middlewares + --no-default-features --features wat,compiler,llvm,wasi,middlewares build-capi-llvm-universal: capi-setup RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features wat,compilation,llvm,wasi,middlewares + --no-default-features --features wat,compiler,llvm,wasi,middlewares # Headless (we include the minimal to be able to run) build-capi-headless-universal: capi-setup RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features compilation,wasi + --no-default-features --features compiler-headless,wasi build-capi-headless-all: capi-setup RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features compilation,wasi + --no-default-features --features compiler-headless,wasi build-capi-headless-ios: capi-setup RUSTFLAGS="${RUSTFLAGS}" cargo lipo --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features wasi + --no-default-features --features compiler-headless,wasi ##### # @@ -520,7 +520,7 @@ test-capi: build-capi package-capi $(foreach compiler_engine,$(capi_compilers_en test-capi-crate-%: WASMER_CAPI_CONFIG=$(shell echo $@ | sed -e s/test-capi-crate-//) $(CARGO_BINARY) test $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features wat,compilation,wasi,middlewares $(capi_compiler_features) -- --nocapture + --no-default-features --features wat,compiler,wasi,middlewares $(capi_compiler_features) -- --nocapture test-capi-integration-%: # Test the Wasmer C API tests for C @@ -698,7 +698,7 @@ update-testsuite: lint-packages: RUSTFLAGS += -D dead-code -D nonstandard-style -D unused-imports -D unused-mut -D unused-variables -D unused-unsafe -D unreachable-patterns -D bad-style -D improper-ctypes -D unused-allocation -D unused-comparisons -D while-true -D unconditional-recursion -D bare-trait-objects -D function_item_references # TODO: add `-D missing-docs` lint-packages: - RUSTFLAGS="${RUSTFLAGS}" cargo clippy --all -- -D clippy::all + RUSTFLAGS="${RUSTFLAGS}" cargo clippy --all --exclude wasmer-cli -- -D clippy::all RUSTFLAGS="${RUSTFLAGS}" cargo clippy --manifest-path lib/cli/Cargo.toml $(compiler_features) -- -D clippy::all RUSTFLAGS="${RUSTFLAGS}" cargo clippy --manifest-path fuzz/Cargo.toml $(compiler_features) -- -D clippy::all diff --git a/benches/static_and_dynamic_functions.rs b/benches/static_and_dynamic_functions.rs index edb87e1edbd..1eb80a13894 100644 --- a/benches/static_and_dynamic_functions.rs +++ b/benches/static_and_dynamic_functions.rs @@ -149,15 +149,21 @@ pub fn run_basic_dynamic_function(store: &Store, compiler_name: &str, c: &mut Cr fn run_static_benchmarks(_c: &mut Criterion) { #[cfg(feature = "llvm")] { - let mut store = - Store::new_with_engine(&Backend::new(wasmer_compiler_llvm::LLVM::new()).engine()); + let mut store = Store::new_with_engine( + &EngineBuilder::new(Some(wasmer_compiler_llvm::LLVM::new()), None, None).engine(), + ); run_basic_static_function(&store, "llvm", c); } #[cfg(feature = "cranelift")] { let mut store = Store::new_with_engine( - &Backend::new(wasmer_compiler_cranelift::Cranelift::new()).engine(), + &EngineBuilder::new( + Some(wasmer_compiler_cranelift::Cranelift::new()), + None, + None, + ) + .engine(), ); run_basic_static_function(&store, "cranelift", c); } @@ -165,7 +171,12 @@ fn run_static_benchmarks(_c: &mut Criterion) { #[cfg(feature = "singlepass")] { let mut store = Store::new_with_engine( - &Backend::new(wasmer_compiler_singlepass::Singlepass::new()).engine(), + &EngineBuilder::new( + Some(wasmer_compiler_singlepass::Singlepass::new()), + None, + None, + ) + .engine(), ); run_basic_static_function(&store, "singlepass", c); } @@ -174,15 +185,21 @@ fn run_static_benchmarks(_c: &mut Criterion) { fn run_dynamic_benchmarks(_c: &mut Criterion) { #[cfg(feature = "llvm")] { - let mut store = - Store::new_with_engine(&Backend::new(wasmer_compiler_llvm::LLVM::new()).engine()); + let mut store = Store::new_with_engine( + &EngineBuilder::new(Some(wasmer_compiler_llvm::LLVM::new()), None, None).engine(), + ); run_basic_dynamic_function(&store, "llvm", c); } #[cfg(feature = "cranelift")] { let mut store = Store::new_with_engine( - &Backend::new(wasmer_compiler_cranelift::Cranelift::new()).engine(), + &EngineBuilder::new( + Some(wasmer_compiler_cranelift::Cranelift::new()), + None, + None, + ) + .engine(), ); run_basic_dynamic_function(&store, "cranelift", c); } @@ -190,7 +207,12 @@ fn run_dynamic_benchmarks(_c: &mut Criterion) { #[cfg(feature = "singlepass")] { let mut store = Store::new_with_engine( - &Backend::new(wasmer_compiler_singlepass::Singlepass::new()).engine(), + &EngineBuilder::new( + Some(wasmer_compiler_singlepass::Singlepass::new()), + None, + None, + ) + .engine(), ); run_basic_dynamic_function(&store, "singlepass", c); } diff --git a/docs/migration_to_3.0.0.md b/docs/migration_to_3.0.0.md index f586170e2dc..72523d5bc9c 100644 --- a/docs/migration_to_3.0.0.md +++ b/docs/migration_to_3.0.0.md @@ -130,7 +130,7 @@ let wasm_bytes = wat2wasm( )?; let compiler_config = Cranelift::default(); -let engine = Backend::new(compiler_config).engine(); +let engine = Universal::new(compiler_config).engine(); let mut store = Store::new(&engine); let module = Module::new(&store, wasm_bytes)?; let instance = Instance::new(&module, &imports! {})?; diff --git a/examples/compiler_cranelift.rs b/examples/compiler_cranelift.rs index e63b30f39b0..394c9adf920 100644 --- a/examples/compiler_cranelift.rs +++ b/examples/compiler_cranelift.rs @@ -11,7 +11,7 @@ //! Ready? use wasmer::{imports, wat2wasm, Instance, Module, Store, Value}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -33,7 +33,7 @@ fn main() -> Result<(), Box> { let compiler = Cranelift::default(); // Create the store - let mut store = Store::new_with_engine(&Backend::new(compiler).engine()); + let mut store = Store::new_with_engine(&EngineBuilder::new(compiler, None, None).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/compiler_llvm.rs b/examples/compiler_llvm.rs index 549dd468a27..0fc43967f49 100644 --- a/examples/compiler_llvm.rs +++ b/examples/compiler_llvm.rs @@ -11,7 +11,7 @@ //! Ready? use wasmer::{imports, wat2wasm, Instance, Module, Store, Value}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_llvm::LLVM; fn main() -> Result<(), Box> { @@ -33,7 +33,7 @@ fn main() -> Result<(), Box> { let compiler = LLVM::default(); // Create the store - let mut store = Store::new_with_engine(&Backend::new(compiler).engine()); + let mut store = Store::new_with_engine(&EngineBuilder::new(compiler, None, None).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/compiler_singlepass.rs b/examples/compiler_singlepass.rs index 3f0e9d8dcf3..79cda03d15a 100644 --- a/examples/compiler_singlepass.rs +++ b/examples/compiler_singlepass.rs @@ -11,7 +11,7 @@ //! Ready? use wasmer::{imports, wat2wasm, Instance, Module, Store, Value}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_singlepass::Singlepass; fn main() -> Result<(), Box> { @@ -33,7 +33,7 @@ fn main() -> Result<(), Box> { let compiler = Singlepass::default(); // Create the store - let mut store = Store::new_with_engine(&Backend::new(compiler).engine()); + let mut store = Store::new_with_engine(&EngineBuilder::new(compiler, None, None).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/early_exit.rs b/examples/early_exit.rs index e6adb11156b..fda18128eb0 100644 --- a/examples/early_exit.rs +++ b/examples/early_exit.rs @@ -20,7 +20,7 @@ use wasmer::{ imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store, TypedFunction, }; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; // First we need to create an error type that we'll use to signal the end of execution. @@ -58,7 +58,8 @@ fn main() -> anyhow::Result<()> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let mut store = Store::new_with_engine(&Backend::new(Cranelift::default()).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(Cranelift::default(), None, None).engine()); let env = FunctionEnv::new(&mut store, ()); println!("Compiling module..."); diff --git a/examples/engine.rs b/examples/engine.rs index dbaa1640a68..52fb6a9b1f9 100644 --- a/examples/engine.rs +++ b/examples/engine.rs @@ -19,7 +19,7 @@ //! Ready? use wasmer::{imports, wat2wasm, Instance, Module, Store, Value}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -49,7 +49,7 @@ fn main() -> Result<(), Box> { // // In this case, the engine is `wasmer_compiler` which roughly // means that the executable code will live in memory. - let engine = Backend::new(compiler_config).engine(); + let engine = EngineBuilder::new(compiler_config, None, None).engine(); // Create a store, that holds the engine. let mut store = Store::new_with_engine(&engine); diff --git a/examples/engine_cross_compilation.rs b/examples/engine_cross_compilation.rs index 7ece0468551..4170b4b4245 100644 --- a/examples/engine_cross_compilation.rs +++ b/examples/engine_cross_compilation.rs @@ -20,7 +20,7 @@ use std::str::FromStr; use wasmer::{wat2wasm, Module, RuntimeError, Store}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; use wasmer_types::{CpuFeature, Target, Triple}; @@ -70,13 +70,7 @@ fn main() -> Result<(), Box> { // That's where we specify the target for the compiler. // // Use the Universal engine. - let engine = Backend::new(compiler_config) - // Here we go. - // Pass the target to the engine! The engine will share - // this information with the compiler. - .target(target) - // Get the engine. - .engine(); + let mut engine = EngineBuilder::new(compiler_config, Some(target), None).engine(); // Create a store, that holds the engine. let mut store = Store::new_with_engine(&engine); diff --git a/examples/engine_headless.rs b/examples/engine_headless.rs index 8c8bf9a322a..943865cefcf 100644 --- a/examples/engine_headless.rs +++ b/examples/engine_headless.rs @@ -52,7 +52,7 @@ use wasmer::Instance; use wasmer::Module; use wasmer::Store; use wasmer::Value; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -82,7 +82,7 @@ fn main() -> Result<(), Box> { println!("Creating univesral engine..."); // Define the engine that will drive everything. - let engine = Backend::new(compiler_config).engine(); + let engine = EngineBuilder::new(compiler_config, None, None).engine(); // Create a store, that holds the engine. let mut store = Store::new_with_engine(&engine); @@ -105,7 +105,7 @@ fn main() -> Result<(), Box> { { println!("Creating headless Universal engine..."); // We create a headless Universal engine. - let engine = Backend::headless().engine(); + let engine = EngineBuilder::headless().engine(); let mut store = Store::new_with_engine(&engine); let mut env = FunctionEnv::new(&mut store, ()); diff --git a/examples/errors.rs b/examples/errors.rs index d8a60c76b50..2de13765e50 100644 --- a/examples/errors.rs +++ b/examples/errors.rs @@ -14,7 +14,7 @@ //! Ready? use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -39,7 +39,8 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let mut store = Store::new_with_engine(&Backend::new(Cranelift::default()).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(Cranelift::default(), None, None).engine()); let mut env = FunctionEnv::new(&mut store, ()); println!("Compiling module..."); diff --git a/examples/exports_function.rs b/examples/exports_function.rs index a27d14e58cb..e8d236345a3 100644 --- a/examples/exports_function.rs +++ b/examples/exports_function.rs @@ -18,7 +18,7 @@ //! Ready? use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction, Value}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -40,7 +40,8 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let mut store = Store::new_with_engine(&Backend::new(Cranelift::default()).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(Cranelift::default(), None, None).engine()); let mut env = FunctionEnv::new(&mut store, ()); println!("Compiling module..."); diff --git a/examples/exports_global.rs b/examples/exports_global.rs index c07abfecf6d..bec126847eb 100644 --- a/examples/exports_global.rs +++ b/examples/exports_global.rs @@ -18,7 +18,7 @@ use wasmer::{ imports, wat2wasm, FunctionEnv, Instance, Module, Mutability, Store, Type, TypedFunction, Value, }; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -40,7 +40,8 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let mut store = Store::new_with_engine(&Backend::new(Cranelift::default()).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(Cranelift::default(), None, None).engine()); let mut env = FunctionEnv::new(&mut store, ()); println!("Compiling module..."); diff --git a/examples/exports_memory.rs b/examples/exports_memory.rs index 11a12edbeb0..255e8916b85 100644 --- a/examples/exports_memory.rs +++ b/examples/exports_memory.rs @@ -12,7 +12,7 @@ //! Ready? use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction, WasmPtr}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -37,7 +37,8 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let mut store = Store::new_with_engine(&Backend::new(Cranelift::default()).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(Cranelift::default(), None, None).engine()); let mut env = FunctionEnv::new(&mut store, ()); println!("Compiling module..."); diff --git a/examples/features.rs b/examples/features.rs index a370cf202d1..3438059aa34 100644 --- a/examples/features.rs +++ b/examples/features.rs @@ -11,7 +11,7 @@ //! Ready? use wasmer::{imports, wat2wasm, Features, FunctionEnv, Instance, Module, Store, Value}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; fn main() -> anyhow::Result<()> { @@ -36,7 +36,7 @@ fn main() -> anyhow::Result<()> { features.multi_value(true); // Set up the engine. That's where we define the features! - let engine = Backend::new(compiler).features(features); + let engine = EngineBuilder::new(compiler, None, Some(features)); // Now, let's define the store, and compile the module. let mut store = Store::new_with_engine(&engine.engine()); diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 48c19b1d43b..6edaa391e45 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -10,7 +10,7 @@ use wasmer::{ imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store, TypedFunction, }; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; fn main() -> anyhow::Result<()> { @@ -47,7 +47,8 @@ fn main() -> anyhow::Result<()> { // However for the purposes of showing what's happening, we create a compiler // (`Cranelift`) and pass it to an engine (`Universal`). We then pass the engine to // the store and are now ready to compile and run WebAssembly! - let mut store = Store::new_with_engine(&Backend::new(Cranelift::default()).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(Cranelift::default(), None, None).engine()); // We then use our store and Wasm bytes to compile a `Module`. // A `Module` is a compiled WebAssembly module that isn't ready to execute yet. diff --git a/examples/imports_exports.rs b/examples/imports_exports.rs index 8cda043000e..ea0ada3d8d4 100644 --- a/examples/imports_exports.rs +++ b/examples/imports_exports.rs @@ -19,7 +19,7 @@ use wasmer::{ imports, wat2wasm, Function, FunctionEnv, FunctionType, Global, Instance, Memory, Module, Store, Table, Type, Value, }; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -44,7 +44,8 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let mut store = Store::new_with_engine(&Backend::new(Cranelift::default()).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(Cranelift::default(), None, None).engine()); let mut env = FunctionEnv::new(&mut store, ()); println!("Compiling module..."); diff --git a/examples/imports_function.rs b/examples/imports_function.rs index f686d93ceb4..2a15b18abad 100644 --- a/examples/imports_function.rs +++ b/examples/imports_function.rs @@ -21,7 +21,7 @@ use wasmer::{ imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, FunctionType, Instance, Module, Store, Type, TypedFunction, Value, }; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -45,7 +45,8 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let mut store = Store::new_with_engine(&Backend::new(Cranelift::default()).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(Cranelift::default(), None, None).engine()); let mut env1 = FunctionEnv::new(&mut store, ()); struct MyEnv; let mut env2 = FunctionEnv::new(&mut store, MyEnv {}); diff --git a/examples/imports_function_env.rs b/examples/imports_function_env.rs index 1bba9f00b92..2496b69dd23 100644 --- a/examples/imports_function_env.rs +++ b/examples/imports_function_env.rs @@ -24,7 +24,7 @@ use wasmer::{ imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store, TypedFunction, }; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -52,7 +52,8 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let mut store = Store::new_with_engine(&Backend::new(Cranelift::default()).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(Cranelift::default(), None, None).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/imports_global.rs b/examples/imports_global.rs index bebd93a1d3d..829cd183668 100644 --- a/examples/imports_global.rs +++ b/examples/imports_global.rs @@ -18,7 +18,7 @@ use wasmer::{ imports, wat2wasm, FunctionEnv, Global, Instance, Module, Store, TypedFunction, Value, }; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -40,7 +40,8 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let mut store = Store::new_with_engine(&Backend::new(Cranelift::default()).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(Cranelift::default(), None, None).engine()); let mut env = FunctionEnv::new(&mut store, ()); println!("Compiling module..."); diff --git a/examples/instance.rs b/examples/instance.rs index 1f556cbe1be..16b13fee2ae 100644 --- a/examples/instance.rs +++ b/examples/instance.rs @@ -15,7 +15,7 @@ //! Ready? use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -39,7 +39,8 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let mut store = Store::new_with_engine(&Backend::new(Cranelift::default()).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(Cranelift::default(), None, None).engine()); let mut env = FunctionEnv::new(&mut store, ()); println!("Compiling module..."); diff --git a/examples/memory.rs b/examples/memory.rs index f1e19e9738b..3aee97ad637 100644 --- a/examples/memory.rs +++ b/examples/memory.rs @@ -18,7 +18,7 @@ use std::mem; use wasmer::{ imports, wat2wasm, Bytes, FunctionEnv, Instance, Module, Pages, Store, TypedFunction, }; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; // this example is a work in progress: @@ -59,7 +59,8 @@ fn main() -> anyhow::Result<()> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let mut store = Store::new_with_engine(&Backend::new(Cranelift::default()).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(Cranelift::default(), None, None).engine()); let mut env = FunctionEnv::new(&mut store, ()); println!("Compiling module..."); diff --git a/examples/metering.rs b/examples/metering.rs index dbe705bd38a..00e04e112c0 100644 --- a/examples/metering.rs +++ b/examples/metering.rs @@ -19,7 +19,7 @@ use std::sync::Arc; use wasmer::wasmparser::Operator; use wasmer::CompilerConfig; use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; use wasmer_middlewares::{ metering::{get_remaining_points, set_remaining_points, MeteringPoints}, @@ -70,7 +70,8 @@ fn main() -> anyhow::Result<()> { // // We use our previously create compiler configuration // with the Universal engine. - let mut store = Store::new_with_engine(&Backend::new(compiler_config).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(compiler_config, None, None).engine()); let mut env = FunctionEnv::new(&mut store, ()); println!("Compiling module..."); diff --git a/examples/table.rs b/examples/table.rs index 5c758fc1a0b..28a4d508da8 100644 --- a/examples/table.rs +++ b/examples/table.rs @@ -2,7 +2,7 @@ use wasmer::{ imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store, TableType, Type, TypedFunction, Value, }; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; /// A function we'll call through a table. @@ -52,7 +52,8 @@ fn main() -> anyhow::Result<()> { )?; // We set up our store with an engine and a compiler. - let mut store = Store::new_with_engine(&Backend::new(Cranelift::default()).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(Cranelift::default(), None, None).engine()); let mut env = FunctionEnv::new(&mut store, ()); // Then compile our Wasm. let module = Module::new(&store, wasm_bytes)?; diff --git a/examples/tunables_limit_memory.rs b/examples/tunables_limit_memory.rs index 024b6ca90a4..90ed9028140 100644 --- a/examples/tunables_limit_memory.rs +++ b/examples/tunables_limit_memory.rs @@ -6,7 +6,7 @@ use wasmer::{ wat2wasm, BaseTunables, FunctionEnv, Instance, Memory, MemoryType, Module, Pages, Store, TableType, Target, Tunables, }; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; /// A custom tunables that allows you to set a memory limit. @@ -137,7 +137,7 @@ fn main() -> Result<(), Box> { // Any compiler and any engine do the job here let compiler = Cranelift::default(); - let engine = Backend::new(compiler).engine(); + let engine = EngineBuilder::new(compiler, None, None).engine(); // Here is where the fun begins diff --git a/examples/wasi.rs b/examples/wasi.rs index 64b9a9ebb60..011346db3b9 100644 --- a/examples/wasi.rs +++ b/examples/wasi.rs @@ -16,7 +16,7 @@ //! Ready? use wasmer::{FunctionEnv, Instance, Module, Store}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; use wasmer_wasi::WasiState; @@ -32,7 +32,8 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let mut store = Store::new_with_engine(&Backend::new(Cranelift::default()).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(Cranelift::default(), None, None).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/wasi_pipes.rs b/examples/wasi_pipes.rs index bd148dc5c31..8ce9897cfa7 100644 --- a/examples/wasi_pipes.rs +++ b/examples/wasi_pipes.rs @@ -13,7 +13,7 @@ use std::io::{Read, Write}; use wasmer::{FunctionEnv, Instance, Module, Store}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; use wasmer_wasi::{Pipe, WasiState}; @@ -29,7 +29,8 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let mut store = Store::new_with_engine(&Backend::new(Cranelift::default()).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(Cranelift::default(), None, None).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/fuzz/fuzz_targets/deterministic.rs b/fuzz/fuzz_targets/deterministic.rs index 245ae8aa81c..6ac7d38caa4 100644 --- a/fuzz/fuzz_targets/deterministic.rs +++ b/fuzz/fuzz_targets/deterministic.rs @@ -3,7 +3,7 @@ use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; use wasm_smith::{Config, ConfiguredModule}; use wasmer::{CompilerConfig, Engine, Module, Store}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; use wasmer_compiler_llvm::LLVM; use wasmer_compiler_singlepass::Singlepass; @@ -47,7 +47,7 @@ fuzz_target!(|module: ConfiguredModule| { compiler.enable_verifier(); compile_and_compare( "universal-cranelift", - Backend::new(compiler.clone()).engine(), + EngineBuilder::new(compiler.clone(), None, None).engine(), &wasm_bytes, ); @@ -56,14 +56,14 @@ fuzz_target!(|module: ConfiguredModule| { compiler.enable_verifier(); compile_and_compare( "universal-llvm", - Backend::new(compiler.clone()).engine(), + EngineBuilder::new(compiler.clone(), None, None).engine(), &wasm_bytes, ); let compiler = Singlepass::default(); compile_and_compare( "universal-singlepass", - Backend::new(compiler.clone()).engine(), + EngineBuilder::new(compiler.clone(), None, None).engine(), &wasm_bytes, ); }); diff --git a/fuzz/fuzz_targets/equivalence_universal.rs b/fuzz/fuzz_targets/equivalence_universal.rs index 6543647daf4..3d105462b5b 100644 --- a/fuzz/fuzz_targets/equivalence_universal.rs +++ b/fuzz/fuzz_targets/equivalence_universal.rs @@ -5,7 +5,7 @@ use anyhow::Result; use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; use wasm_smith::{Config, ConfiguredModule}; use wasmer::{imports, CompilerConfig, Instance, Module, Store, Val}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; #[cfg(feature = "cranelift")] use wasmer_compiler_cranelift::Cranelift; #[cfg(feature = "llvm")] @@ -48,7 +48,7 @@ impl std::fmt::Debug for WasmSmithModule { #[cfg(feature = "singlepass")] fn maybe_instantiate_singlepass(wasm_bytes: &[u8]) -> Result> { let compiler = Singlepass::default(); - let mut store = Store::new_with_engine(&Backend::new(compiler).engine()); + let mut store = Store::new_with_engine(&EngineBuilder::new(compiler, None, None).engine()); let module = Module::new(&store, &wasm_bytes); let module = match module { Ok(m) => m, @@ -69,7 +69,7 @@ fn maybe_instantiate_cranelift(wasm_bytes: &[u8]) -> Result> { let mut compiler = Cranelift::default(); compiler.canonicalize_nans(true); compiler.enable_verifier(); - let mut store = Store::new_with_engine(&Backend::new(compiler).engine()); + let mut store = Store::new_with_engine(&EngineBuilder::new(compiler, None, None).engine()); let module = Module::new(&store, &wasm_bytes)?; let instance = Instance::new(&module, &imports! {})?; Ok(Some(instance)) @@ -80,7 +80,7 @@ fn maybe_instantiate_llvm(wasm_bytes: &[u8]) -> Result> { let mut compiler = LLVM::default(); compiler.canonicalize_nans(true); compiler.enable_verifier(); - let mut store = Store::new_with_engine(&Backend::new(compiler).engine()); + let mut store = Store::new_with_engine(&EngineBuilder::new(compiler, None, None).engine()); let module = Module::new(&store, &wasm_bytes)?; let instance = Instance::new(&module, &imports! {})?; Ok(Some(instance)) diff --git a/fuzz/fuzz_targets/metering.rs b/fuzz/fuzz_targets/metering.rs index 4606a853e00..3d68f0c1f4e 100644 --- a/fuzz/fuzz_targets/metering.rs +++ b/fuzz/fuzz_targets/metering.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use wasm_smith::{Config, ConfiguredModule}; use wasmer::wasmparser::Operator; use wasmer::{imports, CompilerConfig, Instance, Module, Store}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; use wasmer_middlewares::Metering; @@ -56,7 +56,7 @@ fuzz_target!(|module: WasmSmithModule| { compiler.enable_verifier(); let metering = Arc::new(Metering::new(10, cost)); compiler.push_middleware(metering); - let mut store = Store::new_with_engine(&Backend::new(compiler).engine()); + let mut store = Store::new_with_engine(&EngineBuilder::new(compiler, None, None).engine()); let module = Module::new(&store, &wasm_bytes).unwrap(); match Instance::new(&module, &imports! {}) { Ok(_) => {} diff --git a/fuzz/fuzz_targets/universal_cranelift.rs b/fuzz/fuzz_targets/universal_cranelift.rs index 944ed882bf3..1fef9ea2015 100644 --- a/fuzz/fuzz_targets/universal_cranelift.rs +++ b/fuzz/fuzz_targets/universal_cranelift.rs @@ -3,7 +3,7 @@ use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; use wasm_smith::{Config, ConfiguredModule}; use wasmer::{imports, CompilerConfig, Instance, Module, Store}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_cranelift::Cranelift; #[derive(Arbitrary, Debug, Default, Copy, Clone)] @@ -42,7 +42,7 @@ fuzz_target!(|module: WasmSmithModule| { let mut compiler = Cranelift::default(); compiler.canonicalize_nans(true); compiler.enable_verifier(); - let mut store = Store::new_with_engine(&Backend::new(compiler).engine()); + let mut store = Store::new_with_engine(&EngineBuilder::new(compiler, None, None).engine()); let module = Module::new(&store, &wasm_bytes).unwrap(); match Instance::new(&module, &imports! {}) { Ok(_) => {} diff --git a/fuzz/fuzz_targets/universal_llvm.rs b/fuzz/fuzz_targets/universal_llvm.rs index 9619f01de4c..4b9ac9692da 100644 --- a/fuzz/fuzz_targets/universal_llvm.rs +++ b/fuzz/fuzz_targets/universal_llvm.rs @@ -3,7 +3,7 @@ use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; use wasm_smith::{Config, ConfiguredModule}; use wasmer::{imports, CompilerConfig, Instance, Module, Store}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_llvm::LLVM; #[derive(Arbitrary, Debug, Default, Copy, Clone)] @@ -42,7 +42,7 @@ fuzz_target!(|module: WasmSmithModule| { let mut compiler = LLVM::default(); compiler.canonicalize_nans(true); compiler.enable_verifier(); - let mut store = Store::new_with_engine(&Backend::new(compiler).engine()); + let mut store = Store::new_with_engine(&EngineBuilder::new(compiler, None, None).engine()); let module = Module::new(&store, &wasm_bytes).unwrap(); match Instance::new(&module, &imports! {}) { Ok(_) => {} diff --git a/fuzz/fuzz_targets/universal_singlepass.rs b/fuzz/fuzz_targets/universal_singlepass.rs index 48b007e8a90..d6a059eb5c2 100644 --- a/fuzz/fuzz_targets/universal_singlepass.rs +++ b/fuzz/fuzz_targets/universal_singlepass.rs @@ -3,7 +3,7 @@ use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; use wasm_smith::{Config, ConfiguredModule}; use wasmer::{imports, Instance, Module, Store}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_singlepass::Singlepass; #[derive(Arbitrary, Debug, Default, Copy, Clone)] @@ -40,7 +40,7 @@ fuzz_target!(|module: WasmSmithModule| { } let compiler = Singlepass::default(); - let mut store = Store::new_with_engine(&Backend::new(compiler).engine()); + let mut store = Store::new_with_engine(&EngineBuilder::new(compiler, None, None).engine()); let module = Module::new(&store, &wasm_bytes); let module = match module { Ok(m) => m, diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index 5845d2563e9..de08fefe504 100644 --- a/lib/api/Cargo.toml +++ b/lib/api/Cargo.toml @@ -88,32 +88,22 @@ std = [] core = ["hashbrown"] # Features for `sys`. -sys = [] -sys-default = ["sys", "wat", "default-cranelift", "default-engine_compilation"] +sys = [ + "wasmer-compiler/translator", + "wasmer-compiler/compiler", +] +sys-default = ["sys", "wat", "cranelift"] # - Compilers. compiler = [ "sys", - "wasmer-compiler/translator", ] singlepass = ["compiler", "wasmer-compiler-singlepass"] cranelift = ["compiler", "wasmer-compiler-cranelift"] llvm = ["compiler", "wasmer-compiler-llvm"] -default-compiler = [] -default-singlepass = ["default-compiler", "singlepass"] -default-cranelift = ["default-compiler", "cranelift"] -default-llvm = ["default-compiler", "llvm"] # - Engines. engine = ["sys"] -engine_compilation = [ - "engine", "wasmer-compiler/engine_compilation" -] -default-engine = [] -default-engine_compilation = [ - "default-engine", - "engine_compilation", -] # - Deprecated features. -jit = ["engine_compilation"] +jit = ["engine"] # Features for `js`. js = ["wasm-bindgen", "js-sys"] @@ -124,4 +114,4 @@ wasm-types-polyfill = ["js", "wasmparser"] js-serializable-module = [] [package.metadata.docs.rs] -features = ["compiler", "core", "cranelift", "default-compiler", "default-engine", "engine", "jit", "native", "singlepass", "sys", "sys-default", "engine_compilation"] +features = ["compiler", "core", "cranelift", "engine", "jit", "native", "singlepass", "sys", "sys-default" ] diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index 300362667dc..b26505906ee 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -307,8 +307,8 @@ #![cfg_attr(not(feature = "wat"), doc = "(disabled),")] //! enables `wasmer` to parse the WebAssembly text format, //! - `compilation` -#![cfg_attr(feature = "compilation", doc = "(enabled),")] -#![cfg_attr(not(feature = "compilation"), doc = "(disabled),")] +#![cfg_attr(feature = "compiler", doc = "(enabled),")] +#![cfg_attr(not(feature = "compiler"), doc = "(disabled),")] //! enables compilation with the wasmer engine. //! //! The features that set defaults come in sets that are mutually exclusive. diff --git a/lib/api/src/sys/mod.rs b/lib/api/src/sys/mod.rs index 9c02858aab8..e2bfd38f805 100644 --- a/lib/api/src/sys/mod.rs +++ b/lib/api/src/sys/mod.rs @@ -64,26 +64,6 @@ pub mod vm { #[cfg(feature = "wat")] pub use wat::parse_bytes as wat2wasm; -// The compilers are mutually exclusive -#[cfg(any( - all( - feature = "default-llvm", - any(feature = "default-cranelift", feature = "default-singlepass") - ), - all(feature = "default-cranelift", feature = "default-singlepass") -))] -compile_error!( - r#"The `default-singlepass`, `default-cranelift` and `default-llvm` features are mutually exclusive. -If you wish to use more than one compiler, you can simply create the own store. Eg.: - -``` -use wasmer::{Store, Backend, Singlepass}; - -let engine = Backend::new(Singlepass::default()).engine(); -let mut store = Store::new_with_engine(&engine); -```"# -); - #[cfg(feature = "singlepass")] pub use wasmer_compiler_singlepass::Singlepass; @@ -93,17 +73,13 @@ pub use wasmer_compiler_cranelift::{Cranelift, CraneliftOptLevel}; #[cfg(feature = "llvm")] pub use wasmer_compiler_llvm::{LLVMOptLevel, LLVM}; -#[cfg(feature = "engine_compilation")] -pub use wasmer_compiler::{Artifact, Backend, Engine}; +pub use wasmer_compiler::Engine; +#[cfg(feature = "compiler")] +pub use wasmer_compiler::{Artifact, EngineBuilder}; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); -/// The Deprecated JIT Engine (please use `Universal` instead) -#[cfg(feature = "jit")] -#[deprecated(since = "2.0.0", note = "Please use the `universal` feature instead")] -pub type JIT = Backend; - /// This type is deprecated, it has been replaced by TypedFunction. #[deprecated( since = "3.0.0", diff --git a/lib/api/src/sys/store.rs b/lib/api/src/sys/store.rs index b455927837b..21350cd3906 100644 --- a/lib/api/src/sys/store.rs +++ b/lib/api/src/sys/store.rs @@ -4,7 +4,7 @@ use std::sync::{Arc, RwLock}; #[cfg(feature = "compiler")] use wasmer_compiler::CompilerConfig; #[cfg(feature = "compiler")] -use wasmer_compiler::{Backend, Engine, Tunables}; +use wasmer_compiler::{Engine, EngineBuilder, Tunables}; use wasmer_vm::{init_traps, TrapHandler, TrapHandlerFn}; use wasmer_vm::StoreObjects; @@ -39,7 +39,7 @@ impl Store { #[cfg(feature = "compiler")] /// Creates a new `Store` with a specific [`CompilerConfig`]. pub fn new(compiler_config: Box) -> Self { - let engine = Backend::new(compiler_config).engine(); + let engine = EngineBuilder::new(compiler_config, None, None).engine(); Self::new_with_tunables(&engine, BaseTunables::for_target(engine.target())) } @@ -120,20 +120,21 @@ unsafe impl Send for Store {} unsafe impl Sync for Store {} // We only implement default if we have assigned a default compiler and engine -#[cfg(all(feature = "default-compiler", feature = "default-engine"))] +#[cfg(feature = "compiler")] impl Default for Store { fn default() -> Self { // We store them on a function that returns to make // sure this function doesn't emit a compile error even if // more than one compiler is enabled. #[allow(unreachable_code)] + #[cfg(any(feature = "cranelift", feature = "llvm", feature = "singlepass"))] fn get_config() -> impl CompilerConfig + 'static { cfg_if::cfg_if! { - if #[cfg(feature = "default-cranelift")] { + if #[cfg(feature = "cranelift")] { wasmer_compiler_cranelift::Cranelift::default() - } else if #[cfg(feature = "default-llvm")] { + } else if #[cfg(feature = "llvm")] { wasmer_compiler_llvm::LLVM::default() - } else if #[cfg(feature = "default-singlepass")] { + } else if #[cfg(feature = "singlepass")] { wasmer_compiler_singlepass::Singlepass::default() } else { compile_error!("No default compiler chosen") @@ -142,19 +143,28 @@ impl Default for Store { } #[allow(unreachable_code, unused_mut)] - fn get_engine(mut config: impl CompilerConfig + 'static) -> Engine { + fn get_engine() -> Engine { + cfg_if::cfg_if! { + if #[cfg(feature = "compiler")] { + cfg_if::cfg_if! { - if #[cfg(feature = "engine_compilation")] { - wasmer_compiler::Backend::new(config) + if #[cfg(any(feature = "cranelift", feature = "llvm", feature = "singlepass"))] + { + let config = get_config(); + wasmer_compiler::EngineBuilder::new(Box::new(config) as Box, None, None) .engine() + } else { + wasmer_compiler::EngineBuilder::headless() + .engine() + } + } } else { compile_error!("No default engine chosen") } } } - let config = get_config(); - let engine = get_engine(config); + let engine = get_engine(); let tunables = BaseTunables::for_target(engine.target()); Self::new_with_tunables(&engine, tunables) } diff --git a/lib/c-api/Cargo.toml b/lib/c-api/Cargo.toml index aebcab09deb..9b3a93f4d3c 100644 --- a/lib/c-api/Cargo.toml +++ b/lib/c-api/Cargo.toml @@ -48,7 +48,7 @@ inline-c = "0.1.5" default = [ "wat", "cranelift", - "compilation", + "compiler", "wasi", "middlewares", ] @@ -58,12 +58,15 @@ middlewares = [ "compiler", "wasmer-middlewares", ] -compilation = [ - "wasmer-compiler/engine_compilation", - "compiler", -] compiler = [ "wasmer-api/compiler", + "wasmer-compiler/translator", + "wasmer-compiler/compiler", +] +compiler-headless = [ + "wasmer-api/compiler", + "wasmer-compiler/translator", + "wasmer-compiler/compiler", ] singlepass = [ "wasmer-compiler-singlepass", @@ -79,7 +82,7 @@ llvm = [ ] # Deprecated features. -jit = ["compilation"] +jit = ["compiler"] # TODO: Port this feature. #emscripten = ["wasmer-emscripten"] diff --git a/lib/c-api/build.rs b/lib/c-api/build.rs index 0a8c744a6ef..40f9ab820f0 100644 --- a/lib/c-api/build.rs +++ b/lib/c-api/build.rs @@ -140,7 +140,7 @@ fn build_wasm_c_api_headers(crate_dir: &str, out_dir: &str) { pre_header = PRE_HEADER ); - map_feature_as_c_define!("compilation", UNIVERSAL_FEATURE_AS_C_DEFINE, pre_header); + map_feature_as_c_define!("compiler", UNIVERSAL_FEATURE_AS_C_DEFINE, pre_header); map_feature_as_c_define!("compiler", COMPILER_FEATURE_AS_C_DEFINE, pre_header); map_feature_as_c_define!("wasi", WASI_FEATURE_AS_C_DEFINE, pre_header); map_feature_as_c_define!("middlewares", MIDDLEWARES_FEATURE_AS_C_DEFINE, pre_header); diff --git a/lib/c-api/src/wasm_c_api/engine.rs b/lib/c-api/src/wasm_c_api/engine.rs index 6d0e4b076e2..e16da83c59f 100644 --- a/lib/c-api/src/wasm_c_api/engine.rs +++ b/lib/c-api/src/wasm_c_api/engine.rs @@ -1,8 +1,6 @@ #[cfg(feature = "compiler")] pub use super::unstable::engine::wasmer_is_compiler_available; -pub use super::unstable::engine::{ - wasm_config_set_features, wasm_config_set_target, wasmer_is_engine_available, -}; +pub use super::unstable::engine::{wasm_config_set_features, wasm_config_set_target}; use super::unstable::features::wasmer_features_t; #[cfg(feature = "middlewares")] pub use super::unstable::middlewares::wasm_config_push_middleware; @@ -11,8 +9,7 @@ use super::unstable::middlewares::wasmer_middleware_t; use super::unstable::target_lexicon::wasmer_target_t; use crate::error::update_last_error; use cfg_if::cfg_if; -#[cfg(feature = "compilation")] -use wasmer_compiler::{Backend, Engine}; +use wasmer_compiler::{Engine, EngineBuilder}; /// Kind of compilers that can be used by the engines. /// @@ -67,13 +64,7 @@ pub enum wasmer_engine_t { impl Default for wasmer_engine_t { fn default() -> Self { - cfg_if! { - if #[cfg(feature = "compilation")] { - Self::UNIVERSAL - } else { - compile_error!("Please enable one of the engines") - } - } + Self::UNIVERSAL } } @@ -229,12 +220,6 @@ pub extern "C" fn wasm_config_set_compiler( /// // Create the configuration. /// wasm_config_t* config = wasm_config_new(); /// -/// // Use the Universal engine, if available. -/// if (wasmer_is_engine_available(UNIVERSAL)) { -/// wasm_config_set_engine(config, UNIVERSAL); -/// } -/// // OK, let's do not specify any particular engine. -/// /// // Create the engine. /// wasm_engine_t* engine = wasm_engine_new_with_config(config); /// @@ -267,7 +252,7 @@ pub struct wasm_engine_t { #[cfg(feature = "compiler")] use wasmer_api::CompilerConfig; -#[cfg(all(feature = "compiler", any(feature = "compilation", feature = "dylib")))] +#[cfg(all(feature = "compiler", any(feature = "compiler", feature = "dylib")))] fn get_default_compiler_config() -> Box { cfg_if! { if #[cfg(feature = "cranelift")] { @@ -283,7 +268,7 @@ fn get_default_compiler_config() -> Box { } cfg_if! { - if #[cfg(all(feature = "compilation", feature = "compiler"))] { + if #[cfg(feature = "compiler")] { /// Creates a new Universal engine with the default compiler. /// /// # Example @@ -294,10 +279,10 @@ cfg_if! { #[no_mangle] pub extern "C" fn wasm_engine_new() -> Box { let compiler_config: Box = get_default_compiler_config(); - let engine: Engine = Backend::new(compiler_config).engine(); + let engine: Engine = EngineBuilder::new(compiler_config, None, None).engine(); Box::new(wasm_engine_t { inner: engine }) } - } else if #[cfg(feature = "compilation")] { + } else if #[cfg(feature = "compiler-headless")] { /// Creates a new headless Universal engine. /// /// # Example @@ -307,7 +292,7 @@ cfg_if! { /// cbindgen:ignore #[no_mangle] pub extern "C" fn wasm_engine_new() -> Box { - let engine: Engine = Backend::headless().engine(); + let engine: Engine = EngineBuilder::headless().engine(); Box::new(wasm_engine_t { inner: engine }) } } else { @@ -320,7 +305,7 @@ cfg_if! { /// cbindgen:ignore #[no_mangle] pub extern "C" fn wasm_engine_new() -> Box { - unimplemented!("No engine attached; You might want to recompile `wasmer_c_api` with for example `--feature compilation`"); + unimplemented!("No engine attached; You might want to recompile `wasmer_c_api` with for example `--feature compiler`"); } } } @@ -374,7 +359,8 @@ pub extern "C" fn wasm_engine_new_with_config( } let config = config?; - + #[cfg(not(any(feature = "compiler", feature = "compiler-headless")))] + return return_with_error("Wasmer has not been compiled with the `compiler` feature."); cfg_if! { if #[cfg(feature = "compiler")] { #[allow(unused_mut)] @@ -417,19 +403,16 @@ pub extern "C" fn wasm_engine_new_with_config( compiler_config.canonicalize_nans(true); } - #[cfg(not(feature = "compilation"))] - return return_with_error("Wasmer has not been compiled with the `compilation` feature."); - #[cfg(feature = "compilation")] let inner: Engine = { - let mut builder = Backend::new(compiler_config); + let mut builder = EngineBuilder::new(compiler_config, None, None); if let Some(target) = config.target { - builder = builder.target(target.inner); + builder.set_target(Some(target.inner)); } if let Some(features) = config.features { - builder = builder.features(features.inner); + builder.set_features(Some(features.inner)); } builder.engine() @@ -437,22 +420,18 @@ pub extern "C" fn wasm_engine_new_with_config( Some(Box::new(wasm_engine_t { inner })) } else { let inner: Engine = - cfg_if! { - if #[cfg(feature = "compilation")] { - let mut builder = Backend::headless(); + { + let mut builder = EngineBuilder::headless(); if let Some(target) = config.target { - builder = builder.target(target.inner); + builder.set_target(Some(target.inner)); } if let Some(features) = config.features { - builder = builder.features(features.inner); + builder.set_features(Some(features.inner)); } builder.engine() - } else { - return return_with_error("Wasmer has not been compiled with the `compilation` feature."); - } }; Some(Box::new(wasm_engine_t { inner })) } diff --git a/lib/c-api/src/wasm_c_api/mod.rs b/lib/c-api/src/wasm_c_api/mod.rs index d04bfe66e25..a79cabb9bb1 100644 --- a/lib/c-api/src/wasm_c_api/mod.rs +++ b/lib/c-api/src/wasm_c_api/mod.rs @@ -62,7 +62,7 @@ mod macros; /// ``` /// /// To configure the engine, see the [`wasm_config_new`][engine::wasm_config_new]. -#[cfg(feature = "compilation")] +#[cfg(any(feature = "compiler", feature = "compiler-headless"))] pub mod engine; /// cbindgen:ignore diff --git a/lib/c-api/src/wasm_c_api/unstable/engine.rs b/lib/c-api/src/wasm_c_api/unstable/engine.rs index ec61e56a355..43f12facbc0 100644 --- a/lib/c-api/src/wasm_c_api/unstable/engine.rs +++ b/lib/c-api/src/wasm_c_api/unstable/engine.rs @@ -161,7 +161,7 @@ pub extern "C" fn wasmer_is_headless() -> bool { /// compiled library. #[no_mangle] pub extern "C" fn wasmer_is_engine_available(engine: wasmer_engine_t) -> bool { - matches!(engine, wasmer_engine_t::UNIVERSAL if cfg!(feature = "compilation")) + matches!(engine, wasmer_engine_t::UNIVERSAL if cfg!(feature = "compiler")) } #[cfg(test)] @@ -234,11 +234,7 @@ mod tests { fn test_wasmer_is_engine_available() { set_var( "UNIVERSAL", - if cfg!(feature = "compilation") { - "1" - } else { - "0" - }, + if cfg!(feature = "compiler") { "1" } else { "0" }, ); (assert_c! { diff --git a/lib/cache/benches/bench_filesystem_cache.rs b/lib/cache/benches/bench_filesystem_cache.rs index 28532cd93a9..4d18ab4145c 100644 --- a/lib/cache/benches/bench_filesystem_cache.rs +++ b/lib/cache/benches/bench_filesystem_cache.rs @@ -6,7 +6,7 @@ use tempfile::TempDir; use wasmer::{Module, Store}; use wasmer_cache::Cache; use wasmer_cache::{FileSystemCache, Hash}; -use wasmer_compiler::Backend; +use wasmer_compiler::EngineBuilder; use wasmer_compiler_singlepass::Singlepass; fn random_key() -> Hash { @@ -17,7 +17,7 @@ pub fn store_cache_universal(c: &mut Criterion) { let tmp_dir = TempDir::new().unwrap(); let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap(); let compiler = Singlepass::default(); - let store = Store::new_with_engine(&Backend::new(compiler).engine()); + let store = Store::new_with_engine(&EngineBuilder::new(compiler, None, None).engine()); let module = Module::new( &store, std::fs::read("../../lib/c-api/examples/assets/qjs.wasm").unwrap(), @@ -36,7 +36,7 @@ pub fn load_cache_universal(c: &mut Criterion) { let tmp_dir = TempDir::new().unwrap(); let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap(); let compiler = Singlepass::default(); - let store = Store::new_with_engine(&Backend::new(compiler).engine()); + let store = Store::new_with_engine(&EngineBuilder::new(compiler, None, None).engine()); let module = Module::new( &store, std::fs::read("../../lib/c-api/examples/assets/qjs.wasm").unwrap(), @@ -54,7 +54,7 @@ pub fn store_cache_native(c: &mut Criterion) { let tmp_dir = TempDir::new().unwrap(); let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap(); let compiler = Singlepass::default(); - let store = Store::new_with_engine(&Backend::new(compiler).engine()); + let store = Store::new_with_engine(&EngineBuilder::new(compiler, None, None).engine()); let module = Module::new( &store, std::fs::read("../../lib/c-api/examples/assets/qjs.wasm").unwrap(), @@ -73,7 +73,7 @@ pub fn load_cache_native(c: &mut Criterion) { let tmp_dir = TempDir::new().unwrap(); let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap(); let compiler = Singlepass::default(); - let store = Store::new_with_engine(&Backend::new(compiler).engine()); + let store = Store::new_with_engine(&EngineBuilder::new(compiler, None, None).engine()); let module = Module::new( &store, std::fs::read("../../lib/c-api/examples/assets/qjs.wasm").unwrap(), diff --git a/lib/cli-compiler/Cargo.toml b/lib/cli-compiler/Cargo.toml index 85252f94d96..dd70bc754eb 100644 --- a/lib/cli-compiler/Cargo.toml +++ b/lib/cli-compiler/Cargo.toml @@ -18,7 +18,7 @@ path = "src/bin/wasmer_compiler.rs" doc = false [dependencies] -wasmer-compiler = { version = "=2.3.0", path = "../compiler", features = ["engine_compilation"] } +wasmer-compiler = { version = "=2.3.0", path = "../compiler", features = ["compiler"] } wasmer-types = { version = "=2.3.0", path = "../types" } atty = "0.2" colored = "2.0" @@ -52,6 +52,7 @@ default = [] engine = [] compiler = [ "wasmer-compiler/translator", + "wasmer-compiler/compiler", ] singlepass = [ "wasmer-compiler-singlepass", diff --git a/lib/cli-compiler/src/commands/compile.rs b/lib/cli-compiler/src/commands/compile.rs index 3e0422a8362..4e39b911df6 100644 --- a/lib/cli-compiler/src/commands/compile.rs +++ b/lib/cli-compiler/src/commands/compile.rs @@ -55,7 +55,8 @@ impl Compile { Target::new(target_triple.clone(), features) }) .unwrap_or_default(); - let (mut engine, compiler_type) = self.store.get_engine_for_target(target.clone())?; + let (engine_builder, compiler_type) = self.store.get_engine_for_target(target.clone())?; + let engine = engine_builder.engine(); let output_filename = self .output .file_stem() @@ -96,7 +97,7 @@ impl Compile { .map(|table_type| tunables.table_style(table_type)) .collect(); let artifact = ArtifactBuild::new( - &mut engine, + &mut engine.inner_mut(), &wasm_bytes, &target, memory_styles, diff --git a/lib/cli-compiler/src/commands/validate.rs b/lib/cli-compiler/src/commands/validate.rs index 3ec12eec764..1e33c36b6c0 100644 --- a/lib/cli-compiler/src/commands/validate.rs +++ b/lib/cli-compiler/src/commands/validate.rs @@ -27,7 +27,8 @@ impl Validate { Triple::from_str("x86_64-linux-gnu").unwrap(), CpuFeature::SSE2 | CpuFeature::AVX, ); - let (engine, _compiler_type) = self.store.get_engine_for_target(target)?; + let (engine_builder, _compiler_type) = self.store.get_engine_for_target(target)?; + let engine = engine_builder.engine(); let module_contents = std::fs::read(&self.path)?; if !is_wasm(&module_contents) { bail!("`wasmer validate` only validates WebAssembly files"); diff --git a/lib/cli-compiler/src/store.rs b/lib/cli-compiler/src/store.rs index 6d788dca23f..2f4ae826fda 100644 --- a/lib/cli-compiler/src/store.rs +++ b/lib/cli-compiler/src/store.rs @@ -174,7 +174,8 @@ impl CompilerOptions { compiler_config: Box, ) -> Result { let features = self.get_features(compiler_config.default_features_for_target(&target))?; - let engine: EngineBuilder = EngineBuilder::new(Some(compiler_config.compiler()), features); + let engine: EngineBuilder = + EngineBuilder::new(compiler_config, Some(target), Some(features)); Ok(engine) } diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index 8294e4056c3..e32976a2460 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -26,7 +26,7 @@ required-features = ["headless"] [dependencies] wasmer = { version = "=2.3.0", path = "../api", default-features = false } -wasmer-compiler = { version = "=2.3.0", path = "../compiler", features = ["engine_compilation", ] } +wasmer-compiler = { version = "=2.3.0", path = "../compiler", features = ["compiler", ] } wasmer-compiler-cranelift = { version = "=2.3.0", path = "../compiler-cranelift", optional = true } wasmer-compiler-singlepass = { version = "=2.3.0", path = "../compiler-singlepass", optional = true } wasmer-compiler-llvm = { version = "=2.3.0", path = "../compiler-llvm", optional = true } @@ -64,7 +64,7 @@ default = [ "cache", "wasi", "emscripten", - "compilation", + "compiler", ] cache = ["wasmer-cache"] cache-blake3-pure = ["wasmer-cache/blake3-pure"] @@ -74,9 +74,7 @@ emscripten = ["wasmer-emscripten"] wat = ["wasmer/wat"] compiler = [ "wasmer-compiler/translator", -] -compilation = [ - "wasmer-compiler/engine_compilation", + "wasmer-compiler/compiler", ] experimental-io-devices = [ "wasmer-wasi-experimental-io-devices", diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index 2b7dd07dfad..75655330325 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -262,7 +262,7 @@ impl Run { fn get_store_module(&self) -> Result<(Store, Module)> { let contents = std::fs::read(self.path.clone())?; if wasmer_compiler::Artifact::is_deserializable(&contents) { - let engine = wasmer_compiler::Backend::headless().engine(); + let engine = wasmer_compiler::EngineBuilder::headless().engine(); let store = Store::new_with_engine(&engine); let module = unsafe { Module::deserialize_from_file(&store, &self.path)? }; return Ok((store, module)); diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index 26f0e69ac37..990c56d2343 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -14,7 +14,6 @@ use structopt::StructOpt; use wasmer::*; #[cfg(feature = "compiler")] use wasmer_compiler::CompilerConfig; -#[cfg(feature = "compilation")] use wasmer_compiler::Engine; #[derive(Debug, Clone, StructOpt, Default)] @@ -110,7 +109,7 @@ impl CompilerOptions { Ok((store, compiler_type)) } - #[cfg(feature = "compilation")] + #[cfg(feature = "compiler")] fn get_engine( &self, target: Target, @@ -118,9 +117,7 @@ impl CompilerOptions { ) -> Result> { let features = self.get_features(compiler_config.default_features_for_target(&target))?; let engine: Box = Box::new( - wasmer_compiler::Backend::new(compiler_config) - .features(features) - .target(target) + wasmer_compiler::EngineBuilder::new(compiler_config, Some(target), Some(features)) .engine(), ); @@ -320,7 +317,7 @@ impl StoreOptions { Ok((store, compiler_type)) } - #[cfg(feature = "compilation")] + #[cfg(feature = "compiler")] fn get_engine_with_compiler( &self, target: Target, @@ -335,9 +332,8 @@ impl StoreOptions { // If we don't have a compiler, but we have an engine #[cfg(not(feature = "compiler"))] impl StoreOptions { - #[cfg(feature = "compilation")] fn get_engine_headless(&self) -> Result { - let engine: Engine = wasmer_compiler::Backend::headless().engine(); + let engine: Engine = wasmer_compiler::EngineBuilder::headless().engine(); Ok(engine) } diff --git a/lib/compiler-cranelift/Cargo.toml b/lib/compiler-cranelift/Cargo.toml index ac22628414f..cdbf85ede5a 100644 --- a/lib/compiler-cranelift/Cargo.toml +++ b/lib/compiler-cranelift/Cargo.toml @@ -12,7 +12,7 @@ readme = "README.md" edition = "2018" [dependencies] -wasmer-compiler = { path = "../compiler", version = "=2.3.0", features = ["translator"], default-features = false } +wasmer-compiler = { path = "../compiler", version = "=2.3.0", features = ["translator", "compiler"], default-features = false } wasmer-types = { path = "../types", version = "=2.3.0", default-features = false, features = ["std"] } cranelift-entity = { version = "0.82", default-features = false } cranelift-codegen = { version = "0.82", default-features = false, features = ["x86", "arm64"] } diff --git a/lib/compiler-cranelift/README.md b/lib/compiler-cranelift/README.md index 0e14174ff8e..e20c2de104f 100644 --- a/lib/compiler-cranelift/README.md +++ b/lib/compiler-cranelift/README.md @@ -5,12 +5,12 @@ This crate contains a compiler implementation based on Cranelift. ## Usage ```rust -use wasmer::{Store, Backend}; +use wasmer::{Store, EngineBuilder}; use wasmer_compiler_cranelift::Cranelift; let compiler = Cranelift::new(); // Put it into an engine and add it to the store -let mut store = Store::new_with_engine(&Backend::new(compiler).engine()); +let mut store = Store::new_with_engine(&EngineBuilder::new(compiler, None, None).engine()); ``` *Note: you can find a [full working example using Cranelift compiler diff --git a/lib/compiler-llvm/Cargo.toml b/lib/compiler-llvm/Cargo.toml index 0a8b822e6e9..4365ef98ada 100644 --- a/lib/compiler-llvm/Cargo.toml +++ b/lib/compiler-llvm/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" [dependencies] wasmer-compiler = { path = "../compiler", version = "=2.3.0", features = [ - "translator", + "translator", "compiler" ] } wasmer-vm = { path = "../vm", version = "=2.3.0" } wasmer-types = { path = "../types", version = "=2.3.0" } diff --git a/lib/compiler-llvm/README.md b/lib/compiler-llvm/README.md index 2bcc315b944..885ce905ff2 100644 --- a/lib/compiler-llvm/README.md +++ b/lib/compiler-llvm/README.md @@ -5,12 +5,12 @@ This crate contains a compiler implementation based on [the LLVM Compiler Infras ## Usage ```rust -use wasmer::{Store, Backend}; +use wasmer::{Store, EngineBuilder}; use wasmer_compiler_llvm::LLVM; let compiler = LLVM::new(); // Put it into an engine and add it to the store -let mut store = Store::new_with_engine(&Backend::new(compiler).engine()); +let mut store = Store::new_with_engine(&EngineBuilder::new(Some(Box::new(compiler)), None, None).engine()); ``` *Note: you can find a [full working example using LLVM compiler here][example].* diff --git a/lib/compiler-singlepass/Cargo.toml b/lib/compiler-singlepass/Cargo.toml index 8a9ab20286e..c5479028fd1 100644 --- a/lib/compiler-singlepass/Cargo.toml +++ b/lib/compiler-singlepass/Cargo.toml @@ -12,7 +12,7 @@ readme = "README.md" edition = "2018" [dependencies] -wasmer-compiler = { path = "../compiler", version = "=2.3.0", features = ["translator"], default-features = false } +wasmer-compiler = { path = "../compiler", version = "=2.3.0", features = ["translator", "compiler"], default-features = false } wasmer-types = { path = "../types", version = "=2.3.0", default-features = false, features = ["std"] } hashbrown = { version = "0.11", optional = true } gimli = { version = "0.26", optional = true } diff --git a/lib/compiler-singlepass/README.md b/lib/compiler-singlepass/README.md index 739603dc91d..dcd99e7bf67 100644 --- a/lib/compiler-singlepass/README.md +++ b/lib/compiler-singlepass/README.md @@ -5,12 +5,12 @@ This crate contains a compiler implementation based on the Singlepass linear com ## Usage ```rust -use wasmer::{Store, Backend}; +use wasmer::{Store, EngineBuilder}; use wasmer_compiler_singlepass::Singlepass; let compiler = Singlepass::new(); // Put it into an engine and add it to the store -let mut store = Store::new_with_engine(&Backend::new(compiler).engine()); +let mut store = Store::new_with_engine(&EngineBuilder::new(compiler, None, None).engine()); ``` *Note: you can find a [full working example using Singlepass compiler diff --git a/lib/compiler/Cargo.toml b/lib/compiler/Cargo.toml index dc5968ea6bb..43be843960e 100644 --- a/lib/compiler/Cargo.toml +++ b/lib/compiler/Cargo.toml @@ -43,7 +43,7 @@ default = ["std", "enable-serde" ] # `CompilerConfig`, as well as the included wasmparser. # Disable this feature if you just want a headless engine. translator = ["wasmparser"] -engine_compilation = [] +compiler = ["translator"] std = ["wasmer-types/std"] core = ["hashbrown", "wasmer-types/core"] enable-serde = ["serde", "serde_bytes", "wasmer-types/enable-serde"] diff --git a/lib/compiler/src/artifact_builders/artifact_builder.rs b/lib/compiler/src/artifact_builders/artifact_builder.rs index 9558c0b2dc2..7a3c9132a17 100644 --- a/lib/compiler/src/artifact_builders/artifact_builder.rs +++ b/lib/compiler/src/artifact_builders/artifact_builder.rs @@ -1,17 +1,19 @@ //! Define `ArtifactBuild` to allow compiling and instantiating to be //! done as separate steps. -#[cfg(feature = "engine_compilation")] +#[cfg(feature = "compiler")] use super::trampoline::{libcall_trampoline_len, make_libcall_trampolines}; +use crate::ArtifactCreate; +#[cfg(feature = "compiler")] +use crate::EngineInner; use crate::Features; use crate::MetadataHeader; -use crate::{ArtifactCreate, EngineBuilder}; -#[cfg(feature = "engine_compilation")] +#[cfg(feature = "compiler")] use crate::{ModuleEnvironment, ModuleMiddlewareChain}; use enumset::EnumSet; use std::mem; use wasmer_types::entity::PrimaryMap; -#[cfg(feature = "engine_compilation")] +#[cfg(feature = "compiler")] use wasmer_types::CompileModuleInfo; use wasmer_types::SerializeError; use wasmer_types::{ @@ -38,16 +40,16 @@ impl ArtifactBuild { } /// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated. - #[cfg(feature = "engine_compilation")] + #[cfg(feature = "compiler")] pub fn new( - inner_engine: &mut EngineBuilder, + inner_engine: &mut EngineInner, data: &[u8], target: &Target, memory_styles: PrimaryMap, table_styles: PrimaryMap, ) -> Result { let environ = ModuleEnvironment::new(); - let features = inner_engine.features(); + let features = inner_engine.features().clone(); let translation = environ.translate(data).map_err(CompileError::Wasm)?; @@ -60,7 +62,7 @@ impl ArtifactBuild { let compile_info = CompileModuleInfo { module, - features: features.clone(), + features, memory_styles, table_styles, }; @@ -117,8 +119,15 @@ impl ArtifactBuild { } /// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated. - #[cfg(not(feature = "engine_compilation"))] - pub fn new(_engine: &EngineBuilder, _data: &[u8]) -> Result { + #[cfg(not(feature = "compiler"))] + #[cfg(not(target_arch = "wasm32"))] + pub fn new( + _inner_engine: &mut EngineInner, + _data: &[u8], + _target: &Target, + _memory_styles: PrimaryMap, + _table_styles: PrimaryMap, + ) -> Result { Err(CompileError::Codegen( "Compilation is not enabled in the engine".to_string(), )) diff --git a/lib/compiler/src/artifact_builders/mod.rs b/lib/compiler/src/artifact_builders/mod.rs index 9e3e228bc44..0ac7fb40edb 100644 --- a/lib/compiler/src/artifact_builders/mod.rs +++ b/lib/compiler/src/artifact_builders/mod.rs @@ -1,9 +1,7 @@ //! Generic Artifact abstraction for Wasmer Engines. mod artifact_builder; -mod engine_builder; mod trampoline; pub use self::artifact_builder::ArtifactBuild; -pub use self::engine_builder::EngineBuilder; pub use self::trampoline::*; diff --git a/lib/compiler/src/engine/artifact.rs b/lib/compiler/src/engine/artifact.rs index 1409ecde6f5..778c6224a78 100644 --- a/lib/compiler/src/engine/artifact.rs +++ b/lib/compiler/src/engine/artifact.rs @@ -1,17 +1,17 @@ //! Define `Artifact`, based on `ArtifactBuild` //! to allow compiling and instantiating to be done as separate steps. -use crate::engine::inner::{Engine, EngineInner}; use crate::engine::link::link_module; use crate::ArtifactBuild; use crate::ArtifactCreate; use crate::Features; -#[cfg(feature = "engine_compilation")] +#[cfg(feature = "compiler")] use crate::ModuleEnvironment; use crate::{ register_frame_info, resolve_imports, FunctionExtent, GlobalFrameInfoRegistration, InstantiationError, MetadataHeader, RuntimeError, Tunables, }; +use crate::{Engine, EngineInner}; use enumset::EnumSet; use std::sync::Arc; use std::sync::Mutex; @@ -37,7 +37,7 @@ pub struct Artifact { impl Artifact { /// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated. - #[cfg(feature = "engine_compilation")] + #[cfg(feature = "compiler")] pub fn new( engine: &Engine, data: &[u8], @@ -59,7 +59,7 @@ impl Artifact { .collect(); let artifact = ArtifactBuild::new( - inner_engine.builder_mut(), + &mut inner_engine, data, engine.target(), memory_styles, @@ -70,7 +70,7 @@ impl Artifact { } /// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated. - #[cfg(not(feature = "engine_compilation"))] + #[cfg(not(feature = "compiler"))] pub fn new(_engine: &Engine, _data: &[u8]) -> Result { Err(CompileError::Codegen( "Compilation is not enabled in the engine".to_string(), diff --git a/lib/compiler/src/engine/backend.rs b/lib/compiler/src/engine/builder.rs similarity index 54% rename from lib/compiler/src/engine/backend.rs rename to lib/compiler/src/engine/builder.rs index 9b734e187b7..bf97f86811d 100644 --- a/lib/compiler/src/engine/backend.rs +++ b/lib/compiler/src/engine/builder.rs @@ -1,25 +1,27 @@ use super::Engine; -use crate::{CompilerConfig, Features}; -use wasmer_types::Target; +use crate::CompilerConfig; +use wasmer_types::{Features, Target}; -/// The Backend builder -pub struct Backend { - #[allow(dead_code)] +/// The Builder contents of `Engine` +pub struct EngineBuilder { + /// The compiler compiler_config: Option>, + /// The machine target target: Option, + /// The features to compile the Wasm module with features: Option, } -impl Backend { - /// Create a new Backend - pub fn new(compiler_config: T) -> Self +impl EngineBuilder { + /// Create a new builder with pre-made components + pub fn new(compiler_config: T, target: Option, features: Option) -> Self where T: Into>, { Self { compiler_config: Some(compiler_config.into()), - target: None, - features: None, + target, + features, } } @@ -33,35 +35,39 @@ impl Backend { } /// Set the target - pub fn target(mut self, target: Target) -> Self { - self.target = Some(target); + pub fn set_target(&mut self, target: Option) -> &mut Self { + self.target = target; self } /// Set the features - pub fn features(mut self, features: Features) -> Self { - self.features = Some(features); + pub fn set_features(&mut self, features: Option) -> &mut Self { + self.features = features; self } /// Build the `Engine` for this configuration - #[cfg(feature = "engine_compilation")] + #[cfg(feature = "compiler")] pub fn engine(self) -> Engine { let target = self.target.unwrap_or_default(); if let Some(compiler_config) = self.compiler_config { let features = self .features .unwrap_or_else(|| compiler_config.default_features_for_target(&target)); - let compiler = compiler_config.compiler(); - Engine::new(compiler, target, features) + Engine::new(compiler_config, target, features) } else { Engine::headless() } } /// Build the `Engine` for this configuration - #[cfg(not(feature = "engine_compilation"))] + #[cfg(not(feature = "compiler"))] pub fn engine(self) -> Engine { Engine::headless() } + + /// The Wasm features + pub fn features(&self) -> Option<&Features> { + self.features.as_ref() + } } diff --git a/lib/compiler/src/engine/error.rs b/lib/compiler/src/engine/error.rs index a1489585bbb..3ee5860646d 100644 --- a/lib/compiler/src/engine/error.rs +++ b/lib/compiler/src/engine/error.rs @@ -1,4 +1,5 @@ //! The WebAssembly possible errors +#[cfg(not(target_arch = "wasm32"))] use crate::engine::trap::RuntimeError; use thiserror::Error; pub use wasmer_types::{DeserializeError, ImportError, SerializeError}; @@ -16,6 +17,7 @@ pub enum LinkError { #[error("Error while importing {0:?}.{1:?}: {2}")] Import(String, String, ImportError), + #[cfg(not(target_arch = "wasm32"))] /// A trap ocurred during linking. #[error("RuntimeError occurred during linking: {0}")] Trap(#[source] RuntimeError), @@ -44,6 +46,7 @@ pub enum InstantiationError { CpuFeature(String), /// A runtime error occured while invoking the start function + #[cfg(not(target_arch = "wasm32"))] #[error(transparent)] Start(RuntimeError), } diff --git a/lib/compiler/src/engine/inner.rs b/lib/compiler/src/engine/inner.rs index ee263594d40..6b902bbf0e7 100644 --- a/lib/compiler/src/engine/inner.rs +++ b/lib/compiler/src/engine/inner.rs @@ -1,21 +1,28 @@ //! Universal compilation. -#[cfg(feature = "engine_compilation")] -use crate::Compiler; -use crate::EngineBuilder; -use crate::{Artifact, CodeMemory}; +#[cfg(not(target_arch = "wasm32"))] +use crate::Artifact; +#[cfg(not(target_arch = "wasm32"))] +use crate::CodeMemory; +#[cfg(feature = "compiler")] +use crate::{Compiler, CompilerConfig}; +#[cfg(not(target_arch = "wasm32"))] use crate::{FunctionExtent, Tunables}; +#[cfg(not(target_arch = "wasm32"))] use memmap2::Mmap; +#[cfg(not(target_arch = "wasm32"))] use std::path::Path; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; use std::sync::{Arc, Mutex}; -use wasmer_types::entity::PrimaryMap; -use wasmer_types::FunctionBody; +#[cfg(not(target_arch = "wasm32"))] use wasmer_types::{ - CompileError, DeserializeError, Features, FunctionIndex, FunctionType, LocalFunctionIndex, - ModuleInfo, SignatureIndex, Target, + entity::PrimaryMap, DeserializeError, FunctionBody, FunctionIndex, FunctionType, + LocalFunctionIndex, ModuleInfo, SignatureIndex, }; +use wasmer_types::{CompileError, Features, Target}; +#[cfg(not(target_arch = "wasm32"))] use wasmer_types::{CustomSection, CustomSectionProtection, SectionIndex}; +#[cfg(not(target_arch = "wasm32"))] use wasmer_vm::{ FunctionBodyPtr, SectionBodyPtr, SignatureRegistry, VMFunctionBody, VMSharedSignatureIndex, VMTrampoline, @@ -32,12 +39,19 @@ pub struct Engine { impl Engine { /// Create a new `Engine` with the given config - #[cfg(feature = "engine_compilation")] - pub fn new(compiler: Box, target: Target, features: Features) -> Self { + #[cfg(feature = "compiler")] + pub fn new( + compiler_config: Box, + target: Target, + features: Features, + ) -> Self { Self { inner: Arc::new(Mutex::new(EngineInner { - builder: EngineBuilder::new(Some(compiler), features), + compiler: Some(compiler_config.compiler()), + features, + #[cfg(not(target_arch = "wasm32"))] code_memory: vec![], + #[cfg(not(target_arch = "wasm32"))] signatures: SignatureRegistry::new(), })), target: Arc::new(target), @@ -61,8 +75,11 @@ impl Engine { pub fn headless() -> Self { Self { inner: Arc::new(Mutex::new(EngineInner { - builder: EngineBuilder::new(None, Features::default()), + compiler: None, + features: Features::default(), + #[cfg(not(target_arch = "wasm32"))] code_memory: vec![], + #[cfg(not(target_arch = "wasm32"))] signatures: SignatureRegistry::new(), })), target: Arc::new(Target::default()), @@ -70,11 +87,13 @@ impl Engine { } } - pub(crate) fn inner(&self) -> std::sync::MutexGuard<'_, EngineInner> { + /// Get reference to `EngineInner`. + pub fn inner(&self) -> std::sync::MutexGuard<'_, EngineInner> { self.inner.lock().unwrap() } - pub(crate) fn inner_mut(&self) -> std::sync::MutexGuard<'_, EngineInner> { + /// Get mutable reference to `EngineInner`. + pub fn inner_mut(&self) -> std::sync::MutexGuard<'_, EngineInner> { self.inner.lock().unwrap() } @@ -84,12 +103,14 @@ impl Engine { } /// Register a signature + #[cfg(not(target_arch = "wasm32"))] pub fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex { let compiler = self.inner(); compiler.signatures().register(func_type) } /// Lookup a signature + #[cfg(not(target_arch = "wasm32"))] pub fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option { let compiler = self.inner(); compiler.signatures().lookup(sig) @@ -101,7 +122,8 @@ impl Engine { } /// Compile a WebAssembly binary - #[cfg(feature = "engine_compilation")] + #[cfg(feature = "compiler")] + #[cfg(not(target_arch = "wasm32"))] pub fn compile( &self, binary: &[u8], @@ -111,7 +133,8 @@ impl Engine { } /// Compile a WebAssembly binary - #[cfg(not(feature = "engine_compilation"))] + #[cfg(not(feature = "compiler"))] + #[cfg(not(target_arch = "wasm32"))] pub fn compile( &self, _binary: &[u8], @@ -122,6 +145,7 @@ impl Engine { )) } + #[cfg(not(target_arch = "wasm32"))] /// Deserializes a WebAssembly module /// /// # Safety @@ -131,6 +155,7 @@ impl Engine { Ok(Arc::new(Artifact::deserialize(self, bytes)?)) } + #[cfg(not(target_arch = "wasm32"))] /// Deserializes a WebAssembly module from a path /// /// # Safety @@ -162,38 +187,47 @@ impl Engine { /// The inner contents of `Engine` pub struct EngineInner { - /// The builder (include compiler and cpu features) - builder: EngineBuilder, + #[cfg(feature = "compiler")] + /// The compiler and cpu features + compiler: Option>, + #[cfg(feature = "compiler")] + /// The compiler and cpu features + features: Features, /// The code memory is responsible of publishing the compiled /// functions to memory. + #[cfg(not(target_arch = "wasm32"))] code_memory: Vec, /// The signature registry is used mainly to operate with trampolines /// performantly. + #[cfg(not(target_arch = "wasm32"))] signatures: SignatureRegistry, } impl EngineInner { /// Gets the compiler associated to this engine. - #[cfg(feature = "engine_compilation")] + #[cfg(feature = "compiler")] pub fn compiler(&self) -> Result<&dyn Compiler, CompileError> { - self.builder.compiler() + match self.compiler.as_ref() { + None => Err(CompileError::Codegen( + "The Engine is not compiled in.".to_string(), + )), + Some(compiler) => Ok(&**compiler), + } } /// Validate the module pub fn validate(&self, data: &[u8]) -> Result<(), CompileError> { - self.builder.validate(data) + let compiler = self.compiler()?; + compiler.validate_module(&self.features, data) } /// The Wasm features pub fn features(&self) -> &Features { - self.builder.features() - } - - pub fn builder_mut(&mut self) -> &mut EngineBuilder { - &mut self.builder + &self.features } /// Allocate compiled functions into memory + #[cfg(not(target_arch = "wasm32"))] #[allow(clippy::type_complexity)] pub(crate) fn allocate( &mut self, @@ -286,11 +320,13 @@ impl EngineInner { )) } + #[cfg(not(target_arch = "wasm32"))] /// Make memory containing compiled code executable. pub(crate) fn publish_compiled_code(&mut self) { self.code_memory.last_mut().unwrap().publish(); } + #[cfg(not(target_arch = "wasm32"))] /// Register DWARF-type exception handling information associated with the code. pub(crate) fn publish_eh_frame(&mut self, eh_frame: Option<&[u8]>) -> Result<(), CompileError> { self.code_memory @@ -305,6 +341,7 @@ impl EngineInner { } /// Shared signature registry. + #[cfg(not(target_arch = "wasm32"))] pub fn signatures(&self) -> &SignatureRegistry { &self.signatures } diff --git a/lib/compiler/src/engine/mod.rs b/lib/compiler/src/engine/mod.rs index d78d521d6cb..c382be7959b 100644 --- a/lib/compiler/src/engine/mod.rs +++ b/lib/compiler/src/engine/mod.rs @@ -1,35 +1,48 @@ //! The Wasmer Engine. mod error; +#[cfg(not(target_arch = "wasm32"))] mod resolver; +#[cfg(not(target_arch = "wasm32"))] mod trap; +#[cfg(not(target_arch = "wasm32"))] mod tunables; #[cfg(feature = "translator")] +#[cfg(not(target_arch = "wasm32"))] mod artifact; #[cfg(feature = "translator")] -mod backend; +mod builder; #[cfg(feature = "translator")] +#[cfg(not(target_arch = "wasm32"))] mod code_memory; #[cfg(feature = "translator")] mod inner; #[cfg(feature = "translator")] +#[cfg(not(target_arch = "wasm32"))] mod link; #[cfg(feature = "translator")] +#[cfg(not(target_arch = "wasm32"))] mod unwind; pub use self::error::{InstantiationError, LinkError}; +#[cfg(not(target_arch = "wasm32"))] pub use self::resolver::resolve_imports; +#[cfg(not(target_arch = "wasm32"))] pub use self::trap::*; +#[cfg(not(target_arch = "wasm32"))] pub use self::tunables::Tunables; #[cfg(feature = "translator")] +#[cfg(not(target_arch = "wasm32"))] pub use self::artifact::Artifact; #[cfg(feature = "translator")] -pub use self::backend::Backend; +pub use self::builder::EngineBuilder; #[cfg(feature = "translator")] +#[cfg(not(target_arch = "wasm32"))] pub use self::code_memory::CodeMemory; #[cfg(feature = "translator")] -pub use self::inner::Engine; +pub use self::inner::{Engine, EngineInner}; #[cfg(feature = "translator")] +#[cfg(not(target_arch = "wasm32"))] pub use self::link::link_module; diff --git a/lib/compiler/src/lib.rs b/lib/compiler/src/lib.rs index 8ef41ca3779..09a32d32e30 100644 --- a/lib/compiler/src/lib.rs +++ b/lib/compiler/src/lib.rs @@ -51,11 +51,9 @@ mod lib { } } -#[cfg(not(target_arch = "wasm32"))] mod engine; mod traits; -#[cfg(not(target_arch = "wasm32"))] pub use crate::engine::*; pub use crate::traits::*; diff --git a/lib/middlewares/src/metering.rs b/lib/middlewares/src/metering.rs index 2dd876a60f3..e16ef16aad2 100644 --- a/lib/middlewares/src/metering.rs +++ b/lib/middlewares/src/metering.rs @@ -354,7 +354,7 @@ mod tests { use std::sync::Arc; use wasmer::{ - imports, wat2wasm, Backend, CompilerConfig, Cranelift, Module, Store, TypedFunction, + imports, wat2wasm, CompilerConfig, Cranelift, EngineBuilder, Module, Store, TypedFunction, }; fn cost_function(operator: &Operator) -> u64 { @@ -386,7 +386,8 @@ mod tests { let metering = Arc::new(Metering::new(10, cost_function)); let mut compiler_config = Cranelift::default(); compiler_config.push_middleware(metering); - let mut store = Store::new_with_engine(&Backend::new(compiler_config).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(compiler_config, None, None).engine()); let module = Module::new(&store, bytecode()).unwrap(); // Instantiate @@ -434,7 +435,8 @@ mod tests { let metering = Arc::new(Metering::new(10, cost_function)); let mut compiler_config = Cranelift::default(); compiler_config.push_middleware(metering); - let mut store = Store::new_with_engine(&Backend::new(compiler_config).engine()); + let mut store = + Store::new_with_engine(&EngineBuilder::new(compiler_config, None, None).engine()); let module = Module::new(&store, bytecode()).unwrap(); // Instantiate diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index 1a454143c80..c9e35a7be83 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -49,7 +49,7 @@ tracing-wasm = "0.2" default = ["sys-default"] sys = ["wasmer/sys"] -sys-default = ["wasmer/wat", "wasmer/default-engine_compilation", "sys", "logging", "host-fs", "sys-poll", "host-vnet" ] +sys-default = ["wasmer/wat", "wasmer/compiler", "sys", "logging", "host-fs", "sys-poll", "host-vnet" ] sys-poll = [] js = ["wasmer/js", "mem-fs", "wasmer-vfs/no-time", "getrandom/js", "chrono"] diff --git a/tests/compilers/config.rs b/tests/compilers/config.rs index ce7784738c4..d150a73bf93 100644 --- a/tests/compilers/config.rs +++ b/tests/compilers/config.rs @@ -51,15 +51,15 @@ impl Config { } pub fn engine(&self, compiler_config: Box) -> Box { - let mut engine = wasmer_compiler::Backend::new(compiler_config); + let mut engine = wasmer_compiler::EngineBuilder::new(compiler_config, None, None); if let Some(ref features) = self.features { - engine = engine.features(features.clone()) + engine.set_features(Some(features.clone())); } Box::new(engine.engine()) } pub fn engine_headless(&self) -> Box { - Box::new(wasmer_compiler::Backend::headless().engine()) + Box::new(wasmer_compiler::EngineBuilder::headless().engine()) } pub fn compiler_config(