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

Remove Engine, Artifact traits, merge all Engines into one, make everything rkyv serialazable #3029

Merged
merged 12 commits into from
Jul 25, 2022
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Looking for changes that affect our C API? See the [C API Changelog](lib/c-api/C
- [#2946](https://github.com/wasmerio/wasmer/pull/2946) Remove dylib,staticlib engines in favor of a single Universal engine
- [#2949](https://github.com/wasmerio/wasmer/pull/2949) Switch back to using custom LLVM builds on CI
- #2892 Renamed `get_native_function` to `get_typed_function`, marked former as deprecated.
- [#3029](https://github.com/wasmerio/wasmer/pull/3029) Removed Artifact, Engine traits. Renamed UniversalArtifact to Artifact, and UniversalEngine to Engine.

### Fixed
- [#2963](https://github.com/wasmerio/wasmer/pull/2963) Remove accidental dependency on libwayland and libxcb in ClI
Expand Down
5 changes: 2 additions & 3 deletions Cargo.lock

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

6 changes: 3 additions & 3 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 = ["universal_engine"] }
wasmer-compiler = { version = "=2.3.0", path = "lib/compiler", features = ["engine_compilation"] }
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 @@ -133,8 +133,8 @@ path = "examples/early_exit.rs"
required-features = ["cranelift"]

[[example]]
name = "engine-universal"
path = "examples/engine_universal.rs"
name = "engine"
path = "examples/engine.rs"
required-features = ["cranelift"]

[[example]]
Expand Down
50 changes: 25 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ SHELL=/usr/bin/env bash

# The matrix is the product of the following columns:
#
# |------------|-----------|----------|--------------|-------|
# | Compiler ⨯ Engine ⨯ Platform ⨯ Architecture ⨯ libc |
# |------------|-----------|----------|--------------|-------|
# | Cranelift | Universal | Linux | amd64 | glibc |
# | LLVM | | Darwin | aarch64 | musl |
# | Singlepass | | Windows | | |
# |------------|-----------|----------|--------------|-------|
# |------------|----------|--------------|-------|
# | Compiler ⨯ Platform ⨯ Architecture ⨯ libc |
# |------------|----------|--------------|-------|
# | Cranelift | Linux | amd64 | glibc |
# | LLVM | Darwin | aarch64 | musl |
# | Singlepass | Windows | | |
# |------------|----------|--------------|-------|
#
# Here is what works and what doesn't:
#
# * Cranelift with the Universal engine works everywhere,
# * Cranelift works everywhere,
#
# * LLVM with the Universal engine works on Linux+Darwin/`amd64`,
# * LLVM works on Linux+Darwin/`amd64`,
# but it doesn't work on */`aarch64` or Windows/*.
#
# * Singlepass with the Universal engine works on Linux+Darwin/`amd64`, but
# * Singlepass works on Linux+Darwin/`amd64`, but
# it doesn't work on */`aarch64` or Windows/*.
#
# * Windows isn't tested on `aarch64`, that's why we consider it's not
Expand Down Expand Up @@ -355,11 +355,11 @@ check-wasmer:
$(CARGO_BINARY) check $(CARGO_TARGET) --manifest-path lib/cli/Cargo.toml $(compiler_features) --bin wasmer

check-wasmer-wasm:
$(CARGO_BINARY) check --manifest-path lib/cli-compiler/Cargo.toml --target wasm32-wasi --features singlepass,cranelift,universal --bin wasmer-compiler
$(CARGO_BINARY) check --manifest-path lib/cli-compiler/Cargo.toml --target wasm32-wasi --features singlepass,cranelift --bin wasmer-compiler

check-capi: capi-setup
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) check $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml \
--no-default-features --features wat,universal,wasi,middlewares $(capi_compiler_features)
--no-default-features --features wat,compilation,wasi,middlewares $(capi_compiler_features)

build-wasmer:
$(CARGO_BINARY) build $(CARGO_TARGET) --release --manifest-path lib/cli/Cargo.toml $(compiler_features) --bin wasmer
Expand All @@ -371,7 +371,7 @@ bench:
$(CARGO_BINARY) bench $(CARGO_TARGET) $(compiler_features)

build-wasmer-wasm:
$(CARGO_BINARY) build --release --manifest-path lib/cli-compiler/Cargo.toml --target wasm32-wasi --features singlepass,cranelift,universal --bin wasmer-compiler
$(CARGO_BINARY) build --release --manifest-path lib/cli-compiler/Cargo.toml --target wasm32-wasi --features singlepass,cranelift --bin wasmer-compiler

# For best results ensure the release profile looks like the following
# in Cargo.toml:
Expand Down Expand Up @@ -421,46 +421,46 @@ 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,universal,cranelift,wasi
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) doc $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --no-deps --features wat,compilation,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,universal,wasi,middlewares $(capi_compiler_features)
--no-default-features --features wat,compilation,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,universal,singlepass,wasi,middlewares
--no-default-features --features wat,compilation,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,universal,singlepass,wasi,middlewares
--no-default-features --features wat,compilation,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,universal,cranelift,wasi,middlewares
--no-default-features --features wat,compilation,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,universal,cranelift,wasi,middlewares
--no-default-features --features wat,compilation,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,universal,llvm,wasi,middlewares
--no-default-features --features wat,compilation,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,universal,llvm,wasi,middlewares
--no-default-features --features wat,compilation,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 universal,wasi
--no-default-features --features compilation,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 universal,wasi
--no-default-features --features compilation,wasi

build-capi-headless-ios: capi-setup
RUSTFLAGS="${RUSTFLAGS}" cargo lipo --manifest-path lib/c-api/Cargo.toml --release \
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,universal,wasi,middlewares $(capi_compiler_features) -- --nocapture
--no-default-features --features wat,compilation,wasi,middlewares $(capi_compiler_features) -- --nocapture

test-capi-integration-%:
# Test the Wasmer C API tests for C
Expand Down Expand Up @@ -713,4 +713,4 @@ install-local: package

test-minimal-versions:
rm -f Cargo.lock
cargo +nightly build --tests -Z minimal-versions --all-features
cargo +nightly build --tests -Z minimal-versions --all-features
12 changes: 6 additions & 6 deletions benches/static_and_dynamic_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,22 @@ fn run_static_benchmarks(_c: &mut Criterion) {
#[cfg(feature = "llvm")]
{
let mut store =
Store::new_with_engine(&Universal::new(wasmer_compiler_llvm::LLVM::new()).engine());
Store::new_with_engine(&Backend::new(wasmer_compiler_llvm::LLVM::new()).engine());
run_basic_static_function(&store, "llvm", c);
}

#[cfg(feature = "cranelift")]
{
let mut store = Store::new_with_engine(
&Universal::new(wasmer_compiler_cranelift::Cranelift::new()).engine(),
&Backend::new(wasmer_compiler_cranelift::Cranelift::new()).engine(),
);
run_basic_static_function(&store, "cranelift", c);
}

#[cfg(feature = "singlepass")]
{
let mut store = Store::new_with_engine(
&Universal::new(wasmer_compiler_singlepass::Singlepass::new()).engine(),
&Backend::new(wasmer_compiler_singlepass::Singlepass::new()).engine(),
);
run_basic_static_function(&store, "singlepass", c);
}
Expand All @@ -175,22 +175,22 @@ fn run_dynamic_benchmarks(_c: &mut Criterion) {
#[cfg(feature = "llvm")]
{
let mut store =
Store::new_with_engine(&Universal::new(wasmer_compiler_llvm::LLVM::new()).engine());
Store::new_with_engine(&Backend::new(wasmer_compiler_llvm::LLVM::new()).engine());
run_basic_dynamic_function(&store, "llvm", c);
}

#[cfg(feature = "cranelift")]
{
let mut store = Store::new_with_engine(
&Universal::new(wasmer_compiler_cranelift::Cranelift::new()).engine(),
&Backend::new(wasmer_compiler_cranelift::Cranelift::new()).engine(),
);
run_basic_dynamic_function(&store, "cranelift", c);
}

#[cfg(feature = "singlepass")]
{
let mut store = Store::new_with_engine(
&Universal::new(wasmer_compiler_singlepass::Singlepass::new()).engine(),
&Backend::new(wasmer_compiler_singlepass::Singlepass::new()).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 = Universal::new(compiler_config).engine();
let engine = Backend::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
13 changes: 6 additions & 7 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,17 @@ example.

### Engines

1. [**Universal engine**][engine-universal], explains what an engine is, what the
Universal engine is, and how to set it up. The example completes itself
with the compilation of the Wasm module, its instantiation, and
finally, by calling an exported function.
1. [**Engine**][engine], explains what an engine is and how to set it up. The
example completes itself with the compilation of the Wasm module, its
instantiation, and finally, by calling an exported function.

_Keywords_: Universal, engine, in-memory, executable code.
_Keywords_: engine, in-memory, executable code.

<details>
<summary><em>Execute the example</em></summary>

```shell
$ cargo run --example engine-universal --release --features "cranelift"
$ cargo run --example engine --release --features "cranelift"
```

</details>
Expand Down Expand Up @@ -358,7 +357,7 @@ example.
</details>

[hello-world]: ./hello_world.rs
[engine-universal]: ./engine_universal.rs
[engine]: ./engine.rs
[engine-headless]: ./engine_headless.rs
[compiler-singlepass]: ./compiler_singlepass.rs
[compiler-cranelift]: ./compiler_cranelift.rs
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::Universal;
use wasmer_compiler::Backend;
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(&Universal::new(compiler).engine());
let mut store = Store::new_with_engine(&Backend::new(compiler).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::Universal;
use wasmer_compiler::Backend;
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(&Universal::new(compiler).engine());
let mut store = Store::new_with_engine(&Backend::new(compiler).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::Universal;
use wasmer_compiler::Backend;
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(&Universal::new(compiler).engine());
let mut store = Store::new_with_engine(&Backend::new(compiler).engine());

println!("Compiling module...");
// Let's compile the Wasm module.
Expand Down
4 changes: 2 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::Universal;
use wasmer_compiler::Backend;
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,7 @@ 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(&Universal::new(Cranelift::default()).engine());
let mut store = Store::new_with_engine(&Backend::new(Cranelift::default()).engine());
let env = FunctionEnv::new(&mut store, ());

println!("Compiling module...");
Expand Down
4 changes: 2 additions & 2 deletions examples/engine_universal.rs → 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::Universal;
use wasmer_compiler::Backend;
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 = Universal::new(compiler_config).engine();
let engine = Backend::new(compiler_config).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_cross_compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

use std::str::FromStr;
use wasmer::{wat2wasm, Module, RuntimeError, Store};
use wasmer_compiler::Universal;
use wasmer_compiler::{CpuFeature, Target, Triple};
use wasmer_compiler::Backend;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not call it Engine?

use wasmer_compiler_cranelift::Cranelift;
use wasmer_types::{CpuFeature, Target, Triple};

fn main() -> Result<(), Box<dyn std::error::Error>> {
// Let's declare the Wasm module with the text representation.
Expand Down Expand Up @@ -70,7 +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 = Universal::new(compiler_config)
let engine = Backend::new(compiler_config)
// Here we go.
// Pass the target to the engine! The engine will share
// this information with the compiler.
Expand Down
Loading