Skip to content

Commit

Permalink
Merge pull request #1874 from wasmerio/compilerconfig-owned
Browse files Browse the repository at this point in the history
Set compiler config to be owned (following wasm-c-api)
  • Loading branch information
syrusakbary authored Dec 4, 2020
2 parents d3f73a6 + 2e16b00 commit 54bce39
Show file tree
Hide file tree
Showing 53 changed files with 230 additions and 150 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

* [#1867](https://github.com/wasmerio/wasmer/pull/1867) Added `Metering::get_remaining_points` and `Metering::set_remaining_points`

### Changed

- [#1874](https://github.com/wasmerio/wasmer/pull/1874) Set `CompilerConfig` to be owned (following wasm-c-api)

## 1.0.0-beta1 - 2020-12-01

### Added
Expand Down
12 changes: 6 additions & 6 deletions benches/static_and_dynamic_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,39 +150,39 @@ pub fn run_basic_dynamic_function(store: &Store, compiler_name: &str, c: &mut Cr
fn run_static_benchmarks(c: &mut Criterion) {
#[cfg(feature = "llvm")]
{
let store = Store::new(&JIT::new(&wasmer_compiler_llvm::LLVM::new()).engine());
let store = Store::new(&JIT::new(wasmer_compiler_llvm::LLVM::new()).engine());
run_basic_static_function(&store, "llvm", c);
}

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

#[cfg(feature = "singlepass")]
{
let store = Store::new(&JIT::new(&wasmer_compiler_singlepass::Singlepass::new()).engine());
let store = Store::new(&JIT::new(wasmer_compiler_singlepass::Singlepass::new()).engine());
run_basic_static_function(&store, "singlepass", c);
}
}

fn run_dynamic_benchmarks(c: &mut Criterion) {
#[cfg(feature = "llvm")]
{
let store = Store::new(&JIT::new(&wasmer_compiler_llvm::LLVM::new()).engine());
let store = Store::new(&JIT::new(wasmer_compiler_llvm::LLVM::new()).engine());
run_basic_dynamic_function(&store, "llvm", c);
}

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

#[cfg(feature = "singlepass")]
{
let store = Store::new(&JIT::new(&wasmer_compiler_singlepass::Singlepass::new()).engine());
let store = Store::new(&JIT::new(wasmer_compiler_singlepass::Singlepass::new()).engine());
run_basic_dynamic_function(&store, "singlepass", c);
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/migration_to_1.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ control:

```diff
- let module = compile(&wasm_bytes[..])?;
+ let engine = JIT::new(&Cranelift::default()).engine();
+ let engine = JIT::new(Cranelift::default()).engine();
+ let store = Store::new(&engine);
+ let module = Module::new(&store, wasm_bytes)?;
- let instance = module.instantiate(&imports)?;
Expand Down
2 changes: 1 addition & 1 deletion examples/compiler_cranelift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let compiler = Cranelift::default();

// Create the store
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());

println!("Compiling module...");
// Let's compile the Wasm module.
Expand Down
2 changes: 1 addition & 1 deletion examples/compiler_llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let compiler = LLVM::default();

// Create the store
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());

println!("Compiling module...");
// Let's compile the Wasm module.
Expand Down
2 changes: 1 addition & 1 deletion examples/compiler_singlepass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let compiler = Singlepass::default();

// Create the store
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());

println!("Compiling module...");
// Let's compile the Wasm module.
Expand Down
2 changes: 1 addition & 1 deletion examples/early_exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn main() -> anyhow::Result<()> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());

println!("Compiling module...");
// Let's compile the Wasm module.
Expand Down
4 changes: 2 additions & 2 deletions examples/engine_cross_compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// In this situation, the compiler is
// `wasmer_compiler_cranelift`. The compiler is responsible to
// compile the Wasm module into executable code.
let mut compiler_config = Cranelift::default();
let compiler_config = Cranelift::default();

// Here we go.
//
Expand Down Expand Up @@ -72,7 +72,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
//
// That's where we specify the target for the compiler.
// Use the native engine.
let engine = Native::new(&mut compiler_config)
let engine = Native::new(compiler_config)
// Here we go.
// Pass the target to the engine! The engine will share
// this information with the compiler.
Expand Down
2 changes: 1 addition & 1 deletion examples/engine_headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// are going to store it in a file with the `.so` extension
// for example (or `.dylib`, or `.dll` depending of the
// platform).
let engine = Native::new(&mut compiler_config).engine();
let engine = Native::new(compiler_config).engine();

// Create a store, that holds the engine.
let store = Store::new(&engine);
Expand Down
4 changes: 2 additions & 2 deletions examples/engine_jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// In this situation, the compiler is
// `wasmer_compiler_cranelift`. The compiler is responsible to
// compile the Wasm module into executable code.
let mut compiler_config = Cranelift::default();
let compiler_config = Cranelift::default();

println!("Creating JIT engine...");
// Define the engine that will drive everything.
//
// In this case, the engine is `wasmer_engine_jit` which roughly
// means that the executable code will live in memory.
let engine = JIT::new(&mut compiler_config).engine();
let engine = JIT::new(compiler_config).engine();

// Create a store, that holds the engine.
let store = Store::new(&engine);
Expand Down
2 changes: 1 addition & 1 deletion examples/engine_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
//
// In this case, the engine is `wasmer_engine_native` which means
// that a native object is going to be generated.
let engine = Native::new(&mut compiler_config).engine();
let engine = Native::new(compiler_config).engine();

// Create a store, that holds the engine.
let store = Store::new(&engine);
Expand Down
2 changes: 1 addition & 1 deletion examples/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());

println!("Compiling module...");
// Let's compile the Wasm module.
Expand Down
2 changes: 1 addition & 1 deletion examples/exports_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());

println!("Compiling module...");
// Let's compile the Wasm module.
Expand Down
2 changes: 1 addition & 1 deletion examples/exports_global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());

println!("Compiling module...");
// Let's compile the Wasm module.
Expand Down
2 changes: 1 addition & 1 deletion examples/exports_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());

println!("Compiling module...");
// Let's compile the Wasm module.
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn main() -> anyhow::Result<()> {
// However for the purposes of showing what's happening, we create a compiler
// (`Cranelift`) and pass it to an engine (`JIT`). We then pass the engine to
// the store and are now ready to compile and run WebAssembly!
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());
// We then use our store and Wasm bytes to compile a `Module`.
// A `Module` is a compiled WebAssembly module that isn't ready to execute yet.
let module = Module::new(&store, wasm_bytes)?;
Expand Down
2 changes: 1 addition & 1 deletion examples/imports_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());

println!("Compiling module...");
// Let's compile the Wasm module.
Expand Down
2 changes: 1 addition & 1 deletion examples/imports_function_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());

println!("Compiling module...");
// Let's compile the Wasm module.
Expand Down
2 changes: 1 addition & 1 deletion examples/imports_global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());

println!("Compiling module...");
// Let's compile the Wasm module.
Expand Down
2 changes: 1 addition & 1 deletion examples/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());

println!("Compiling module...");
// Let's compile the Wasm module.
Expand Down
2 changes: 1 addition & 1 deletion examples/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn main() -> anyhow::Result<()> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());

println!("Compiling module...");
// Let's compile the Wasm module.
Expand Down
2 changes: 1 addition & 1 deletion examples/metering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn main() -> anyhow::Result<()> {
//
// We use our previously create compiler configuration
// with the JIT engine.
let store = Store::new(&JIT::new(&compiler_config).engine());
let store = Store::new(&JIT::new(compiler_config).engine());

println!("Compiling module...");
// Let's compile the Wasm module.
Expand Down
2 changes: 1 addition & 1 deletion examples/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn main() -> anyhow::Result<()> {
)?;

// We set up our store with an engine and a compiler.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());
// Then compile our Wasm.
let module = Module::new(&store, wasm_bytes)?;
let import_object = imports! {};
Expand Down
2 changes: 1 addition & 1 deletion examples/tunables_limit_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

// Any compiler and any engine do the job here
let compiler = Cranelift::default();
let engine = JIT::new(&compiler).engine();
let engine = JIT::new(compiler).engine();

// Here is where the fun begins

Expand Down
2 changes: 1 addition & 1 deletion examples/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());

println!("Compiling module...");
// Let's compile the Wasm module.
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/headless_cranelift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use wasmer_engine_native::Native;
fuzz_target!(|wasm_bytes: &[u8]| {
let serialized = {
let mut compiler = Cranelift::default();
let store = Store::new(&Native::new(&mut compiler).engine());
let store = Store::new(&Native::new(compiler).engine());
match Module::validate(&store, wasm_bytes) {
Err(_) => return,
Ok(_) => {}
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/jit_cranelift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fuzz_target!(|wasm_bytes: &[u8]| {
let mut compiler = Cranelift::default();
compiler.canonicalize_nans(true);
compiler.enable_verifier();
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());
match Module::validate(&store, wasm_bytes) {
Ok(_) => {
let module = Module::new(&store, wasm_bytes).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/jit_llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fuzz_target!(|wasm_bytes: &[u8]| {
let mut compiler = LLVM::default();
compiler.canonicalize_nans(true);
compiler.enable_verifier();
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());
match Module::validate(&store, wasm_bytes) {
Ok(_) => {
let module = Module::new(&store, wasm_bytes).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/jit_singlepass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use wasmer_engine_jit::JIT;

fuzz_target!(|wasm_bytes: &[u8]| {
let compiler = Singlepass::default();
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());
match Module::validate(&store, wasm_bytes) {
Ok(_) => {
let module = Module::new(&store, wasm_bytes).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/native_cranelift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use wasmer_engine_native::Native;
fuzz_target!(|wasm_bytes: &[u8]| {
let serialized = {
let mut compiler = Cranelift::default();
let store = Store::new(&Native::new(&mut compiler).engine());
let store = Store::new(&Native::new(compiler).engine());
match Module::validate(&store, wasm_bytes) {
Err(_) => return,
Ok(_) => {}
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ use wasmer_engine_jit::JIT;

fuzz_target!(|wasm_bytes: &[u8]| {
let compiler = Cranelift::default();
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());
Module::validate(&store, wasm_bytes);
});
2 changes: 1 addition & 1 deletion lib/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ If you wish to use more than one compiler, you can simply create the own store.
```
use wasmer::{Store, JIT, Singlepass};
let engine = JIT::new(&Singlepass::default()).engine();
let engine = JIT::new(Singlepass::default()).engine();
let store = Store::new(&engine);
```"#
);
Expand Down
10 changes: 6 additions & 4 deletions lib/api/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Default for Store {
// sure this function doesn't emit a compile error even if
// more than one compiler is enabled.
#[allow(unreachable_code)]
fn get_config() -> impl CompilerConfig + Send + Sync {
fn get_config() -> impl CompilerConfig + Send + Sync + 'static {
cfg_if::cfg_if! {
if #[cfg(feature = "default-cranelift")] {
wasmer_compiler_cranelift::Cranelift::default()
Expand All @@ -95,13 +95,15 @@ impl Default for Store {
}

#[allow(unreachable_code, unused_mut)]
fn get_engine(mut config: impl CompilerConfig + Send + Sync) -> impl Engine + Send + Sync {
fn get_engine(
mut config: impl CompilerConfig + Send + Sync + 'static,
) -> impl Engine + Send + Sync {
cfg_if::cfg_if! {
if #[cfg(feature = "default-jit")] {
wasmer_engine_jit::JIT::new(&config)
wasmer_engine_jit::JIT::new(config)
.engine()
} else if #[cfg(feature = "default-native")] {
wasmer_engine_native::Native::new(&mut config)
wasmer_engine_native::Native::new(config)
.engine()
} else {
compile_error!("No default engine chosen")
Expand Down
Loading

0 comments on commit 54bce39

Please sign in to comment.