Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Backend into EngineBuilder and refactor feature flags #3046

Merged
merged 1 commit into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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"
Expand Down
28 changes: 14 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

#####
#
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
38 changes: 30 additions & 8 deletions benches/static_and_dynamic_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,34 @@ 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);
}

#[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);
}
Expand All @@ -174,23 +185,34 @@ 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);
}

#[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);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/migration_to_3.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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! {})?;
Expand Down
4 changes: 2 additions & 2 deletions examples/compiler_cranelift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
Expand All @@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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.
Expand Down
4 changes: 2 additions & 2 deletions examples/compiler_llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
Expand All @@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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.
Expand Down
4 changes: 2 additions & 2 deletions examples/compiler_singlepass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
Expand All @@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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.
Expand Down
5 changes: 3 additions & 2 deletions examples/early_exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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...");
Expand Down
4 changes: 2 additions & 2 deletions examples/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
Expand Down Expand Up @@ -49,7 +49,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
//
// 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);
Expand Down
10 changes: 2 additions & 8 deletions examples/engine_cross_compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -70,13 +70,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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);
Expand Down
6 changes: 3 additions & 3 deletions examples/engine_headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
Expand Down Expand Up @@ -82,7 +82,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

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);
Expand All @@ -105,7 +105,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
{
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, ());

Expand Down
5 changes: 3 additions & 2 deletions examples/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
Expand All @@ -39,7 +39,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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...");
Expand Down
5 changes: 3 additions & 2 deletions examples/exports_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
Expand All @@ -40,7 +40,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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...");
Expand Down
5 changes: 3 additions & 2 deletions examples/exports_global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
Expand All @@ -40,7 +40,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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...");
Expand Down
Loading