mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-03 11:18:31 +00:00
Merge Backend into EngineBuilder and refactor feature flags
This commit is contained in:
@@ -11,7 +11,7 @@ autoexamples = false
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmer = { version = "=2.3.0", path = "lib/api", default-features = false }
|
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-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-singlepass = { version = "=2.3.0", path = "lib/compiler-singlepass", optional = true }
|
||||||
wasmer-compiler-llvm = { version = "=2.3.0", path = "lib/compiler-llvm", 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"
|
rustc_version = "0.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[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"
|
anyhow = "1.0"
|
||||||
criterion = "0.3"
|
criterion = "0.3"
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
|
|||||||
28
Makefile
28
Makefile
@@ -359,7 +359,7 @@ check-wasmer-wasm:
|
|||||||
|
|
||||||
check-capi: capi-setup
|
check-capi: capi-setup
|
||||||
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) check $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml \
|
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:
|
build-wasmer:
|
||||||
$(CARGO_BINARY) build $(CARGO_TARGET) --release --manifest-path lib/cli/Cargo.toml $(compiler_features) --bin 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
|
# when generating the documentation, we rename it to its
|
||||||
# crate's name. Then we restore the lib's name.
|
# 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
|
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
|
sed "$(SEDI)" -e 's/name = "wasmer_c_api" # ##lib.name##/name = "wasmer" # ##lib.name##/' lib/c-api/Cargo.toml
|
||||||
|
|
||||||
build-capi: capi-setup
|
build-capi: capi-setup
|
||||||
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \
|
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
|
build-capi-singlepass: capi-setup
|
||||||
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \
|
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
|
build-capi-singlepass-universal: capi-setup
|
||||||
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \
|
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
|
build-capi-cranelift: capi-setup
|
||||||
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \
|
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
|
build-capi-cranelift-universal: capi-setup
|
||||||
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \
|
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
|
build-capi-llvm: capi-setup
|
||||||
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \
|
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
|
build-capi-llvm-universal: capi-setup
|
||||||
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \
|
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)
|
# Headless (we include the minimal to be able to run)
|
||||||
|
|
||||||
build-capi-headless-universal: capi-setup
|
build-capi-headless-universal: capi-setup
|
||||||
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \
|
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
|
build-capi-headless-all: capi-setup
|
||||||
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \
|
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
|
build-capi-headless-ios: capi-setup
|
||||||
RUSTFLAGS="${RUSTFLAGS}" cargo lipo --manifest-path lib/c-api/Cargo.toml --release \
|
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-%:
|
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 \
|
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-capi-integration-%:
|
||||||
# Test the Wasmer C API tests for C
|
# 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 += -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:
|
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 lib/cli/Cargo.toml $(compiler_features) -- -D clippy::all
|
||||||
RUSTFLAGS="${RUSTFLAGS}" cargo clippy --manifest-path fuzz/Cargo.toml $(compiler_features) -- -D clippy::all
|
RUSTFLAGS="${RUSTFLAGS}" cargo clippy --manifest-path fuzz/Cargo.toml $(compiler_features) -- -D clippy::all
|
||||||
|
|
||||||
|
|||||||
@@ -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) {
|
fn run_static_benchmarks(_c: &mut Criterion) {
|
||||||
#[cfg(feature = "llvm")]
|
#[cfg(feature = "llvm")]
|
||||||
{
|
{
|
||||||
let mut store =
|
let mut store = Store::new_with_engine(
|
||||||
Store::new_with_engine(&Backend::new(wasmer_compiler_llvm::LLVM::new()).engine());
|
&EngineBuilder::new(Some(wasmer_compiler_llvm::LLVM::new()), None, None).engine(),
|
||||||
|
);
|
||||||
run_basic_static_function(&store, "llvm", c);
|
run_basic_static_function(&store, "llvm", c);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "cranelift")]
|
#[cfg(feature = "cranelift")]
|
||||||
{
|
{
|
||||||
let mut store = Store::new_with_engine(
|
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);
|
run_basic_static_function(&store, "cranelift", c);
|
||||||
}
|
}
|
||||||
@@ -165,7 +171,12 @@ fn run_static_benchmarks(_c: &mut Criterion) {
|
|||||||
#[cfg(feature = "singlepass")]
|
#[cfg(feature = "singlepass")]
|
||||||
{
|
{
|
||||||
let mut store = Store::new_with_engine(
|
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);
|
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) {
|
fn run_dynamic_benchmarks(_c: &mut Criterion) {
|
||||||
#[cfg(feature = "llvm")]
|
#[cfg(feature = "llvm")]
|
||||||
{
|
{
|
||||||
let mut store =
|
let mut store = Store::new_with_engine(
|
||||||
Store::new_with_engine(&Backend::new(wasmer_compiler_llvm::LLVM::new()).engine());
|
&EngineBuilder::new(Some(wasmer_compiler_llvm::LLVM::new()), None, None).engine(),
|
||||||
|
);
|
||||||
run_basic_dynamic_function(&store, "llvm", c);
|
run_basic_dynamic_function(&store, "llvm", c);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "cranelift")]
|
#[cfg(feature = "cranelift")]
|
||||||
{
|
{
|
||||||
let mut store = Store::new_with_engine(
|
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);
|
run_basic_dynamic_function(&store, "cranelift", c);
|
||||||
}
|
}
|
||||||
@@ -190,7 +207,12 @@ fn run_dynamic_benchmarks(_c: &mut Criterion) {
|
|||||||
#[cfg(feature = "singlepass")]
|
#[cfg(feature = "singlepass")]
|
||||||
{
|
{
|
||||||
let mut store = Store::new_with_engine(
|
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);
|
run_basic_dynamic_function(&store, "singlepass", c);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ let wasm_bytes = wat2wasm(
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
let compiler_config = Cranelift::default();
|
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 mut store = Store::new(&engine);
|
||||||
let module = Module::new(&store, wasm_bytes)?;
|
let module = Module::new(&store, wasm_bytes)?;
|
||||||
let instance = Instance::new(&module, &imports! {})?;
|
let instance = Instance::new(&module, &imports! {})?;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{imports, wat2wasm, Instance, Module, Store, Value};
|
use wasmer::{imports, wat2wasm, Instance, Module, Store, Value};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let compiler = Cranelift::default();
|
let compiler = Cranelift::default();
|
||||||
|
|
||||||
// Create the store
|
// 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...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{imports, wat2wasm, Instance, Module, Store, Value};
|
use wasmer::{imports, wat2wasm, Instance, Module, Store, Value};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_llvm::LLVM;
|
use wasmer_compiler_llvm::LLVM;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let compiler = LLVM::default();
|
let compiler = LLVM::default();
|
||||||
|
|
||||||
// Create the store
|
// 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...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{imports, wat2wasm, Instance, Module, Store, Value};
|
use wasmer::{imports, wat2wasm, Instance, Module, Store, Value};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_singlepass::Singlepass;
|
use wasmer_compiler_singlepass::Singlepass;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let compiler = Singlepass::default();
|
let compiler = Singlepass::default();
|
||||||
|
|
||||||
// Create the store
|
// 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...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use wasmer::{
|
|||||||
imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store,
|
imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store,
|
||||||
TypedFunction,
|
TypedFunction,
|
||||||
};
|
};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
// First we need to create an error type that we'll use to signal the end of execution.
|
// 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
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// 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, ());
|
let env = FunctionEnv::new(&mut store, ());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{imports, wat2wasm, Instance, Module, Store, Value};
|
use wasmer::{imports, wat2wasm, Instance, Module, Store, Value};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -49,7 +49,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
//
|
//
|
||||||
// In this case, the engine is `wasmer_compiler` which roughly
|
// In this case, the engine is `wasmer_compiler` which roughly
|
||||||
// means that the executable code will live in memory.
|
// 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.
|
// Create a store, that holds the engine.
|
||||||
let mut store = Store::new_with_engine(&engine);
|
let mut store = Store::new_with_engine(&engine);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use wasmer::{wat2wasm, Module, RuntimeError, Store};
|
use wasmer::{wat2wasm, Module, RuntimeError, Store};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
use wasmer_types::{CpuFeature, Target, Triple};
|
use wasmer_types::{CpuFeature, Target, Triple};
|
||||||
|
|
||||||
@@ -70,13 +70,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// That's where we specify the target for the compiler.
|
// That's where we specify the target for the compiler.
|
||||||
//
|
//
|
||||||
// Use the Universal engine.
|
// Use the Universal engine.
|
||||||
let engine = Backend::new(compiler_config)
|
let mut engine = EngineBuilder::new(compiler_config, Some(target), None).engine();
|
||||||
// Here we go.
|
|
||||||
// Pass the target to the engine! The engine will share
|
|
||||||
// this information with the compiler.
|
|
||||||
.target(target)
|
|
||||||
// Get the engine.
|
|
||||||
.engine();
|
|
||||||
|
|
||||||
// Create a store, that holds the engine.
|
// Create a store, that holds the engine.
|
||||||
let mut store = Store::new_with_engine(&engine);
|
let mut store = Store::new_with_engine(&engine);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ use wasmer::Instance;
|
|||||||
use wasmer::Module;
|
use wasmer::Module;
|
||||||
use wasmer::Store;
|
use wasmer::Store;
|
||||||
use wasmer::Value;
|
use wasmer::Value;
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -82,7 +82,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
println!("Creating univesral engine...");
|
println!("Creating univesral engine...");
|
||||||
// Define the engine that will drive everything.
|
// 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.
|
// Create a store, that holds the engine.
|
||||||
let mut store = Store::new_with_engine(&engine);
|
let mut store = Store::new_with_engine(&engine);
|
||||||
@@ -105,7 +105,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
{
|
{
|
||||||
println!("Creating headless Universal engine...");
|
println!("Creating headless Universal engine...");
|
||||||
// We create a 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 store = Store::new_with_engine(&engine);
|
||||||
let mut env = FunctionEnv::new(&mut store, ());
|
let mut env = FunctionEnv::new(&mut store, ());
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction};
|
use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -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
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// 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, ());
|
let mut env = FunctionEnv::new(&mut store, ());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction, Value};
|
use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction, Value};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -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
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// 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, ());
|
let mut env = FunctionEnv::new(&mut store, ());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
use wasmer::{
|
use wasmer::{
|
||||||
imports, wat2wasm, FunctionEnv, Instance, Module, Mutability, Store, Type, TypedFunction, Value,
|
imports, wat2wasm, FunctionEnv, Instance, Module, Mutability, Store, Type, TypedFunction, Value,
|
||||||
};
|
};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -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
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// 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, ());
|
let mut env = FunctionEnv::new(&mut store, ());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction, WasmPtr};
|
use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction, WasmPtr};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -37,7 +37,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
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// 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, ());
|
let mut env = FunctionEnv::new(&mut store, ());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{imports, wat2wasm, Features, FunctionEnv, Instance, Module, Store, Value};
|
use wasmer::{imports, wat2wasm, Features, FunctionEnv, Instance, Module, Store, Value};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
@@ -36,7 +36,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
features.multi_value(true);
|
features.multi_value(true);
|
||||||
|
|
||||||
// Set up the engine. That's where we define the features!
|
// 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.
|
// Now, let's define the store, and compile the module.
|
||||||
let mut store = Store::new_with_engine(&engine.engine());
|
let mut store = Store::new_with_engine(&engine.engine());
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use wasmer::{
|
|||||||
imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store,
|
imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store,
|
||||||
TypedFunction,
|
TypedFunction,
|
||||||
};
|
};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
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
|
// 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
|
// (`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!
|
// 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`.
|
// 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.
|
// A `Module` is a compiled WebAssembly module that isn't ready to execute yet.
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use wasmer::{
|
|||||||
imports, wat2wasm, Function, FunctionEnv, FunctionType, Global, Instance, Memory, Module,
|
imports, wat2wasm, Function, FunctionEnv, FunctionType, Global, Instance, Memory, Module,
|
||||||
Store, Table, Type, Value,
|
Store, Table, Type, Value,
|
||||||
};
|
};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -44,7 +44,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
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// 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, ());
|
let mut env = FunctionEnv::new(&mut store, ());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ use wasmer::{
|
|||||||
imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, FunctionType, Instance, Module,
|
imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, FunctionType, Instance, Module,
|
||||||
Store, Type, TypedFunction, Value,
|
Store, Type, TypedFunction, Value,
|
||||||
};
|
};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -45,7 +45,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
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// 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, ());
|
let mut env1 = FunctionEnv::new(&mut store, ());
|
||||||
struct MyEnv;
|
struct MyEnv;
|
||||||
let mut env2 = FunctionEnv::new(&mut store, MyEnv {});
|
let mut env2 = FunctionEnv::new(&mut store, MyEnv {});
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ use wasmer::{
|
|||||||
imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store,
|
imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store,
|
||||||
TypedFunction,
|
TypedFunction,
|
||||||
};
|
};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -52,7 +52,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
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// 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...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
use wasmer::{
|
use wasmer::{
|
||||||
imports, wat2wasm, FunctionEnv, Global, Instance, Module, Store, TypedFunction, Value,
|
imports, wat2wasm, FunctionEnv, Global, Instance, Module, Store, TypedFunction, Value,
|
||||||
};
|
};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -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
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// 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, ());
|
let mut env = FunctionEnv::new(&mut store, ());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction};
|
use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -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
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// 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, ());
|
let mut env = FunctionEnv::new(&mut store, ());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ use std::mem;
|
|||||||
use wasmer::{
|
use wasmer::{
|
||||||
imports, wat2wasm, Bytes, FunctionEnv, Instance, Module, Pages, Store, TypedFunction,
|
imports, wat2wasm, Bytes, FunctionEnv, Instance, Module, Pages, Store, TypedFunction,
|
||||||
};
|
};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
// this example is a work in progress:
|
// 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
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// 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, ());
|
let mut env = FunctionEnv::new(&mut store, ());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use std::sync::Arc;
|
|||||||
use wasmer::wasmparser::Operator;
|
use wasmer::wasmparser::Operator;
|
||||||
use wasmer::CompilerConfig;
|
use wasmer::CompilerConfig;
|
||||||
use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction};
|
use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
use wasmer_middlewares::{
|
use wasmer_middlewares::{
|
||||||
metering::{get_remaining_points, set_remaining_points, MeteringPoints},
|
metering::{get_remaining_points, set_remaining_points, MeteringPoints},
|
||||||
@@ -70,7 +70,8 @@ fn main() -> anyhow::Result<()> {
|
|||||||
//
|
//
|
||||||
// We use our previously create compiler configuration
|
// We use our previously create compiler configuration
|
||||||
// with the Universal engine.
|
// 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, ());
|
let mut env = FunctionEnv::new(&mut store, ());
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use wasmer::{
|
|||||||
imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store, TableType,
|
imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store, TableType,
|
||||||
Type, TypedFunction, Value,
|
Type, TypedFunction, Value,
|
||||||
};
|
};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
/// A function we'll call through a table.
|
/// 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.
|
// 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, ());
|
let mut env = FunctionEnv::new(&mut store, ());
|
||||||
// Then compile our Wasm.
|
// Then compile our Wasm.
|
||||||
let module = Module::new(&store, wasm_bytes)?;
|
let module = Module::new(&store, wasm_bytes)?;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use wasmer::{
|
|||||||
wat2wasm, BaseTunables, FunctionEnv, Instance, Memory, MemoryType, Module, Pages, Store,
|
wat2wasm, BaseTunables, FunctionEnv, Instance, Memory, MemoryType, Module, Pages, Store,
|
||||||
TableType, Target, Tunables,
|
TableType, Target, Tunables,
|
||||||
};
|
};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
/// A custom tunables that allows you to set a memory limit.
|
/// A custom tunables that allows you to set a memory limit.
|
||||||
@@ -137,7 +137,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
// Any compiler and any engine do the job here
|
// Any compiler and any engine do the job here
|
||||||
let compiler = Cranelift::default();
|
let compiler = Cranelift::default();
|
||||||
let engine = Backend::new(compiler).engine();
|
let engine = EngineBuilder::new(compiler, None, None).engine();
|
||||||
|
|
||||||
// Here is where the fun begins
|
// Here is where the fun begins
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{FunctionEnv, Instance, Module, Store};
|
use wasmer::{FunctionEnv, Instance, Module, Store};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
use wasmer_wasi::WasiState;
|
use wasmer_wasi::WasiState;
|
||||||
|
|
||||||
@@ -32,7 +32,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
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// 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...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use wasmer::{FunctionEnv, Instance, Module, Store};
|
use wasmer::{FunctionEnv, Instance, Module, Store};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
use wasmer_wasi::{Pipe, WasiState};
|
use wasmer_wasi::{Pipe, WasiState};
|
||||||
|
|
||||||
@@ -29,7 +29,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
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// 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...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target};
|
use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target};
|
||||||
use wasm_smith::{Config, ConfiguredModule};
|
use wasm_smith::{Config, ConfiguredModule};
|
||||||
use wasmer::{CompilerConfig, Engine, Module, Store};
|
use wasmer::{CompilerConfig, Engine, Module, Store};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
use wasmer_compiler_llvm::LLVM;
|
use wasmer_compiler_llvm::LLVM;
|
||||||
use wasmer_compiler_singlepass::Singlepass;
|
use wasmer_compiler_singlepass::Singlepass;
|
||||||
@@ -47,7 +47,7 @@ fuzz_target!(|module: ConfiguredModule<NoImportsConfig>| {
|
|||||||
compiler.enable_verifier();
|
compiler.enable_verifier();
|
||||||
compile_and_compare(
|
compile_and_compare(
|
||||||
"universal-cranelift",
|
"universal-cranelift",
|
||||||
Backend::new(compiler.clone()).engine(),
|
EngineBuilder::new(compiler.clone(), None, None).engine(),
|
||||||
&wasm_bytes,
|
&wasm_bytes,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -56,14 +56,14 @@ fuzz_target!(|module: ConfiguredModule<NoImportsConfig>| {
|
|||||||
compiler.enable_verifier();
|
compiler.enable_verifier();
|
||||||
compile_and_compare(
|
compile_and_compare(
|
||||||
"universal-llvm",
|
"universal-llvm",
|
||||||
Backend::new(compiler.clone()).engine(),
|
EngineBuilder::new(compiler.clone(), None, None).engine(),
|
||||||
&wasm_bytes,
|
&wasm_bytes,
|
||||||
);
|
);
|
||||||
|
|
||||||
let compiler = Singlepass::default();
|
let compiler = Singlepass::default();
|
||||||
compile_and_compare(
|
compile_and_compare(
|
||||||
"universal-singlepass",
|
"universal-singlepass",
|
||||||
Backend::new(compiler.clone()).engine(),
|
EngineBuilder::new(compiler.clone(), None, None).engine(),
|
||||||
&wasm_bytes,
|
&wasm_bytes,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use anyhow::Result;
|
|||||||
use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target};
|
use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target};
|
||||||
use wasm_smith::{Config, ConfiguredModule};
|
use wasm_smith::{Config, ConfiguredModule};
|
||||||
use wasmer::{imports, CompilerConfig, Instance, Module, Store, Val};
|
use wasmer::{imports, CompilerConfig, Instance, Module, Store, Val};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
#[cfg(feature = "cranelift")]
|
#[cfg(feature = "cranelift")]
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
#[cfg(feature = "llvm")]
|
#[cfg(feature = "llvm")]
|
||||||
@@ -48,7 +48,7 @@ impl std::fmt::Debug for WasmSmithModule {
|
|||||||
#[cfg(feature = "singlepass")]
|
#[cfg(feature = "singlepass")]
|
||||||
fn maybe_instantiate_singlepass(wasm_bytes: &[u8]) -> Result<Option<Instance>> {
|
fn maybe_instantiate_singlepass(wasm_bytes: &[u8]) -> Result<Option<Instance>> {
|
||||||
let compiler = Singlepass::default();
|
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 = Module::new(&store, &wasm_bytes);
|
||||||
let module = match module {
|
let module = match module {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
@@ -69,7 +69,7 @@ fn maybe_instantiate_cranelift(wasm_bytes: &[u8]) -> Result<Option<Instance>> {
|
|||||||
let mut compiler = Cranelift::default();
|
let mut compiler = Cranelift::default();
|
||||||
compiler.canonicalize_nans(true);
|
compiler.canonicalize_nans(true);
|
||||||
compiler.enable_verifier();
|
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 module = Module::new(&store, &wasm_bytes)?;
|
||||||
let instance = Instance::new(&module, &imports! {})?;
|
let instance = Instance::new(&module, &imports! {})?;
|
||||||
Ok(Some(instance))
|
Ok(Some(instance))
|
||||||
@@ -80,7 +80,7 @@ fn maybe_instantiate_llvm(wasm_bytes: &[u8]) -> Result<Option<Instance>> {
|
|||||||
let mut compiler = LLVM::default();
|
let mut compiler = LLVM::default();
|
||||||
compiler.canonicalize_nans(true);
|
compiler.canonicalize_nans(true);
|
||||||
compiler.enable_verifier();
|
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 module = Module::new(&store, &wasm_bytes)?;
|
||||||
let instance = Instance::new(&module, &imports! {})?;
|
let instance = Instance::new(&module, &imports! {})?;
|
||||||
Ok(Some(instance))
|
Ok(Some(instance))
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use std::sync::Arc;
|
|||||||
use wasm_smith::{Config, ConfiguredModule};
|
use wasm_smith::{Config, ConfiguredModule};
|
||||||
use wasmer::wasmparser::Operator;
|
use wasmer::wasmparser::Operator;
|
||||||
use wasmer::{imports, CompilerConfig, Instance, Module, Store};
|
use wasmer::{imports, CompilerConfig, Instance, Module, Store};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
use wasmer_middlewares::Metering;
|
use wasmer_middlewares::Metering;
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ fuzz_target!(|module: WasmSmithModule| {
|
|||||||
compiler.enable_verifier();
|
compiler.enable_verifier();
|
||||||
let metering = Arc::new(Metering::new(10, cost));
|
let metering = Arc::new(Metering::new(10, cost));
|
||||||
compiler.push_middleware(metering);
|
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();
|
let module = Module::new(&store, &wasm_bytes).unwrap();
|
||||||
match Instance::new(&module, &imports! {}) {
|
match Instance::new(&module, &imports! {}) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target};
|
use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target};
|
||||||
use wasm_smith::{Config, ConfiguredModule};
|
use wasm_smith::{Config, ConfiguredModule};
|
||||||
use wasmer::{imports, CompilerConfig, Instance, Module, Store};
|
use wasmer::{imports, CompilerConfig, Instance, Module, Store};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
#[derive(Arbitrary, Debug, Default, Copy, Clone)]
|
#[derive(Arbitrary, Debug, Default, Copy, Clone)]
|
||||||
@@ -42,7 +42,7 @@ fuzz_target!(|module: WasmSmithModule| {
|
|||||||
let mut compiler = Cranelift::default();
|
let mut compiler = Cranelift::default();
|
||||||
compiler.canonicalize_nans(true);
|
compiler.canonicalize_nans(true);
|
||||||
compiler.enable_verifier();
|
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();
|
let module = Module::new(&store, &wasm_bytes).unwrap();
|
||||||
match Instance::new(&module, &imports! {}) {
|
match Instance::new(&module, &imports! {}) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target};
|
use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target};
|
||||||
use wasm_smith::{Config, ConfiguredModule};
|
use wasm_smith::{Config, ConfiguredModule};
|
||||||
use wasmer::{imports, CompilerConfig, Instance, Module, Store};
|
use wasmer::{imports, CompilerConfig, Instance, Module, Store};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_llvm::LLVM;
|
use wasmer_compiler_llvm::LLVM;
|
||||||
|
|
||||||
#[derive(Arbitrary, Debug, Default, Copy, Clone)]
|
#[derive(Arbitrary, Debug, Default, Copy, Clone)]
|
||||||
@@ -42,7 +42,7 @@ fuzz_target!(|module: WasmSmithModule| {
|
|||||||
let mut compiler = LLVM::default();
|
let mut compiler = LLVM::default();
|
||||||
compiler.canonicalize_nans(true);
|
compiler.canonicalize_nans(true);
|
||||||
compiler.enable_verifier();
|
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();
|
let module = Module::new(&store, &wasm_bytes).unwrap();
|
||||||
match Instance::new(&module, &imports! {}) {
|
match Instance::new(&module, &imports! {}) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target};
|
use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target};
|
||||||
use wasm_smith::{Config, ConfiguredModule};
|
use wasm_smith::{Config, ConfiguredModule};
|
||||||
use wasmer::{imports, Instance, Module, Store};
|
use wasmer::{imports, Instance, Module, Store};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_singlepass::Singlepass;
|
use wasmer_compiler_singlepass::Singlepass;
|
||||||
|
|
||||||
#[derive(Arbitrary, Debug, Default, Copy, Clone)]
|
#[derive(Arbitrary, Debug, Default, Copy, Clone)]
|
||||||
@@ -40,7 +40,7 @@ fuzz_target!(|module: WasmSmithModule| {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let compiler = Singlepass::default();
|
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 = Module::new(&store, &wasm_bytes);
|
||||||
let module = match module {
|
let module = match module {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
|
|||||||
@@ -88,32 +88,22 @@ std = []
|
|||||||
core = ["hashbrown"]
|
core = ["hashbrown"]
|
||||||
|
|
||||||
# Features for `sys`.
|
# Features for `sys`.
|
||||||
sys = []
|
sys = [
|
||||||
sys-default = ["sys", "wat", "default-cranelift", "default-engine_compilation"]
|
"wasmer-compiler/translator",
|
||||||
|
"wasmer-compiler/compiler",
|
||||||
|
]
|
||||||
|
sys-default = ["sys", "wat", "cranelift"]
|
||||||
# - Compilers.
|
# - Compilers.
|
||||||
compiler = [
|
compiler = [
|
||||||
"sys",
|
"sys",
|
||||||
"wasmer-compiler/translator",
|
|
||||||
]
|
]
|
||||||
singlepass = ["compiler", "wasmer-compiler-singlepass"]
|
singlepass = ["compiler", "wasmer-compiler-singlepass"]
|
||||||
cranelift = ["compiler", "wasmer-compiler-cranelift"]
|
cranelift = ["compiler", "wasmer-compiler-cranelift"]
|
||||||
llvm = ["compiler", "wasmer-compiler-llvm"]
|
llvm = ["compiler", "wasmer-compiler-llvm"]
|
||||||
default-compiler = []
|
|
||||||
default-singlepass = ["default-compiler", "singlepass"]
|
|
||||||
default-cranelift = ["default-compiler", "cranelift"]
|
|
||||||
default-llvm = ["default-compiler", "llvm"]
|
|
||||||
# - Engines.
|
# - Engines.
|
||||||
engine = ["sys"]
|
engine = ["sys"]
|
||||||
engine_compilation = [
|
|
||||||
"engine", "wasmer-compiler/engine_compilation"
|
|
||||||
]
|
|
||||||
default-engine = []
|
|
||||||
default-engine_compilation = [
|
|
||||||
"default-engine",
|
|
||||||
"engine_compilation",
|
|
||||||
]
|
|
||||||
# - Deprecated features.
|
# - Deprecated features.
|
||||||
jit = ["engine_compilation"]
|
jit = ["engine"]
|
||||||
|
|
||||||
# Features for `js`.
|
# Features for `js`.
|
||||||
js = ["wasm-bindgen", "js-sys"]
|
js = ["wasm-bindgen", "js-sys"]
|
||||||
@@ -124,4 +114,4 @@ wasm-types-polyfill = ["js", "wasmparser"]
|
|||||||
js-serializable-module = []
|
js-serializable-module = []
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[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" ]
|
||||||
|
|||||||
@@ -307,8 +307,8 @@
|
|||||||
#![cfg_attr(not(feature = "wat"), doc = "(disabled),")]
|
#![cfg_attr(not(feature = "wat"), doc = "(disabled),")]
|
||||||
//! enables `wasmer` to parse the WebAssembly text format,
|
//! enables `wasmer` to parse the WebAssembly text format,
|
||||||
//! - `compilation`
|
//! - `compilation`
|
||||||
#![cfg_attr(feature = "compilation", doc = "(enabled),")]
|
#![cfg_attr(feature = "compiler", doc = "(enabled),")]
|
||||||
#![cfg_attr(not(feature = "compilation"), doc = "(disabled),")]
|
#![cfg_attr(not(feature = "compiler"), doc = "(disabled),")]
|
||||||
//! enables compilation with the wasmer engine.
|
//! enables compilation with the wasmer engine.
|
||||||
//!
|
//!
|
||||||
//! The features that set defaults come in sets that are mutually exclusive.
|
//! The features that set defaults come in sets that are mutually exclusive.
|
||||||
|
|||||||
@@ -64,26 +64,6 @@ pub mod vm {
|
|||||||
#[cfg(feature = "wat")]
|
#[cfg(feature = "wat")]
|
||||||
pub use wat::parse_bytes as wat2wasm;
|
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")]
|
#[cfg(feature = "singlepass")]
|
||||||
pub use wasmer_compiler_singlepass::Singlepass;
|
pub use wasmer_compiler_singlepass::Singlepass;
|
||||||
|
|
||||||
@@ -93,17 +73,13 @@ pub use wasmer_compiler_cranelift::{Cranelift, CraneliftOptLevel};
|
|||||||
#[cfg(feature = "llvm")]
|
#[cfg(feature = "llvm")]
|
||||||
pub use wasmer_compiler_llvm::{LLVMOptLevel, LLVM};
|
pub use wasmer_compiler_llvm::{LLVMOptLevel, LLVM};
|
||||||
|
|
||||||
#[cfg(feature = "engine_compilation")]
|
pub use wasmer_compiler::Engine;
|
||||||
pub use wasmer_compiler::{Artifact, Backend, Engine};
|
#[cfg(feature = "compiler")]
|
||||||
|
pub use wasmer_compiler::{Artifact, EngineBuilder};
|
||||||
|
|
||||||
/// Version number of this crate.
|
/// Version number of this crate.
|
||||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
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.
|
/// This type is deprecated, it has been replaced by TypedFunction.
|
||||||
#[deprecated(
|
#[deprecated(
|
||||||
since = "3.0.0",
|
since = "3.0.0",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use std::sync::{Arc, RwLock};
|
|||||||
#[cfg(feature = "compiler")]
|
#[cfg(feature = "compiler")]
|
||||||
use wasmer_compiler::CompilerConfig;
|
use wasmer_compiler::CompilerConfig;
|
||||||
#[cfg(feature = "compiler")]
|
#[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::{init_traps, TrapHandler, TrapHandlerFn};
|
||||||
|
|
||||||
use wasmer_vm::StoreObjects;
|
use wasmer_vm::StoreObjects;
|
||||||
@@ -39,7 +39,7 @@ impl Store {
|
|||||||
#[cfg(feature = "compiler")]
|
#[cfg(feature = "compiler")]
|
||||||
/// Creates a new `Store` with a specific [`CompilerConfig`].
|
/// Creates a new `Store` with a specific [`CompilerConfig`].
|
||||||
pub fn new(compiler_config: Box<dyn CompilerConfig>) -> Self {
|
pub fn new(compiler_config: Box<dyn CompilerConfig>) -> 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()))
|
Self::new_with_tunables(&engine, BaseTunables::for_target(engine.target()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,20 +120,21 @@ unsafe impl Send for Store {}
|
|||||||
unsafe impl Sync for Store {}
|
unsafe impl Sync for Store {}
|
||||||
|
|
||||||
// We only implement default if we have assigned a default compiler and engine
|
// 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 {
|
impl Default for Store {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
// We store them on a function that returns to make
|
// We store them on a function that returns to make
|
||||||
// sure this function doesn't emit a compile error even if
|
// sure this function doesn't emit a compile error even if
|
||||||
// more than one compiler is enabled.
|
// more than one compiler is enabled.
|
||||||
#[allow(unreachable_code)]
|
#[allow(unreachable_code)]
|
||||||
|
#[cfg(any(feature = "cranelift", feature = "llvm", feature = "singlepass"))]
|
||||||
fn get_config() -> impl CompilerConfig + 'static {
|
fn get_config() -> impl CompilerConfig + 'static {
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(feature = "default-cranelift")] {
|
if #[cfg(feature = "cranelift")] {
|
||||||
wasmer_compiler_cranelift::Cranelift::default()
|
wasmer_compiler_cranelift::Cranelift::default()
|
||||||
} else if #[cfg(feature = "default-llvm")] {
|
} else if #[cfg(feature = "llvm")] {
|
||||||
wasmer_compiler_llvm::LLVM::default()
|
wasmer_compiler_llvm::LLVM::default()
|
||||||
} else if #[cfg(feature = "default-singlepass")] {
|
} else if #[cfg(feature = "singlepass")] {
|
||||||
wasmer_compiler_singlepass::Singlepass::default()
|
wasmer_compiler_singlepass::Singlepass::default()
|
||||||
} else {
|
} else {
|
||||||
compile_error!("No default compiler chosen")
|
compile_error!("No default compiler chosen")
|
||||||
@@ -142,19 +143,28 @@ impl Default for Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unreachable_code, unused_mut)]
|
#[allow(unreachable_code, unused_mut)]
|
||||||
fn get_engine(mut config: impl CompilerConfig + 'static) -> Engine {
|
fn get_engine() -> Engine {
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(feature = "engine_compilation")] {
|
if #[cfg(feature = "compiler")] {
|
||||||
wasmer_compiler::Backend::new(config)
|
|
||||||
|
cfg_if::cfg_if! {
|
||||||
|
if #[cfg(any(feature = "cranelift", feature = "llvm", feature = "singlepass"))]
|
||||||
|
{
|
||||||
|
let config = get_config();
|
||||||
|
wasmer_compiler::EngineBuilder::new(Box::new(config) as Box<dyn CompilerConfig>, None, None)
|
||||||
.engine()
|
.engine()
|
||||||
|
} else {
|
||||||
|
wasmer_compiler::EngineBuilder::headless()
|
||||||
|
.engine()
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
compile_error!("No default engine chosen")
|
compile_error!("No default engine chosen")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = get_config();
|
let engine = get_engine();
|
||||||
let engine = get_engine(config);
|
|
||||||
let tunables = BaseTunables::for_target(engine.target());
|
let tunables = BaseTunables::for_target(engine.target());
|
||||||
Self::new_with_tunables(&engine, tunables)
|
Self::new_with_tunables(&engine, tunables)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ inline-c = "0.1.5"
|
|||||||
default = [
|
default = [
|
||||||
"wat",
|
"wat",
|
||||||
"cranelift",
|
"cranelift",
|
||||||
"compilation",
|
"compiler",
|
||||||
"wasi",
|
"wasi",
|
||||||
"middlewares",
|
"middlewares",
|
||||||
]
|
]
|
||||||
@@ -58,12 +58,15 @@ middlewares = [
|
|||||||
"compiler",
|
"compiler",
|
||||||
"wasmer-middlewares",
|
"wasmer-middlewares",
|
||||||
]
|
]
|
||||||
compilation = [
|
|
||||||
"wasmer-compiler/engine_compilation",
|
|
||||||
"compiler",
|
|
||||||
]
|
|
||||||
compiler = [
|
compiler = [
|
||||||
"wasmer-api/compiler",
|
"wasmer-api/compiler",
|
||||||
|
"wasmer-compiler/translator",
|
||||||
|
"wasmer-compiler/compiler",
|
||||||
|
]
|
||||||
|
compiler-headless = [
|
||||||
|
"wasmer-api/compiler",
|
||||||
|
"wasmer-compiler/translator",
|
||||||
|
"wasmer-compiler/compiler",
|
||||||
]
|
]
|
||||||
singlepass = [
|
singlepass = [
|
||||||
"wasmer-compiler-singlepass",
|
"wasmer-compiler-singlepass",
|
||||||
@@ -79,7 +82,7 @@ llvm = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
# Deprecated features.
|
# Deprecated features.
|
||||||
jit = ["compilation"]
|
jit = ["compiler"]
|
||||||
|
|
||||||
# TODO: Port this feature.
|
# TODO: Port this feature.
|
||||||
#emscripten = ["wasmer-emscripten"]
|
#emscripten = ["wasmer-emscripten"]
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ fn build_wasm_c_api_headers(crate_dir: &str, out_dir: &str) {
|
|||||||
pre_header = PRE_HEADER
|
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!("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!("wasi", WASI_FEATURE_AS_C_DEFINE, pre_header);
|
||||||
map_feature_as_c_define!("middlewares", MIDDLEWARES_FEATURE_AS_C_DEFINE, pre_header);
|
map_feature_as_c_define!("middlewares", MIDDLEWARES_FEATURE_AS_C_DEFINE, pre_header);
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#[cfg(feature = "compiler")]
|
#[cfg(feature = "compiler")]
|
||||||
pub use super::unstable::engine::wasmer_is_compiler_available;
|
pub use super::unstable::engine::wasmer_is_compiler_available;
|
||||||
pub use super::unstable::engine::{
|
pub use super::unstable::engine::{wasm_config_set_features, wasm_config_set_target};
|
||||||
wasm_config_set_features, wasm_config_set_target, wasmer_is_engine_available,
|
|
||||||
};
|
|
||||||
use super::unstable::features::wasmer_features_t;
|
use super::unstable::features::wasmer_features_t;
|
||||||
#[cfg(feature = "middlewares")]
|
#[cfg(feature = "middlewares")]
|
||||||
pub use super::unstable::middlewares::wasm_config_push_middleware;
|
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 super::unstable::target_lexicon::wasmer_target_t;
|
||||||
use crate::error::update_last_error;
|
use crate::error::update_last_error;
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
#[cfg(feature = "compilation")]
|
use wasmer_compiler::{Engine, EngineBuilder};
|
||||||
use wasmer_compiler::{Backend, Engine};
|
|
||||||
|
|
||||||
/// Kind of compilers that can be used by the engines.
|
/// 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 {
|
impl Default for wasmer_engine_t {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
cfg_if! {
|
|
||||||
if #[cfg(feature = "compilation")] {
|
|
||||||
Self::UNIVERSAL
|
Self::UNIVERSAL
|
||||||
} else {
|
|
||||||
compile_error!("Please enable one of the engines")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,12 +220,6 @@ pub extern "C" fn wasm_config_set_compiler(
|
|||||||
/// // Create the configuration.
|
/// // Create the configuration.
|
||||||
/// wasm_config_t* config = wasm_config_new();
|
/// 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.
|
/// // Create the engine.
|
||||||
/// wasm_engine_t* engine = wasm_engine_new_with_config(config);
|
/// wasm_engine_t* engine = wasm_engine_new_with_config(config);
|
||||||
///
|
///
|
||||||
@@ -267,7 +252,7 @@ pub struct wasm_engine_t {
|
|||||||
#[cfg(feature = "compiler")]
|
#[cfg(feature = "compiler")]
|
||||||
use wasmer_api::CompilerConfig;
|
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<dyn CompilerConfig> {
|
fn get_default_compiler_config() -> Box<dyn CompilerConfig> {
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(feature = "cranelift")] {
|
if #[cfg(feature = "cranelift")] {
|
||||||
@@ -283,7 +268,7 @@ fn get_default_compiler_config() -> Box<dyn CompilerConfig> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(all(feature = "compilation", feature = "compiler"))] {
|
if #[cfg(feature = "compiler")] {
|
||||||
/// Creates a new Universal engine with the default compiler.
|
/// Creates a new Universal engine with the default compiler.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@@ -294,10 +279,10 @@ cfg_if! {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
||||||
let compiler_config: Box<dyn CompilerConfig> = get_default_compiler_config();
|
let compiler_config: Box<dyn CompilerConfig> = 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 })
|
Box::new(wasm_engine_t { inner: engine })
|
||||||
}
|
}
|
||||||
} else if #[cfg(feature = "compilation")] {
|
} else if #[cfg(feature = "compiler-headless")] {
|
||||||
/// Creates a new headless Universal engine.
|
/// Creates a new headless Universal engine.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@@ -307,7 +292,7 @@ cfg_if! {
|
|||||||
/// cbindgen:ignore
|
/// cbindgen:ignore
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
||||||
let engine: Engine = Backend::headless().engine();
|
let engine: Engine = EngineBuilder::headless().engine();
|
||||||
Box::new(wasm_engine_t { inner: engine })
|
Box::new(wasm_engine_t { inner: engine })
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -320,7 +305,7 @@ cfg_if! {
|
|||||||
/// cbindgen:ignore
|
/// cbindgen:ignore
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
||||||
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?;
|
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! {
|
cfg_if! {
|
||||||
if #[cfg(feature = "compiler")] {
|
if #[cfg(feature = "compiler")] {
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
@@ -417,19 +403,16 @@ pub extern "C" fn wasm_engine_new_with_config(
|
|||||||
compiler_config.canonicalize_nans(true);
|
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 inner: Engine =
|
||||||
{
|
{
|
||||||
let mut builder = Backend::new(compiler_config);
|
let mut builder = EngineBuilder::new(compiler_config, None, None);
|
||||||
|
|
||||||
if let Some(target) = config.target {
|
if let Some(target) = config.target {
|
||||||
builder = builder.target(target.inner);
|
builder.set_target(Some(target.inner));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(features) = config.features {
|
if let Some(features) = config.features {
|
||||||
builder = builder.features(features.inner);
|
builder.set_features(Some(features.inner));
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.engine()
|
builder.engine()
|
||||||
@@ -437,22 +420,18 @@ pub extern "C" fn wasm_engine_new_with_config(
|
|||||||
Some(Box::new(wasm_engine_t { inner }))
|
Some(Box::new(wasm_engine_t { inner }))
|
||||||
} else {
|
} else {
|
||||||
let inner: Engine =
|
let inner: Engine =
|
||||||
cfg_if! {
|
{
|
||||||
if #[cfg(feature = "compilation")] {
|
let mut builder = EngineBuilder::headless();
|
||||||
let mut builder = Backend::headless();
|
|
||||||
|
|
||||||
if let Some(target) = config.target {
|
if let Some(target) = config.target {
|
||||||
builder = builder.target(target.inner);
|
builder.set_target(Some(target.inner));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(features) = config.features {
|
if let Some(features) = config.features {
|
||||||
builder = builder.features(features.inner);
|
builder.set_features(Some(features.inner));
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.engine()
|
builder.engine()
|
||||||
} else {
|
|
||||||
return return_with_error("Wasmer has not been compiled with the `compilation` feature.");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
Some(Box::new(wasm_engine_t { inner }))
|
Some(Box::new(wasm_engine_t { inner }))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ mod macros;
|
|||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// To configure the engine, see the [`wasm_config_new`][engine::wasm_config_new].
|
/// 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;
|
pub mod engine;
|
||||||
|
|
||||||
/// cbindgen:ignore
|
/// cbindgen:ignore
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ pub extern "C" fn wasmer_is_headless() -> bool {
|
|||||||
/// compiled library.
|
/// compiled library.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasmer_is_engine_available(engine: wasmer_engine_t) -> bool {
|
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)]
|
#[cfg(test)]
|
||||||
@@ -234,11 +234,7 @@ mod tests {
|
|||||||
fn test_wasmer_is_engine_available() {
|
fn test_wasmer_is_engine_available() {
|
||||||
set_var(
|
set_var(
|
||||||
"UNIVERSAL",
|
"UNIVERSAL",
|
||||||
if cfg!(feature = "compilation") {
|
if cfg!(feature = "compiler") { "1" } else { "0" },
|
||||||
"1"
|
|
||||||
} else {
|
|
||||||
"0"
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
(assert_c! {
|
(assert_c! {
|
||||||
|
|||||||
10
lib/cache/benches/bench_filesystem_cache.rs
vendored
10
lib/cache/benches/bench_filesystem_cache.rs
vendored
@@ -6,7 +6,7 @@ use tempfile::TempDir;
|
|||||||
use wasmer::{Module, Store};
|
use wasmer::{Module, Store};
|
||||||
use wasmer_cache::Cache;
|
use wasmer_cache::Cache;
|
||||||
use wasmer_cache::{FileSystemCache, Hash};
|
use wasmer_cache::{FileSystemCache, Hash};
|
||||||
use wasmer_compiler::Backend;
|
use wasmer_compiler::EngineBuilder;
|
||||||
use wasmer_compiler_singlepass::Singlepass;
|
use wasmer_compiler_singlepass::Singlepass;
|
||||||
|
|
||||||
fn random_key() -> Hash {
|
fn random_key() -> Hash {
|
||||||
@@ -17,7 +17,7 @@ pub fn store_cache_universal(c: &mut Criterion) {
|
|||||||
let tmp_dir = TempDir::new().unwrap();
|
let tmp_dir = TempDir::new().unwrap();
|
||||||
let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap();
|
let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap();
|
||||||
let compiler = Singlepass::default();
|
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(
|
let module = Module::new(
|
||||||
&store,
|
&store,
|
||||||
std::fs::read("../../lib/c-api/examples/assets/qjs.wasm").unwrap(),
|
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 tmp_dir = TempDir::new().unwrap();
|
||||||
let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap();
|
let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap();
|
||||||
let compiler = Singlepass::default();
|
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(
|
let module = Module::new(
|
||||||
&store,
|
&store,
|
||||||
std::fs::read("../../lib/c-api/examples/assets/qjs.wasm").unwrap(),
|
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 tmp_dir = TempDir::new().unwrap();
|
||||||
let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap();
|
let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap();
|
||||||
let compiler = Singlepass::default();
|
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(
|
let module = Module::new(
|
||||||
&store,
|
&store,
|
||||||
std::fs::read("../../lib/c-api/examples/assets/qjs.wasm").unwrap(),
|
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 tmp_dir = TempDir::new().unwrap();
|
||||||
let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap();
|
let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap();
|
||||||
let compiler = Singlepass::default();
|
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(
|
let module = Module::new(
|
||||||
&store,
|
&store,
|
||||||
std::fs::read("../../lib/c-api/examples/assets/qjs.wasm").unwrap(),
|
std::fs::read("../../lib/c-api/examples/assets/qjs.wasm").unwrap(),
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ path = "src/bin/wasmer_compiler.rs"
|
|||||||
doc = false
|
doc = false
|
||||||
|
|
||||||
[dependencies]
|
[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" }
|
wasmer-types = { version = "=2.3.0", path = "../types" }
|
||||||
atty = "0.2"
|
atty = "0.2"
|
||||||
colored = "2.0"
|
colored = "2.0"
|
||||||
@@ -52,6 +52,7 @@ default = []
|
|||||||
engine = []
|
engine = []
|
||||||
compiler = [
|
compiler = [
|
||||||
"wasmer-compiler/translator",
|
"wasmer-compiler/translator",
|
||||||
|
"wasmer-compiler/compiler",
|
||||||
]
|
]
|
||||||
singlepass = [
|
singlepass = [
|
||||||
"wasmer-compiler-singlepass",
|
"wasmer-compiler-singlepass",
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ impl Compile {
|
|||||||
Target::new(target_triple.clone(), features)
|
Target::new(target_triple.clone(), features)
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.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
|
let output_filename = self
|
||||||
.output
|
.output
|
||||||
.file_stem()
|
.file_stem()
|
||||||
@@ -96,7 +97,7 @@ impl Compile {
|
|||||||
.map(|table_type| tunables.table_style(table_type))
|
.map(|table_type| tunables.table_style(table_type))
|
||||||
.collect();
|
.collect();
|
||||||
let artifact = ArtifactBuild::new(
|
let artifact = ArtifactBuild::new(
|
||||||
&mut engine,
|
&mut engine.inner_mut(),
|
||||||
&wasm_bytes,
|
&wasm_bytes,
|
||||||
&target,
|
&target,
|
||||||
memory_styles,
|
memory_styles,
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ impl Validate {
|
|||||||
Triple::from_str("x86_64-linux-gnu").unwrap(),
|
Triple::from_str("x86_64-linux-gnu").unwrap(),
|
||||||
CpuFeature::SSE2 | CpuFeature::AVX,
|
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)?;
|
let module_contents = std::fs::read(&self.path)?;
|
||||||
if !is_wasm(&module_contents) {
|
if !is_wasm(&module_contents) {
|
||||||
bail!("`wasmer validate` only validates WebAssembly files");
|
bail!("`wasmer validate` only validates WebAssembly files");
|
||||||
|
|||||||
@@ -174,7 +174,8 @@ impl CompilerOptions {
|
|||||||
compiler_config: Box<dyn CompilerConfig>,
|
compiler_config: Box<dyn CompilerConfig>,
|
||||||
) -> Result<EngineBuilder> {
|
) -> Result<EngineBuilder> {
|
||||||
let features = self.get_features(compiler_config.default_features_for_target(&target))?;
|
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)
|
Ok(engine)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ required-features = ["headless"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmer = { version = "=2.3.0", path = "../api", default-features = false }
|
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-cranelift = { version = "=2.3.0", path = "../compiler-cranelift", optional = true }
|
||||||
wasmer-compiler-singlepass = { version = "=2.3.0", path = "../compiler-singlepass", 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 }
|
wasmer-compiler-llvm = { version = "=2.3.0", path = "../compiler-llvm", optional = true }
|
||||||
@@ -64,7 +64,7 @@ default = [
|
|||||||
"cache",
|
"cache",
|
||||||
"wasi",
|
"wasi",
|
||||||
"emscripten",
|
"emscripten",
|
||||||
"compilation",
|
"compiler",
|
||||||
]
|
]
|
||||||
cache = ["wasmer-cache"]
|
cache = ["wasmer-cache"]
|
||||||
cache-blake3-pure = ["wasmer-cache/blake3-pure"]
|
cache-blake3-pure = ["wasmer-cache/blake3-pure"]
|
||||||
@@ -74,9 +74,7 @@ emscripten = ["wasmer-emscripten"]
|
|||||||
wat = ["wasmer/wat"]
|
wat = ["wasmer/wat"]
|
||||||
compiler = [
|
compiler = [
|
||||||
"wasmer-compiler/translator",
|
"wasmer-compiler/translator",
|
||||||
]
|
"wasmer-compiler/compiler",
|
||||||
compilation = [
|
|
||||||
"wasmer-compiler/engine_compilation",
|
|
||||||
]
|
]
|
||||||
experimental-io-devices = [
|
experimental-io-devices = [
|
||||||
"wasmer-wasi-experimental-io-devices",
|
"wasmer-wasi-experimental-io-devices",
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ impl Run {
|
|||||||
fn get_store_module(&self) -> Result<(Store, Module)> {
|
fn get_store_module(&self) -> Result<(Store, Module)> {
|
||||||
let contents = std::fs::read(self.path.clone())?;
|
let contents = std::fs::read(self.path.clone())?;
|
||||||
if wasmer_compiler::Artifact::is_deserializable(&contents) {
|
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 store = Store::new_with_engine(&engine);
|
||||||
let module = unsafe { Module::deserialize_from_file(&store, &self.path)? };
|
let module = unsafe { Module::deserialize_from_file(&store, &self.path)? };
|
||||||
return Ok((store, module));
|
return Ok((store, module));
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ use structopt::StructOpt;
|
|||||||
use wasmer::*;
|
use wasmer::*;
|
||||||
#[cfg(feature = "compiler")]
|
#[cfg(feature = "compiler")]
|
||||||
use wasmer_compiler::CompilerConfig;
|
use wasmer_compiler::CompilerConfig;
|
||||||
#[cfg(feature = "compilation")]
|
|
||||||
use wasmer_compiler::Engine;
|
use wasmer_compiler::Engine;
|
||||||
|
|
||||||
#[derive(Debug, Clone, StructOpt, Default)]
|
#[derive(Debug, Clone, StructOpt, Default)]
|
||||||
@@ -110,7 +109,7 @@ impl CompilerOptions {
|
|||||||
Ok((store, compiler_type))
|
Ok((store, compiler_type))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "compilation")]
|
#[cfg(feature = "compiler")]
|
||||||
fn get_engine(
|
fn get_engine(
|
||||||
&self,
|
&self,
|
||||||
target: Target,
|
target: Target,
|
||||||
@@ -118,9 +117,7 @@ impl CompilerOptions {
|
|||||||
) -> Result<Box<Engine>> {
|
) -> Result<Box<Engine>> {
|
||||||
let features = self.get_features(compiler_config.default_features_for_target(&target))?;
|
let features = self.get_features(compiler_config.default_features_for_target(&target))?;
|
||||||
let engine: Box<Engine> = Box::new(
|
let engine: Box<Engine> = Box::new(
|
||||||
wasmer_compiler::Backend::new(compiler_config)
|
wasmer_compiler::EngineBuilder::new(compiler_config, Some(target), Some(features))
|
||||||
.features(features)
|
|
||||||
.target(target)
|
|
||||||
.engine(),
|
.engine(),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -320,7 +317,7 @@ impl StoreOptions {
|
|||||||
Ok((store, compiler_type))
|
Ok((store, compiler_type))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "compilation")]
|
#[cfg(feature = "compiler")]
|
||||||
fn get_engine_with_compiler(
|
fn get_engine_with_compiler(
|
||||||
&self,
|
&self,
|
||||||
target: Target,
|
target: Target,
|
||||||
@@ -335,9 +332,8 @@ impl StoreOptions {
|
|||||||
// If we don't have a compiler, but we have an engine
|
// If we don't have a compiler, but we have an engine
|
||||||
#[cfg(not(feature = "compiler"))]
|
#[cfg(not(feature = "compiler"))]
|
||||||
impl StoreOptions {
|
impl StoreOptions {
|
||||||
#[cfg(feature = "compilation")]
|
|
||||||
fn get_engine_headless(&self) -> Result<Engine> {
|
fn get_engine_headless(&self) -> Result<Engine> {
|
||||||
let engine: Engine = wasmer_compiler::Backend::headless().engine();
|
let engine: Engine = wasmer_compiler::EngineBuilder::headless().engine();
|
||||||
Ok(engine)
|
Ok(engine)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ readme = "README.md"
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[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"] }
|
wasmer-types = { path = "../types", version = "=2.3.0", default-features = false, features = ["std"] }
|
||||||
cranelift-entity = { version = "0.82", default-features = false }
|
cranelift-entity = { version = "0.82", default-features = false }
|
||||||
cranelift-codegen = { version = "0.82", default-features = false, features = ["x86", "arm64"] }
|
cranelift-codegen = { version = "0.82", default-features = false, features = ["x86", "arm64"] }
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ This crate contains a compiler implementation based on Cranelift.
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use wasmer::{Store, Backend};
|
use wasmer::{Store, EngineBuilder};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
|
|
||||||
let compiler = Cranelift::new();
|
let compiler = Cranelift::new();
|
||||||
// Put it into an engine and add it to the store
|
// 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
|
*Note: you can find a [full working example using Cranelift compiler
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmer-compiler = { path = "../compiler", version = "=2.3.0", features = [
|
wasmer-compiler = { path = "../compiler", version = "=2.3.0", features = [
|
||||||
"translator",
|
"translator", "compiler"
|
||||||
] }
|
] }
|
||||||
wasmer-vm = { path = "../vm", version = "=2.3.0" }
|
wasmer-vm = { path = "../vm", version = "=2.3.0" }
|
||||||
wasmer-types = { path = "../types", version = "=2.3.0" }
|
wasmer-types = { path = "../types", version = "=2.3.0" }
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ This crate contains a compiler implementation based on [the LLVM Compiler Infras
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use wasmer::{Store, Backend};
|
use wasmer::{Store, EngineBuilder};
|
||||||
use wasmer_compiler_llvm::LLVM;
|
use wasmer_compiler_llvm::LLVM;
|
||||||
|
|
||||||
let compiler = LLVM::new();
|
let compiler = LLVM::new();
|
||||||
// Put it into an engine and add it to the store
|
// 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].*
|
*Note: you can find a [full working example using LLVM compiler here][example].*
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ readme = "README.md"
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[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"] }
|
wasmer-types = { path = "../types", version = "=2.3.0", default-features = false, features = ["std"] }
|
||||||
hashbrown = { version = "0.11", optional = true }
|
hashbrown = { version = "0.11", optional = true }
|
||||||
gimli = { version = "0.26", optional = true }
|
gimli = { version = "0.26", optional = true }
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ This crate contains a compiler implementation based on the Singlepass linear com
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use wasmer::{Store, Backend};
|
use wasmer::{Store, EngineBuilder};
|
||||||
use wasmer_compiler_singlepass::Singlepass;
|
use wasmer_compiler_singlepass::Singlepass;
|
||||||
|
|
||||||
let compiler = Singlepass::new();
|
let compiler = Singlepass::new();
|
||||||
// Put it into an engine and add it to the store
|
// 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
|
*Note: you can find a [full working example using Singlepass compiler
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ default = ["std", "enable-serde" ]
|
|||||||
# `CompilerConfig`, as well as the included wasmparser.
|
# `CompilerConfig`, as well as the included wasmparser.
|
||||||
# Disable this feature if you just want a headless engine.
|
# Disable this feature if you just want a headless engine.
|
||||||
translator = ["wasmparser"]
|
translator = ["wasmparser"]
|
||||||
engine_compilation = []
|
compiler = ["translator"]
|
||||||
std = ["wasmer-types/std"]
|
std = ["wasmer-types/std"]
|
||||||
core = ["hashbrown", "wasmer-types/core"]
|
core = ["hashbrown", "wasmer-types/core"]
|
||||||
enable-serde = ["serde", "serde_bytes", "wasmer-types/enable-serde"]
|
enable-serde = ["serde", "serde_bytes", "wasmer-types/enable-serde"]
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
//! Define `ArtifactBuild` to allow compiling and instantiating to be
|
//! Define `ArtifactBuild` to allow compiling and instantiating to be
|
||||||
//! done as separate steps.
|
//! done as separate steps.
|
||||||
|
|
||||||
#[cfg(feature = "engine_compilation")]
|
#[cfg(feature = "compiler")]
|
||||||
use super::trampoline::{libcall_trampoline_len, make_libcall_trampolines};
|
use super::trampoline::{libcall_trampoline_len, make_libcall_trampolines};
|
||||||
|
use crate::ArtifactCreate;
|
||||||
|
#[cfg(feature = "compiler")]
|
||||||
|
use crate::EngineInner;
|
||||||
use crate::Features;
|
use crate::Features;
|
||||||
use crate::MetadataHeader;
|
use crate::MetadataHeader;
|
||||||
use crate::{ArtifactCreate, EngineBuilder};
|
#[cfg(feature = "compiler")]
|
||||||
#[cfg(feature = "engine_compilation")]
|
|
||||||
use crate::{ModuleEnvironment, ModuleMiddlewareChain};
|
use crate::{ModuleEnvironment, ModuleMiddlewareChain};
|
||||||
use enumset::EnumSet;
|
use enumset::EnumSet;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use wasmer_types::entity::PrimaryMap;
|
use wasmer_types::entity::PrimaryMap;
|
||||||
#[cfg(feature = "engine_compilation")]
|
#[cfg(feature = "compiler")]
|
||||||
use wasmer_types::CompileModuleInfo;
|
use wasmer_types::CompileModuleInfo;
|
||||||
use wasmer_types::SerializeError;
|
use wasmer_types::SerializeError;
|
||||||
use wasmer_types::{
|
use wasmer_types::{
|
||||||
@@ -38,16 +40,16 @@ impl ArtifactBuild {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated.
|
/// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated.
|
||||||
#[cfg(feature = "engine_compilation")]
|
#[cfg(feature = "compiler")]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
inner_engine: &mut EngineBuilder,
|
inner_engine: &mut EngineInner,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
target: &Target,
|
target: &Target,
|
||||||
memory_styles: PrimaryMap<MemoryIndex, MemoryStyle>,
|
memory_styles: PrimaryMap<MemoryIndex, MemoryStyle>,
|
||||||
table_styles: PrimaryMap<TableIndex, TableStyle>,
|
table_styles: PrimaryMap<TableIndex, TableStyle>,
|
||||||
) -> Result<Self, CompileError> {
|
) -> Result<Self, CompileError> {
|
||||||
let environ = ModuleEnvironment::new();
|
let environ = ModuleEnvironment::new();
|
||||||
let features = inner_engine.features();
|
let features = inner_engine.features().clone();
|
||||||
|
|
||||||
let translation = environ.translate(data).map_err(CompileError::Wasm)?;
|
let translation = environ.translate(data).map_err(CompileError::Wasm)?;
|
||||||
|
|
||||||
@@ -60,7 +62,7 @@ impl ArtifactBuild {
|
|||||||
|
|
||||||
let compile_info = CompileModuleInfo {
|
let compile_info = CompileModuleInfo {
|
||||||
module,
|
module,
|
||||||
features: features.clone(),
|
features,
|
||||||
memory_styles,
|
memory_styles,
|
||||||
table_styles,
|
table_styles,
|
||||||
};
|
};
|
||||||
@@ -117,8 +119,15 @@ impl ArtifactBuild {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated.
|
/// 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: &EngineBuilder, _data: &[u8]) -> Result<Self, CompileError> {
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub fn new(
|
||||||
|
_inner_engine: &mut EngineInner,
|
||||||
|
_data: &[u8],
|
||||||
|
_target: &Target,
|
||||||
|
_memory_styles: PrimaryMap<MemoryIndex, MemoryStyle>,
|
||||||
|
_table_styles: PrimaryMap<TableIndex, TableStyle>,
|
||||||
|
) -> Result<Self, CompileError> {
|
||||||
Err(CompileError::Codegen(
|
Err(CompileError::Codegen(
|
||||||
"Compilation is not enabled in the engine".to_string(),
|
"Compilation is not enabled in the engine".to_string(),
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
//! Generic Artifact abstraction for Wasmer Engines.
|
//! Generic Artifact abstraction for Wasmer Engines.
|
||||||
|
|
||||||
mod artifact_builder;
|
mod artifact_builder;
|
||||||
mod engine_builder;
|
|
||||||
mod trampoline;
|
mod trampoline;
|
||||||
|
|
||||||
pub use self::artifact_builder::ArtifactBuild;
|
pub use self::artifact_builder::ArtifactBuild;
|
||||||
pub use self::engine_builder::EngineBuilder;
|
|
||||||
pub use self::trampoline::*;
|
pub use self::trampoline::*;
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
//! Define `Artifact`, based on `ArtifactBuild`
|
//! Define `Artifact`, based on `ArtifactBuild`
|
||||||
//! to allow compiling and instantiating to be done as separate steps.
|
//! 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::engine::link::link_module;
|
||||||
use crate::ArtifactBuild;
|
use crate::ArtifactBuild;
|
||||||
use crate::ArtifactCreate;
|
use crate::ArtifactCreate;
|
||||||
use crate::Features;
|
use crate::Features;
|
||||||
#[cfg(feature = "engine_compilation")]
|
#[cfg(feature = "compiler")]
|
||||||
use crate::ModuleEnvironment;
|
use crate::ModuleEnvironment;
|
||||||
use crate::{
|
use crate::{
|
||||||
register_frame_info, resolve_imports, FunctionExtent, GlobalFrameInfoRegistration,
|
register_frame_info, resolve_imports, FunctionExtent, GlobalFrameInfoRegistration,
|
||||||
InstantiationError, MetadataHeader, RuntimeError, Tunables,
|
InstantiationError, MetadataHeader, RuntimeError, Tunables,
|
||||||
};
|
};
|
||||||
|
use crate::{Engine, EngineInner};
|
||||||
use enumset::EnumSet;
|
use enumset::EnumSet;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
@@ -37,7 +37,7 @@ pub struct Artifact {
|
|||||||
|
|
||||||
impl Artifact {
|
impl Artifact {
|
||||||
/// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated.
|
/// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated.
|
||||||
#[cfg(feature = "engine_compilation")]
|
#[cfg(feature = "compiler")]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
engine: &Engine,
|
engine: &Engine,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
@@ -59,7 +59,7 @@ impl Artifact {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let artifact = ArtifactBuild::new(
|
let artifact = ArtifactBuild::new(
|
||||||
inner_engine.builder_mut(),
|
&mut inner_engine,
|
||||||
data,
|
data,
|
||||||
engine.target(),
|
engine.target(),
|
||||||
memory_styles,
|
memory_styles,
|
||||||
@@ -70,7 +70,7 @@ impl Artifact {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated.
|
/// 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<Self, CompileError> {
|
pub fn new(_engine: &Engine, _data: &[u8]) -> Result<Self, CompileError> {
|
||||||
Err(CompileError::Codegen(
|
Err(CompileError::Codegen(
|
||||||
"Compilation is not enabled in the engine".to_string(),
|
"Compilation is not enabled in the engine".to_string(),
|
||||||
|
|||||||
@@ -1,25 +1,27 @@
|
|||||||
use super::Engine;
|
use super::Engine;
|
||||||
use crate::{CompilerConfig, Features};
|
use crate::CompilerConfig;
|
||||||
use wasmer_types::Target;
|
use wasmer_types::{Features, Target};
|
||||||
|
|
||||||
/// The Backend builder
|
/// The Builder contents of `Engine`
|
||||||
pub struct Backend {
|
pub struct EngineBuilder {
|
||||||
#[allow(dead_code)]
|
/// The compiler
|
||||||
compiler_config: Option<Box<dyn CompilerConfig>>,
|
compiler_config: Option<Box<dyn CompilerConfig>>,
|
||||||
|
/// The machine target
|
||||||
target: Option<Target>,
|
target: Option<Target>,
|
||||||
|
/// The features to compile the Wasm module with
|
||||||
features: Option<Features>,
|
features: Option<Features>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Backend {
|
impl EngineBuilder {
|
||||||
/// Create a new Backend
|
/// Create a new builder with pre-made components
|
||||||
pub fn new<T>(compiler_config: T) -> Self
|
pub fn new<T>(compiler_config: T, target: Option<Target>, features: Option<Features>) -> Self
|
||||||
where
|
where
|
||||||
T: Into<Box<dyn CompilerConfig>>,
|
T: Into<Box<dyn CompilerConfig>>,
|
||||||
{
|
{
|
||||||
Self {
|
Self {
|
||||||
compiler_config: Some(compiler_config.into()),
|
compiler_config: Some(compiler_config.into()),
|
||||||
target: None,
|
target,
|
||||||
features: None,
|
features,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,35 +35,39 @@ impl Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set the target
|
/// Set the target
|
||||||
pub fn target(mut self, target: Target) -> Self {
|
pub fn set_target(&mut self, target: Option<Target>) -> &mut Self {
|
||||||
self.target = Some(target);
|
self.target = target;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the features
|
/// Set the features
|
||||||
pub fn features(mut self, features: Features) -> Self {
|
pub fn set_features(&mut self, features: Option<Features>) -> &mut Self {
|
||||||
self.features = Some(features);
|
self.features = features;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build the `Engine` for this configuration
|
/// Build the `Engine` for this configuration
|
||||||
#[cfg(feature = "engine_compilation")]
|
#[cfg(feature = "compiler")]
|
||||||
pub fn engine(self) -> Engine {
|
pub fn engine(self) -> Engine {
|
||||||
let target = self.target.unwrap_or_default();
|
let target = self.target.unwrap_or_default();
|
||||||
if let Some(compiler_config) = self.compiler_config {
|
if let Some(compiler_config) = self.compiler_config {
|
||||||
let features = self
|
let features = self
|
||||||
.features
|
.features
|
||||||
.unwrap_or_else(|| compiler_config.default_features_for_target(&target));
|
.unwrap_or_else(|| compiler_config.default_features_for_target(&target));
|
||||||
let compiler = compiler_config.compiler();
|
Engine::new(compiler_config, target, features)
|
||||||
Engine::new(compiler, target, features)
|
|
||||||
} else {
|
} else {
|
||||||
Engine::headless()
|
Engine::headless()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build the `Engine` for this configuration
|
/// Build the `Engine` for this configuration
|
||||||
#[cfg(not(feature = "engine_compilation"))]
|
#[cfg(not(feature = "compiler"))]
|
||||||
pub fn engine(self) -> Engine {
|
pub fn engine(self) -> Engine {
|
||||||
Engine::headless()
|
Engine::headless()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The Wasm features
|
||||||
|
pub fn features(&self) -> Option<&Features> {
|
||||||
|
self.features.as_ref()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
//! The WebAssembly possible errors
|
//! The WebAssembly possible errors
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use crate::engine::trap::RuntimeError;
|
use crate::engine::trap::RuntimeError;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
pub use wasmer_types::{DeserializeError, ImportError, SerializeError};
|
pub use wasmer_types::{DeserializeError, ImportError, SerializeError};
|
||||||
@@ -16,6 +17,7 @@ pub enum LinkError {
|
|||||||
#[error("Error while importing {0:?}.{1:?}: {2}")]
|
#[error("Error while importing {0:?}.{1:?}: {2}")]
|
||||||
Import(String, String, ImportError),
|
Import(String, String, ImportError),
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
/// A trap ocurred during linking.
|
/// A trap ocurred during linking.
|
||||||
#[error("RuntimeError occurred during linking: {0}")]
|
#[error("RuntimeError occurred during linking: {0}")]
|
||||||
Trap(#[source] RuntimeError),
|
Trap(#[source] RuntimeError),
|
||||||
@@ -44,6 +46,7 @@ pub enum InstantiationError {
|
|||||||
CpuFeature(String),
|
CpuFeature(String),
|
||||||
|
|
||||||
/// A runtime error occured while invoking the start function
|
/// A runtime error occured while invoking the start function
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Start(RuntimeError),
|
Start(RuntimeError),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,28 @@
|
|||||||
//! Universal compilation.
|
//! Universal compilation.
|
||||||
|
|
||||||
#[cfg(feature = "engine_compilation")]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use crate::Compiler;
|
use crate::Artifact;
|
||||||
use crate::EngineBuilder;
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use crate::{Artifact, CodeMemory};
|
use crate::CodeMemory;
|
||||||
|
#[cfg(feature = "compiler")]
|
||||||
|
use crate::{Compiler, CompilerConfig};
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use crate::{FunctionExtent, Tunables};
|
use crate::{FunctionExtent, Tunables};
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use memmap2::Mmap;
|
use memmap2::Mmap;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
|
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use wasmer_types::entity::PrimaryMap;
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use wasmer_types::FunctionBody;
|
|
||||||
use wasmer_types::{
|
use wasmer_types::{
|
||||||
CompileError, DeserializeError, Features, FunctionIndex, FunctionType, LocalFunctionIndex,
|
entity::PrimaryMap, DeserializeError, FunctionBody, FunctionIndex, FunctionType,
|
||||||
ModuleInfo, SignatureIndex, Target,
|
LocalFunctionIndex, ModuleInfo, SignatureIndex,
|
||||||
};
|
};
|
||||||
|
use wasmer_types::{CompileError, Features, Target};
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use wasmer_types::{CustomSection, CustomSectionProtection, SectionIndex};
|
use wasmer_types::{CustomSection, CustomSectionProtection, SectionIndex};
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use wasmer_vm::{
|
use wasmer_vm::{
|
||||||
FunctionBodyPtr, SectionBodyPtr, SignatureRegistry, VMFunctionBody, VMSharedSignatureIndex,
|
FunctionBodyPtr, SectionBodyPtr, SignatureRegistry, VMFunctionBody, VMSharedSignatureIndex,
|
||||||
VMTrampoline,
|
VMTrampoline,
|
||||||
@@ -32,12 +39,19 @@ pub struct Engine {
|
|||||||
|
|
||||||
impl Engine {
|
impl Engine {
|
||||||
/// Create a new `Engine` with the given config
|
/// Create a new `Engine` with the given config
|
||||||
#[cfg(feature = "engine_compilation")]
|
#[cfg(feature = "compiler")]
|
||||||
pub fn new(compiler: Box<dyn Compiler>, target: Target, features: Features) -> Self {
|
pub fn new(
|
||||||
|
compiler_config: Box<dyn CompilerConfig>,
|
||||||
|
target: Target,
|
||||||
|
features: Features,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: Arc::new(Mutex::new(EngineInner {
|
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![],
|
code_memory: vec![],
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
signatures: SignatureRegistry::new(),
|
signatures: SignatureRegistry::new(),
|
||||||
})),
|
})),
|
||||||
target: Arc::new(target),
|
target: Arc::new(target),
|
||||||
@@ -61,8 +75,11 @@ impl Engine {
|
|||||||
pub fn headless() -> Self {
|
pub fn headless() -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: Arc::new(Mutex::new(EngineInner {
|
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![],
|
code_memory: vec![],
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
signatures: SignatureRegistry::new(),
|
signatures: SignatureRegistry::new(),
|
||||||
})),
|
})),
|
||||||
target: Arc::new(Target::default()),
|
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()
|
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()
|
self.inner.lock().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,12 +103,14 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Register a signature
|
/// Register a signature
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex {
|
pub fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex {
|
||||||
let compiler = self.inner();
|
let compiler = self.inner();
|
||||||
compiler.signatures().register(func_type)
|
compiler.signatures().register(func_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Lookup a signature
|
/// Lookup a signature
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option<FunctionType> {
|
pub fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option<FunctionType> {
|
||||||
let compiler = self.inner();
|
let compiler = self.inner();
|
||||||
compiler.signatures().lookup(sig)
|
compiler.signatures().lookup(sig)
|
||||||
@@ -101,7 +122,8 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Compile a WebAssembly binary
|
/// Compile a WebAssembly binary
|
||||||
#[cfg(feature = "engine_compilation")]
|
#[cfg(feature = "compiler")]
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub fn compile(
|
pub fn compile(
|
||||||
&self,
|
&self,
|
||||||
binary: &[u8],
|
binary: &[u8],
|
||||||
@@ -111,7 +133,8 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Compile a WebAssembly binary
|
/// Compile a WebAssembly binary
|
||||||
#[cfg(not(feature = "engine_compilation"))]
|
#[cfg(not(feature = "compiler"))]
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub fn compile(
|
pub fn compile(
|
||||||
&self,
|
&self,
|
||||||
_binary: &[u8],
|
_binary: &[u8],
|
||||||
@@ -122,6 +145,7 @@ impl Engine {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
/// Deserializes a WebAssembly module
|
/// Deserializes a WebAssembly module
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
@@ -131,6 +155,7 @@ impl Engine {
|
|||||||
Ok(Arc::new(Artifact::deserialize(self, bytes)?))
|
Ok(Arc::new(Artifact::deserialize(self, bytes)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
/// Deserializes a WebAssembly module from a path
|
/// Deserializes a WebAssembly module from a path
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
@@ -162,38 +187,47 @@ impl Engine {
|
|||||||
|
|
||||||
/// The inner contents of `Engine`
|
/// The inner contents of `Engine`
|
||||||
pub struct EngineInner {
|
pub struct EngineInner {
|
||||||
/// The builder (include compiler and cpu features)
|
#[cfg(feature = "compiler")]
|
||||||
builder: EngineBuilder,
|
/// The compiler and cpu features
|
||||||
|
compiler: Option<Box<dyn Compiler>>,
|
||||||
|
#[cfg(feature = "compiler")]
|
||||||
|
/// The compiler and cpu features
|
||||||
|
features: Features,
|
||||||
/// The code memory is responsible of publishing the compiled
|
/// The code memory is responsible of publishing the compiled
|
||||||
/// functions to memory.
|
/// functions to memory.
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
code_memory: Vec<CodeMemory>,
|
code_memory: Vec<CodeMemory>,
|
||||||
/// The signature registry is used mainly to operate with trampolines
|
/// The signature registry is used mainly to operate with trampolines
|
||||||
/// performantly.
|
/// performantly.
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
signatures: SignatureRegistry,
|
signatures: SignatureRegistry,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EngineInner {
|
impl EngineInner {
|
||||||
/// Gets the compiler associated to this engine.
|
/// Gets the compiler associated to this engine.
|
||||||
#[cfg(feature = "engine_compilation")]
|
#[cfg(feature = "compiler")]
|
||||||
pub fn compiler(&self) -> Result<&dyn Compiler, CompileError> {
|
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
|
/// Validate the module
|
||||||
pub fn validate(&self, data: &[u8]) -> Result<(), CompileError> {
|
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
|
/// The Wasm features
|
||||||
pub fn features(&self) -> &Features {
|
pub fn features(&self) -> &Features {
|
||||||
self.builder.features()
|
&self.features
|
||||||
}
|
|
||||||
|
|
||||||
pub fn builder_mut(&mut self) -> &mut EngineBuilder {
|
|
||||||
&mut self.builder
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allocate compiled functions into memory
|
/// Allocate compiled functions into memory
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
pub(crate) fn allocate(
|
pub(crate) fn allocate(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -286,11 +320,13 @@ impl EngineInner {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
/// Make memory containing compiled code executable.
|
/// Make memory containing compiled code executable.
|
||||||
pub(crate) fn publish_compiled_code(&mut self) {
|
pub(crate) fn publish_compiled_code(&mut self) {
|
||||||
self.code_memory.last_mut().unwrap().publish();
|
self.code_memory.last_mut().unwrap().publish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
/// Register DWARF-type exception handling information associated with the code.
|
/// Register DWARF-type exception handling information associated with the code.
|
||||||
pub(crate) fn publish_eh_frame(&mut self, eh_frame: Option<&[u8]>) -> Result<(), CompileError> {
|
pub(crate) fn publish_eh_frame(&mut self, eh_frame: Option<&[u8]>) -> Result<(), CompileError> {
|
||||||
self.code_memory
|
self.code_memory
|
||||||
@@ -305,6 +341,7 @@ impl EngineInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Shared signature registry.
|
/// Shared signature registry.
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub fn signatures(&self) -> &SignatureRegistry {
|
pub fn signatures(&self) -> &SignatureRegistry {
|
||||||
&self.signatures
|
&self.signatures
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,48 @@
|
|||||||
//! The Wasmer Engine.
|
//! The Wasmer Engine.
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
mod resolver;
|
mod resolver;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
mod trap;
|
mod trap;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
mod tunables;
|
mod tunables;
|
||||||
|
|
||||||
#[cfg(feature = "translator")]
|
#[cfg(feature = "translator")]
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
mod artifact;
|
mod artifact;
|
||||||
#[cfg(feature = "translator")]
|
#[cfg(feature = "translator")]
|
||||||
mod backend;
|
mod builder;
|
||||||
#[cfg(feature = "translator")]
|
#[cfg(feature = "translator")]
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
mod code_memory;
|
mod code_memory;
|
||||||
#[cfg(feature = "translator")]
|
#[cfg(feature = "translator")]
|
||||||
mod inner;
|
mod inner;
|
||||||
#[cfg(feature = "translator")]
|
#[cfg(feature = "translator")]
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
mod link;
|
mod link;
|
||||||
#[cfg(feature = "translator")]
|
#[cfg(feature = "translator")]
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
mod unwind;
|
mod unwind;
|
||||||
|
|
||||||
pub use self::error::{InstantiationError, LinkError};
|
pub use self::error::{InstantiationError, LinkError};
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub use self::resolver::resolve_imports;
|
pub use self::resolver::resolve_imports;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub use self::trap::*;
|
pub use self::trap::*;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub use self::tunables::Tunables;
|
pub use self::tunables::Tunables;
|
||||||
|
|
||||||
#[cfg(feature = "translator")]
|
#[cfg(feature = "translator")]
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub use self::artifact::Artifact;
|
pub use self::artifact::Artifact;
|
||||||
#[cfg(feature = "translator")]
|
#[cfg(feature = "translator")]
|
||||||
pub use self::backend::Backend;
|
pub use self::builder::EngineBuilder;
|
||||||
#[cfg(feature = "translator")]
|
#[cfg(feature = "translator")]
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub use self::code_memory::CodeMemory;
|
pub use self::code_memory::CodeMemory;
|
||||||
#[cfg(feature = "translator")]
|
#[cfg(feature = "translator")]
|
||||||
pub use self::inner::Engine;
|
pub use self::inner::{Engine, EngineInner};
|
||||||
#[cfg(feature = "translator")]
|
#[cfg(feature = "translator")]
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub use self::link::link_module;
|
pub use self::link::link_module;
|
||||||
|
|||||||
@@ -51,11 +51,9 @@ mod lib {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
mod engine;
|
mod engine;
|
||||||
mod traits;
|
mod traits;
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use crate::engine::*;
|
pub use crate::engine::*;
|
||||||
pub use crate::traits::*;
|
pub use crate::traits::*;
|
||||||
|
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ mod tests {
|
|||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasmer::{
|
use wasmer::{
|
||||||
imports, wat2wasm, Backend, CompilerConfig, Cranelift, Module, Store, TypedFunction,
|
imports, wat2wasm, CompilerConfig, Cranelift, EngineBuilder, Module, Store, TypedFunction,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn cost_function(operator: &Operator) -> u64 {
|
fn cost_function(operator: &Operator) -> u64 {
|
||||||
@@ -386,7 +386,8 @@ mod tests {
|
|||||||
let metering = Arc::new(Metering::new(10, cost_function));
|
let metering = Arc::new(Metering::new(10, cost_function));
|
||||||
let mut compiler_config = Cranelift::default();
|
let mut compiler_config = Cranelift::default();
|
||||||
compiler_config.push_middleware(metering);
|
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();
|
let module = Module::new(&store, bytecode()).unwrap();
|
||||||
|
|
||||||
// Instantiate
|
// Instantiate
|
||||||
@@ -434,7 +435,8 @@ mod tests {
|
|||||||
let metering = Arc::new(Metering::new(10, cost_function));
|
let metering = Arc::new(Metering::new(10, cost_function));
|
||||||
let mut compiler_config = Cranelift::default();
|
let mut compiler_config = Cranelift::default();
|
||||||
compiler_config.push_middleware(metering);
|
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();
|
let module = Module::new(&store, bytecode()).unwrap();
|
||||||
|
|
||||||
// Instantiate
|
// Instantiate
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ tracing-wasm = "0.2"
|
|||||||
default = ["sys-default"]
|
default = ["sys-default"]
|
||||||
|
|
||||||
sys = ["wasmer/sys"]
|
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 = []
|
sys-poll = []
|
||||||
|
|
||||||
js = ["wasmer/js", "mem-fs", "wasmer-vfs/no-time", "getrandom/js", "chrono"]
|
js = ["wasmer/js", "mem-fs", "wasmer-vfs/no-time", "getrandom/js", "chrono"]
|
||||||
|
|||||||
@@ -51,15 +51,15 @@ impl Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn engine(&self, compiler_config: Box<dyn CompilerConfig>) -> Box<Engine> {
|
pub fn engine(&self, compiler_config: Box<dyn CompilerConfig>) -> Box<Engine> {
|
||||||
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 {
|
if let Some(ref features) = self.features {
|
||||||
engine = engine.features(features.clone())
|
engine.set_features(Some(features.clone()));
|
||||||
}
|
}
|
||||||
Box::new(engine.engine())
|
Box::new(engine.engine())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn engine_headless(&self) -> Box<Engine> {
|
pub fn engine_headless(&self) -> Box<Engine> {
|
||||||
Box::new(wasmer_compiler::Backend::headless().engine())
|
Box::new(wasmer_compiler::EngineBuilder::headless().engine())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compiler_config(
|
pub fn compiler_config(
|
||||||
|
|||||||
Reference in New Issue
Block a user