From aeb66ee48e3e32462ed4119dfcbefb115421dd3f Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 21 Nov 2019 13:36:44 -0800 Subject: [PATCH 01/10] Simplify compiler test options --- Cargo.lock | 5 +- lib/emscripten-tests/Cargo.toml | 10 +- lib/emscripten-tests/src/lib.rs | 32 +---- lib/emscripten-tests/tests/emtests/_common.rs | 31 +--- lib/runtime/src/lib.rs | 11 +- lib/spectests/Cargo.toml | 10 +- lib/spectests/examples/simple/main.rs | 45 ++---- lib/spectests/examples/test.rs | 31 +--- lib/spectests/tests/semantics.rs | 7 +- lib/spectests/tests/spectest.rs | 135 +++++++----------- lib/wasi-tests/Cargo.toml | 13 +- lib/wasi-tests/src/lib.rs | 3 +- lib/wasi-tests/tests/wasitests/_common.rs | 29 +--- 13 files changed, 105 insertions(+), 257 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 24fa874a3..37410c356 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1436,7 +1436,7 @@ dependencies = [ "wasmer-dev-utils 0.10.2", "wasmer-emscripten 0.10.2", "wasmer-llvm-backend 0.10.2", - "wasmer-runtime-core 0.10.2", + "wasmer-runtime 0.10.2", "wasmer-singlepass-backend 0.10.2", ] @@ -1574,7 +1574,7 @@ dependencies = [ "wabt 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-clif-backend 0.10.2", "wasmer-llvm-backend 0.10.2", - "wasmer-runtime-core 0.10.2", + "wasmer-runtime 0.10.2", "wasmer-singlepass-backend 0.10.2", ] @@ -1604,7 +1604,6 @@ dependencies = [ "wasmer-dev-utils 0.10.2", "wasmer-llvm-backend 0.10.2", "wasmer-runtime 0.10.2", - "wasmer-runtime-core 0.10.2", "wasmer-singlepass-backend 0.10.2", "wasmer-wasi 0.10.2", ] diff --git a/lib/emscripten-tests/Cargo.toml b/lib/emscripten-tests/Cargo.toml index 49880090f..6be2a3056 100644 --- a/lib/emscripten-tests/Cargo.toml +++ b/lib/emscripten-tests/Cargo.toml @@ -10,8 +10,8 @@ build = "build/mod.rs" [dependencies] wasmer-emscripten = { path = "../emscripten", version = "0.10.2" } -wasmer-runtime-core = { path = "../runtime-core", version = "0.10.2" } -wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2" } +wasmer-runtime = { path = "../runtime", version = "0.10.2", default-features = false } +wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2", optional = true} wasmer-llvm-backend = { path = "../llvm-backend", version = "0.10.2", optional = true } wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.10.2", optional = true } @@ -23,6 +23,6 @@ wasmer-dev-utils = { path = "../dev-utils", version = "0.10.2"} glob = "0.3" [features] -clif = [] -llvm = ["wasmer-llvm-backend"] -singlepass = ["wasmer-singlepass-backend"] +clif = ["wasmer-clif-backend", "wasmer-runtime/default-backend-cranelift"] +singlepass = ["wasmer-singlepass-backend", "wasmer-runtime/default-backend-singlepass"] +llvm = ["wasmer-llvm-backend", "wasmer-runtime/default-backend-llvm"] diff --git a/lib/emscripten-tests/src/lib.rs b/lib/emscripten-tests/src/lib.rs index 1da0abc73..496aa5d73 100644 --- a/lib/emscripten-tests/src/lib.rs +++ b/lib/emscripten-tests/src/lib.rs @@ -3,40 +3,14 @@ mod tests { use std::sync::Arc; use wabt::wat2wasm; use wasmer_emscripten::is_emscripten_module; - use wasmer_runtime_core::backend::Compiler; - use wasmer_runtime_core::compile_with; - - #[cfg(feature = "clif")] - fn get_compiler() -> impl Compiler { - use wasmer_clif_backend::CraneliftCompiler; - CraneliftCompiler::new() - } - - #[cfg(feature = "llvm")] - fn get_compiler() -> impl Compiler { - use wasmer_llvm_backend::LLVMCompiler; - LLVMCompiler::new() - } - - #[cfg(feature = "singlepass")] - fn get_compiler() -> impl Compiler { - use wasmer_singlepass_backend::SinglePassCompiler; - SinglePassCompiler::new() - } - - #[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))] - fn get_compiler() -> impl Compiler { - panic!("compiler not specified, activate a compiler via features"); - use wasmer_clif_backend::CraneliftCompiler; - CraneliftCompiler::new() - } + use wasmer_runtime::compile; #[test] fn should_detect_emscripten_files() { const WAST_BYTES: &[u8] = include_bytes!("tests/is_emscripten_true.wast"); let wasm_binary = wat2wasm(WAST_BYTES.to_vec()).expect("Can't convert to wasm"); let module = - compile_with(&wasm_binary[..], &get_compiler()).expect("WASM can't be compiled"); + compile(&wasm_binary[..]).expect("WASM can't be compiled"); let module = Arc::new(module); assert!(is_emscripten_module(&module)); } @@ -46,7 +20,7 @@ mod tests { const WAST_BYTES: &[u8] = include_bytes!("tests/is_emscripten_false.wast"); let wasm_binary = wat2wasm(WAST_BYTES.to_vec()).expect("Can't convert to wasm"); let module = - compile_with(&wasm_binary[..], &get_compiler()).expect("WASM can't be compiled"); + compile(&wasm_binary[..]).expect("WASM can't be compiled"); let module = Arc::new(module); assert!(!is_emscripten_module(&module)); } diff --git a/lib/emscripten-tests/tests/emtests/_common.rs b/lib/emscripten-tests/tests/emtests/_common.rs index 1e5dfba6e..2e6c590d9 100644 --- a/lib/emscripten-tests/tests/emtests/_common.rs +++ b/lib/emscripten-tests/tests/emtests/_common.rs @@ -5,39 +5,12 @@ macro_rules! assert_emscripten_output { EmscriptenGlobals, generate_emscripten_env, }; - use wasmer_runtime_core::{ - backend::Compiler, - }; + use wasmer_runtime::compile; use wasmer_dev_utils::stdio::StdioCapturer; - #[cfg(feature = "clif")] - fn get_compiler() -> impl Compiler { - use wasmer_clif_backend::CraneliftCompiler; - CraneliftCompiler::new() - } - - #[cfg(feature = "llvm")] - fn get_compiler() -> impl Compiler { - use wasmer_llvm_backend::LLVMCompiler; - LLVMCompiler::new() - } - - #[cfg(feature = "singlepass")] - fn get_compiler() -> impl Compiler { - use wasmer_singlepass_backend::SinglePassCompiler; - SinglePassCompiler::new() - } - - #[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))] - fn get_compiler() -> impl Compiler { - panic!("compiler not specified, activate a compiler via features"); - use wasmer_clif_backend::CraneliftCompiler; - CraneliftCompiler::new() - } - let wasm_bytes = include_bytes!($file); - let module = wasmer_runtime_core::compile_with(&wasm_bytes[..], &get_compiler()) + let module = compile(&wasm_bytes[..]) .expect("WASM can't be compiled"); // let module = compile(&wasm_bytes[..]) diff --git a/lib/runtime/src/lib.rs b/lib/runtime/src/lib.rs index ad47226fd..4d3bf4c4f 100644 --- a/lib/runtime/src/lib.rs +++ b/lib/runtime/src/lib.rs @@ -87,11 +87,11 @@ //! [`wasmer-clif-backend`]: https://crates.io/crates/wasmer-clif-backend //! [`compile_with`]: fn.compile_with.html -pub use wasmer_runtime_core::backend::Backend; +pub use wasmer_runtime_core::backend::{Backend, Features}; pub use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler}; pub use wasmer_runtime_core::export::Export; pub use wasmer_runtime_core::global::Global; -pub use wasmer_runtime_core::import::ImportObject; +pub use wasmer_runtime_core::import::{ImportObject, LikeNamespace}; pub use wasmer_runtime_core::instance::{DynFunc, Instance}; pub use wasmer_runtime_core::memory::ptr::{Array, Item, WasmPtr}; pub use wasmer_runtime_core::memory::Memory; @@ -131,9 +131,14 @@ pub mod units { pub use wasmer_runtime_core::units::{Bytes, Pages}; } +pub mod types { + //! Various types. + pub use wasmer_runtime_core::types::*; +} + pub mod cache; -use wasmer_runtime_core::backend::{Compiler, CompilerConfig}; +pub use wasmer_runtime_core::backend::{Compiler, CompilerConfig}; /// Compile WebAssembly binary code into a [`Module`]. /// This function is useful if it is necessary to diff --git a/lib/spectests/Cargo.toml b/lib/spectests/Cargo.toml index 54c17ccc1..fe02bec5d 100644 --- a/lib/spectests/Cargo.toml +++ b/lib/spectests/Cargo.toml @@ -9,8 +9,8 @@ edition = "2018" [dependencies] glob = "0.3" -wasmer-runtime-core = { path = "../runtime-core", version = "0.10.2" } -wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2" } +wasmer-runtime = { path = "../runtime", version = "0.10.2", default-features = false} +wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2", optional = true} wasmer-llvm-backend = { path = "../llvm-backend", version = "0.10.2", optional = true } wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.10.2", optional = true } @@ -23,6 +23,6 @@ wabt = "0.9.1" [features] default = ["fast-tests"] fast-tests = [] -clif = [] -llvm = ["wasmer-llvm-backend"] -singlepass = ["wasmer-singlepass-backend"] +clif = ["wasmer-clif-backend", "wasmer-runtime/default-backend-cranelift"] +singlepass = ["wasmer-singlepass-backend", "wasmer-runtime/default-backend-singlepass"] +llvm = ["wasmer-llvm-backend", "wasmer-runtime/default-backend-llvm"] diff --git a/lib/spectests/examples/simple/main.rs b/lib/spectests/examples/simple/main.rs index e9309c3c2..20643feb1 100644 --- a/lib/spectests/examples/simple/main.rs +++ b/lib/spectests/examples/simple/main.rs @@ -1,46 +1,23 @@ use wabt::wat2wasm; -use wasmer_runtime_core::{ - backend::Compiler, +use wasmer_runtime::{ error, - global::Global, - memory::Memory, - prelude::*, - table::Table, + func, + Global, + Memory, + imports, + compile, + Table, + Ctx, types::{ElementType, MemoryDescriptor, TableDescriptor, Value}, units::Pages, }; -#[cfg(feature = "clif")] -fn get_compiler() -> impl Compiler { - use wasmer_clif_backend::CraneliftCompiler; - CraneliftCompiler::new() -} - -#[cfg(feature = "llvm")] -fn get_compiler() -> impl Compiler { - use wasmer_llvm_backend::LLVMCompiler; - LLVMCompiler::new() -} - -#[cfg(feature = "singlepass")] -fn get_compiler() -> impl Compiler { - use wasmer_singlepass_backend::SinglePassCompiler; - SinglePassCompiler::new() -} - -#[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))] -fn get_compiler() -> impl Compiler { - panic!("compiler not specified, activate a compiler via features"); - use wasmer_clif_backend::CraneliftCompiler; - CraneliftCompiler::new() -} - static EXAMPLE_WASM: &'static [u8] = include_bytes!("simple.wasm"); fn main() -> error::Result<()> { let wasm_binary = wat2wasm(IMPORT_MODULE.as_bytes()).expect("WAST not valid or malformed"); - let inner_module = wasmer_runtime_core::compile_with(&wasm_binary, &get_compiler())?; + let inner_module = compile(&wasm_binary)?; let memory_desc = MemoryDescriptor::new(Pages(1), Some(Pages(1)), false).unwrap(); let memory = Memory::new(memory_desc).unwrap(); @@ -71,7 +48,7 @@ fn main() -> error::Result<()> { "env" => inner_instance, }; - let outer_module = wasmer_runtime_core::compile_with(EXAMPLE_WASM, &get_compiler())?; + let outer_module = compile(EXAMPLE_WASM)?; let outer_instance = outer_module.instantiate(&outer_imports)?; let ret = outer_instance.call("main", &[Value::I32(42)])?; println!("ret: {:?}", ret); @@ -79,7 +56,7 @@ fn main() -> error::Result<()> { Ok(()) } -fn print_num(ctx: &mut vm::Ctx, n: i32) -> Result { +fn print_num(ctx: &mut Ctx, n: i32) -> Result { println!("print_num({})", n); let memory: &Memory = ctx.memory(0); diff --git a/lib/spectests/examples/test.rs b/lib/spectests/examples/test.rs index 006fc1397..77e16abdf 100644 --- a/lib/spectests/examples/test.rs +++ b/lib/spectests/examples/test.rs @@ -1,5 +1,5 @@ use wabt::wat2wasm; -use wasmer_runtime_core::{backend::Compiler, import::ImportObject, Instance}; +use wasmer_runtime::{ImportObject, Instance, compile}; fn main() { let instance = create_module_1(); @@ -23,38 +23,13 @@ fn create_module_1() -> Instance { (elem (;1;) (i32.const 9) 1)) "#; let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); - let module = wasmer_runtime_core::compile_with(&wasm_binary[..], &get_compiler()) + let module = compile(&wasm_binary[..]) .expect("WASM can't be compiled"); module .instantiate(&generate_imports()) .expect("WASM can't be instantiated") } -#[cfg(feature = "clif")] -fn get_compiler() -> impl Compiler { - use wasmer_clif_backend::CraneliftCompiler; - CraneliftCompiler::new() -} - -#[cfg(feature = "llvm")] -fn get_compiler() -> impl Compiler { - use wasmer_llvm_backend::LLVMCompiler; - LLVMCompiler::new() -} - -#[cfg(feature = "singlepass")] -fn get_compiler() -> impl Compiler { - use wasmer_singlepass_backend::SinglePassCompiler; - SinglePassCompiler::new() -} - -#[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))] -fn get_compiler() -> impl Compiler { - panic!("compiler not specified, activate a compiler via features"); - use wasmer_clif_backend::CraneliftCompiler; - CraneliftCompiler::new() -} - static IMPORT_MODULE: &str = r#" (module (type $t0 (func (param i32))) @@ -68,7 +43,7 @@ static IMPORT_MODULE: &str = r#" pub fn generate_imports() -> ImportObject { let wasm_binary = wat2wasm(IMPORT_MODULE.as_bytes()).expect("WAST not valid or malformed"); - let module = wasmer_runtime_core::compile_with(&wasm_binary[..], &get_compiler()) + let module = compile(&wasm_binary[..]) .expect("WASM can't be compiled"); let instance = module .instantiate(&ImportObject::new()) diff --git a/lib/spectests/tests/semantics.rs b/lib/spectests/tests/semantics.rs index 0bffa9dca..7e1be1f7a 100644 --- a/lib/spectests/tests/semantics.rs +++ b/lib/spectests/tests/semantics.rs @@ -1,10 +1,9 @@ #[cfg(test)] mod tests { use wabt::wat2wasm; - use wasmer_clif_backend::CraneliftCompiler; - use wasmer_runtime_core::{ + use wasmer_runtime::{ error::{CallError, RuntimeError}, - import::ImportObject, + ImportObject, }; // The semantics of stack overflow are documented at: @@ -22,7 +21,7 @@ mod tests { (elem (;0;) (i32.const 0) 0)) "#; let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); - let module = wasmer_runtime_core::compile_with(&wasm_binary[..], &CraneliftCompiler::new()) + let module = wasmer_runtime::compile(&wasm_binary[..]) .expect("WASM can't be compiled"); let instance = module .instantiate(&ImportObject::new()) diff --git a/lib/spectests/tests/spectest.rs b/lib/spectests/tests/spectest.rs index 9bb6f631c..96ab1c317 100644 --- a/lib/spectests/tests/spectest.rs +++ b/lib/spectests/tests/spectest.rs @@ -63,31 +63,6 @@ mod tests { } } - #[cfg(feature = "clif")] - fn get_compiler() -> impl Compiler { - use wasmer_clif_backend::CraneliftCompiler; - CraneliftCompiler::new() - } - - #[cfg(feature = "llvm")] - fn get_compiler() -> impl Compiler { - use wasmer_llvm_backend::LLVMCompiler; - LLVMCompiler::new() - } - - #[cfg(feature = "singlepass")] - fn get_compiler() -> impl Compiler { - use wasmer_singlepass_backend::SinglePassCompiler; - SinglePassCompiler::new() - } - - #[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))] - fn get_compiler() -> impl Compiler { - panic!("compiler not specified, activate a compiler via features"); - use wasmer_clif_backend::CraneliftCompiler; - CraneliftCompiler::new() - } - #[cfg(feature = "clif")] fn get_compiler_name() -> &'static str { "clif" @@ -241,20 +216,23 @@ mod tests { use std::panic::AssertUnwindSafe; use std::path::PathBuf; use wabt::script::{Action, Command, CommandKind, ScriptParser, Value}; - use wasmer_runtime_core::backend::{Compiler, CompilerConfig, Features}; - use wasmer_runtime_core::error::CompileError; - use wasmer_runtime_core::import::ImportObject; - use wasmer_runtime_core::Instance; - use wasmer_runtime_core::{ - export::Export, - global::Global, - import::LikeNamespace, - memory::Memory, - table::Table, + use wasmer_runtime::{ + CompilerConfig, + ImportObject, + LikeNamespace, + Instance, + error::{CompileError}, + Export, + Global, + Memory, + Table, types::{ElementType, MemoryDescriptor, TableDescriptor}, units::Pages, + + Features, + func, imports, Ctx, + compile_with_config, }; - use wasmer_runtime_core::{func, imports, vm::Ctx}; fn parse_and_run( path: &PathBuf, @@ -328,9 +306,8 @@ mod tests { }, ..Default::default() }; - let module = wasmer_runtime_core::compile_with_config( + let module = compile_with_config( &module.into_vec(), - &get_compiler(), config, ) .expect("WASM can't be compiled"); @@ -375,7 +352,7 @@ mod tests { &named_modules, &module, |instance| { - let params: Vec = + let params: Vec = args.iter().cloned().map(convert_value).collect(); instance.call(&field, ¶ms[..]) }, @@ -507,7 +484,7 @@ mod tests { } => { let maybe_call_result = with_instance(instance.clone(), &named_modules, &module, |instance| { - let params: Vec = + let params: Vec = args.iter().cloned().map(convert_value).collect(); instance.call(&field, ¶ms[..]) }); @@ -578,7 +555,7 @@ mod tests { } => { let maybe_call_result = with_instance(instance.clone(), &named_modules, &module, |instance| { - let params: Vec = + let params: Vec = args.iter().cloned().map(convert_value).collect(); instance.call(&field, ¶ms[..]) }); @@ -649,7 +626,7 @@ mod tests { } => { let maybe_call_result = with_instance(instance.clone(), &named_modules, &module, |instance| { - let params: Vec = + let params: Vec = args.iter().cloned().map(convert_value).collect(); instance.call(&field, ¶ms[..]) }); @@ -667,7 +644,7 @@ mod tests { ); } else { let call_result = maybe_call_result.unwrap(); - use wasmer_runtime_core::error::{CallError, RuntimeError}; + use wasmer_runtime::error::{CallError, RuntimeError}; match call_result { Err(e) => { match e { @@ -738,9 +715,8 @@ mod tests { }, ..Default::default() }; - wasmer_runtime_core::compile_with_config( + compile_with_config( &module.into_vec(), - &get_compiler(), config, ) }); @@ -794,9 +770,8 @@ mod tests { }, ..Default::default() }; - wasmer_runtime_core::compile_with_config( + compile_with_config( &module.into_vec(), - &get_compiler(), config, ) }); @@ -849,9 +824,8 @@ mod tests { }, ..Default::default() }; - let module = wasmer_runtime_core::compile_with_config( + let module = compile_with_config( &module.into_vec(), - &get_compiler(), config, ) .expect("WASM can't be compiled"); @@ -891,7 +865,7 @@ mod tests { &named_modules, &module, |instance| { - let params: Vec = + let params: Vec = args.iter().cloned().map(convert_value).collect(); instance.call(&field, ¶ms[..]) }, @@ -948,9 +922,8 @@ mod tests { }, ..Default::default() }; - let module = wasmer_runtime_core::compile_with_config( + let module = compile_with_config( &module.into_vec(), - &get_compiler(), config, ) .expect("WASM can't be compiled"); @@ -987,7 +960,7 @@ mod tests { ); } Err(e) => match e { - wasmer_runtime_core::error::Error::LinkError(_) => { + wasmer_runtime::error::Error::LinkError(_) => { test_report.count_passed(); } _ => { @@ -1046,7 +1019,7 @@ mod tests { } => { let maybe_call_result = with_instance(instance.clone(), &named_modules, &module, |instance| { - let params: Vec = + let params: Vec = args.iter().cloned().map(convert_value).collect(); instance.call(&field, ¶ms[..]) }); @@ -1094,29 +1067,29 @@ mod tests { Ok(test_report) } - fn is_canonical_nan(val: wasmer_runtime_core::types::Value) -> bool { + fn is_canonical_nan(val: wasmer_runtime::types::Value) -> bool { match val { - wasmer_runtime_core::types::Value::F32(x) => x.is_canonical_nan(), - wasmer_runtime_core::types::Value::F64(x) => x.is_canonical_nan(), + wasmer_runtime::types::Value::F32(x) => x.is_canonical_nan(), + wasmer_runtime::types::Value::F64(x) => x.is_canonical_nan(), _ => panic!("value is not a float {:?}", val), } } - fn is_arithmetic_nan(val: wasmer_runtime_core::types::Value) -> bool { + fn is_arithmetic_nan(val: wasmer_runtime::types::Value) -> bool { match val { - wasmer_runtime_core::types::Value::F32(x) => x.is_quiet_nan(), - wasmer_runtime_core::types::Value::F64(x) => x.is_quiet_nan(), + wasmer_runtime::types::Value::F32(x) => x.is_quiet_nan(), + wasmer_runtime::types::Value::F64(x) => x.is_quiet_nan(), _ => panic!("value is not a float {:?}", val), } } - fn value_to_hex(val: wasmer_runtime_core::types::Value) -> String { + fn value_to_hex(val: wasmer_runtime::types::Value) -> String { match val { - wasmer_runtime_core::types::Value::I32(x) => format!("{:#x}", x), - wasmer_runtime_core::types::Value::I64(x) => format!("{:#x}", x), - wasmer_runtime_core::types::Value::F32(x) => format!("{:#x}", x.to_bits()), - wasmer_runtime_core::types::Value::F64(x) => format!("{:#x}", x.to_bits()), - wasmer_runtime_core::types::Value::V128(x) => format!("{:#x}", x), + wasmer_runtime::types::Value::I32(x) => format!("{:#x}", x), + wasmer_runtime::types::Value::I64(x) => format!("{:#x}", x), + wasmer_runtime::types::Value::F32(x) => format!("{:#x}", x.to_bits()), + wasmer_runtime::types::Value::F64(x) => format!("{:#x}", x.to_bits()), + wasmer_runtime::types::Value::V128(x) => format!("{:#x}", x), } } @@ -1129,13 +1102,13 @@ mod tests { V128(u128), } - fn convert_wasmer_value(other: wasmer_runtime_core::types::Value) -> SpectestValue { + fn convert_wasmer_value(other: wasmer_runtime::types::Value) -> SpectestValue { match other { - wasmer_runtime_core::types::Value::I32(v) => SpectestValue::I32(v), - wasmer_runtime_core::types::Value::I64(v) => SpectestValue::I64(v), - wasmer_runtime_core::types::Value::F32(v) => SpectestValue::F32(v.to_bits()), - wasmer_runtime_core::types::Value::F64(v) => SpectestValue::F64(v.to_bits()), - wasmer_runtime_core::types::Value::V128(v) => SpectestValue::V128(v), + wasmer_runtime::types::Value::I32(v) => SpectestValue::I32(v), + wasmer_runtime::types::Value::I64(v) => SpectestValue::I64(v), + wasmer_runtime::types::Value::F32(v) => SpectestValue::F32(v.to_bits()), + wasmer_runtime::types::Value::F64(v) => SpectestValue::F64(v.to_bits()), + wasmer_runtime::types::Value::V128(v) => SpectestValue::V128(v), } } @@ -1149,13 +1122,13 @@ mod tests { } } - fn convert_value(other: Value) -> wasmer_runtime_core::types::Value { + fn convert_value(other: Value) -> wasmer_runtime::types::Value { match other { - Value::I32(v) => wasmer_runtime_core::types::Value::I32(v), - Value::I64(v) => wasmer_runtime_core::types::Value::I64(v), - Value::F32(v) => wasmer_runtime_core::types::Value::F32(v), - Value::F64(v) => wasmer_runtime_core::types::Value::F64(v), - Value::V128(v) => wasmer_runtime_core::types::Value::V128(v), + Value::I32(v) => wasmer_runtime::types::Value::I32(v), + Value::I64(v) => wasmer_runtime::types::Value::I64(v), + Value::F32(v) => wasmer_runtime::types::Value::F32(v), + Value::F64(v) => wasmer_runtime::types::Value::F64(v), + Value::V128(v) => wasmer_runtime::types::Value::V128(v), } } @@ -1199,9 +1172,9 @@ mod tests { let memory_desc = MemoryDescriptor::new(Pages(1), Some(Pages(2)), false).unwrap(); let memory = Memory::new(memory_desc).unwrap(); - let global_i32 = Global::new(wasmer_runtime_core::types::Value::I32(666)); - let global_f32 = Global::new(wasmer_runtime_core::types::Value::F32(666.0)); - let global_f64 = Global::new(wasmer_runtime_core::types::Value::F64(666.0)); + let global_i32 = Global::new(wasmer_runtime::types::Value::I32(666)); + let global_f32 = Global::new(wasmer_runtime::types::Value::F32(666.0)); + let global_f64 = Global::new(wasmer_runtime::types::Value::F64(666.0)); let table = Table::new(TableDescriptor { element: ElementType::Anyfunc, diff --git a/lib/wasi-tests/Cargo.toml b/lib/wasi-tests/Cargo.toml index 05544c7a3..fa81d0fc1 100644 --- a/lib/wasi-tests/Cargo.toml +++ b/lib/wasi-tests/Cargo.toml @@ -9,22 +9,21 @@ publish = false build = "build/mod.rs" [dependencies] -wasmer-runtime-core = { path = "../runtime-core", version = "0.10.2" } -wasmer-runtime = { path = "../runtime", version = "0.10.2" } +# We set default features to false to be able to use the singlepass backend properly +wasmer-runtime = { path = "../runtime", version = "0.10.2", default-features = false } wasmer-wasi = { path = "../wasi", version = "0.10.2" } # hack to get tests to work +wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2", optional = true} wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.10.2", optional = true } wasmer-llvm-backend = { path = "../llvm-backend", version = "0.10.2", optional = true } - [build-dependencies] glob = "0.3" [dev-dependencies] -wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2" } wasmer-dev-utils = { path = "../dev-utils", version = "0.10.2"} [features] -clif = [] -singlepass = ["wasmer-singlepass-backend"] -llvm = ["wasmer-llvm-backend"] +clif = ["wasmer-clif-backend", "wasmer-runtime/default-backend-cranelift"] +singlepass = ["wasmer-singlepass-backend", "wasmer-runtime/default-backend-singlepass"] +llvm = ["wasmer-llvm-backend", "wasmer-runtime/default-backend-llvm"] diff --git a/lib/wasi-tests/src/lib.rs b/lib/wasi-tests/src/lib.rs index 4508e432e..7e3faecf3 100644 --- a/lib/wasi-tests/src/lib.rs +++ b/lib/wasi-tests/src/lib.rs @@ -1,6 +1,5 @@ #![cfg(test)] -use wasmer_runtime::{compile, Func}; -use wasmer_runtime_core::vm::Ctx; +use wasmer_runtime::{compile, Func, Ctx}; use wasmer_wasi::{state::*, *}; use std::ffi::c_void; diff --git a/lib/wasi-tests/tests/wasitests/_common.rs b/lib/wasi-tests/tests/wasitests/_common.rs index 958fdf6ad..7aedda0c2 100644 --- a/lib/wasi-tests/tests/wasitests/_common.rs +++ b/lib/wasi-tests/tests/wasitests/_common.rs @@ -1,36 +1,11 @@ macro_rules! assert_wasi_output { ($file:expr, $name:expr, $po_dir_args: expr, $mapdir_args:expr, $envvar_args:expr, $expected:expr) => {{ use wasmer_dev_utils::stdio::StdioCapturer; - use wasmer_runtime_core::{backend::Compiler, Func}; + use wasmer_runtime::Func; use wasmer_wasi::generate_import_object; - - #[cfg(feature = "clif")] - fn get_compiler() -> impl Compiler { - use wasmer_clif_backend::CraneliftCompiler; - CraneliftCompiler::new() - } - - #[cfg(feature = "llvm")] - fn get_compiler() -> impl Compiler { - use wasmer_llvm_backend::LLVMCompiler; - LLVMCompiler::new() - } - - #[cfg(feature = "singlepass")] - fn get_compiler() -> impl Compiler { - use wasmer_singlepass_backend::SinglePassCompiler; - SinglePassCompiler::new() - } - - #[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))] - fn get_compiler() -> impl Compiler { - compile_error!("compiler not specified, activate a compiler via features"); - unreachable!(); - } - let wasm_bytes = include_bytes!($file); - let module = wasmer_runtime_core::compile_with(&wasm_bytes[..], &get_compiler()) + let module = wasmer_runtime::compile(&wasm_bytes[..]) .expect("WASM can't be compiled"); let import_object = generate_import_object(vec![], vec![], $po_dir_args, $mapdir_args); From c3f93f1275748f84ba4d5ac8c24fc97860765456 Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 21 Nov 2019 13:38:22 -0800 Subject: [PATCH 02/10] Fixed formatting --- lib/emscripten-tests/src/lib.rs | 6 +-- lib/spectests/examples/simple/main.rs | 10 +---- lib/spectests/examples/test.rs | 8 ++-- lib/spectests/tests/semantics.rs | 3 +- lib/spectests/tests/spectest.rs | 49 ++++++----------------- lib/wasi-tests/src/lib.rs | 2 +- lib/wasi-tests/tests/wasitests/_common.rs | 3 +- 7 files changed, 23 insertions(+), 58 deletions(-) diff --git a/lib/emscripten-tests/src/lib.rs b/lib/emscripten-tests/src/lib.rs index 496aa5d73..59bcf90eb 100644 --- a/lib/emscripten-tests/src/lib.rs +++ b/lib/emscripten-tests/src/lib.rs @@ -9,8 +9,7 @@ mod tests { fn should_detect_emscripten_files() { const WAST_BYTES: &[u8] = include_bytes!("tests/is_emscripten_true.wast"); let wasm_binary = wat2wasm(WAST_BYTES.to_vec()).expect("Can't convert to wasm"); - let module = - compile(&wasm_binary[..]).expect("WASM can't be compiled"); + let module = compile(&wasm_binary[..]).expect("WASM can't be compiled"); let module = Arc::new(module); assert!(is_emscripten_module(&module)); } @@ -19,8 +18,7 @@ mod tests { fn should_detect_non_emscripten_files() { const WAST_BYTES: &[u8] = include_bytes!("tests/is_emscripten_false.wast"); let wasm_binary = wat2wasm(WAST_BYTES.to_vec()).expect("Can't convert to wasm"); - let module = - compile(&wasm_binary[..]).expect("WASM can't be compiled"); + let module = compile(&wasm_binary[..]).expect("WASM can't be compiled"); let module = Arc::new(module); assert!(!is_emscripten_module(&module)); } diff --git a/lib/spectests/examples/simple/main.rs b/lib/spectests/examples/simple/main.rs index 20643feb1..6ef870479 100644 --- a/lib/spectests/examples/simple/main.rs +++ b/lib/spectests/examples/simple/main.rs @@ -1,15 +1,9 @@ use wabt::wat2wasm; use wasmer_runtime::{ - error, - func, - Global, - Memory, - imports, - compile, - Table, - Ctx, + compile, error, func, imports, types::{ElementType, MemoryDescriptor, TableDescriptor, Value}, units::Pages, + Ctx, Global, Memory, Table, }; static EXAMPLE_WASM: &'static [u8] = include_bytes!("simple.wasm"); diff --git a/lib/spectests/examples/test.rs b/lib/spectests/examples/test.rs index 77e16abdf..eff7793b9 100644 --- a/lib/spectests/examples/test.rs +++ b/lib/spectests/examples/test.rs @@ -1,5 +1,5 @@ use wabt::wat2wasm; -use wasmer_runtime::{ImportObject, Instance, compile}; +use wasmer_runtime::{compile, ImportObject, Instance}; fn main() { let instance = create_module_1(); @@ -23,8 +23,7 @@ fn create_module_1() -> Instance { (elem (;1;) (i32.const 9) 1)) "#; let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); - let module = compile(&wasm_binary[..]) - .expect("WASM can't be compiled"); + let module = compile(&wasm_binary[..]).expect("WASM can't be compiled"); module .instantiate(&generate_imports()) .expect("WASM can't be instantiated") @@ -43,8 +42,7 @@ static IMPORT_MODULE: &str = r#" pub fn generate_imports() -> ImportObject { let wasm_binary = wat2wasm(IMPORT_MODULE.as_bytes()).expect("WAST not valid or malformed"); - let module = compile(&wasm_binary[..]) - .expect("WASM can't be compiled"); + let module = compile(&wasm_binary[..]).expect("WASM can't be compiled"); let instance = module .instantiate(&ImportObject::new()) .expect("WASM can't be instantiated"); diff --git a/lib/spectests/tests/semantics.rs b/lib/spectests/tests/semantics.rs index 7e1be1f7a..eadbeef0e 100644 --- a/lib/spectests/tests/semantics.rs +++ b/lib/spectests/tests/semantics.rs @@ -21,8 +21,7 @@ mod tests { (elem (;0;) (i32.const 0) 0)) "#; let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); - let module = wasmer_runtime::compile(&wasm_binary[..]) - .expect("WASM can't be compiled"); + let module = wasmer_runtime::compile(&wasm_binary[..]).expect("WASM can't be compiled"); let instance = module .instantiate(&ImportObject::new()) .expect("WASM can't be instantiated"); diff --git a/lib/spectests/tests/spectest.rs b/lib/spectests/tests/spectest.rs index 96ab1c317..3b03b598f 100644 --- a/lib/spectests/tests/spectest.rs +++ b/lib/spectests/tests/spectest.rs @@ -217,21 +217,13 @@ mod tests { use std::path::PathBuf; use wabt::script::{Action, Command, CommandKind, ScriptParser, Value}; use wasmer_runtime::{ - CompilerConfig, - ImportObject, - LikeNamespace, - Instance, - error::{CompileError}, - Export, - Global, - Memory, - Table, + compile_with_config, + error::CompileError, + func, imports, types::{ElementType, MemoryDescriptor, TableDescriptor}, units::Pages, - - Features, - func, imports, Ctx, - compile_with_config, + CompilerConfig, Ctx, Export, Features, Global, ImportObject, Instance, LikeNamespace, + Memory, Table, }; fn parse_and_run( @@ -306,11 +298,8 @@ mod tests { }, ..Default::default() }; - let module = compile_with_config( - &module.into_vec(), - config, - ) - .expect("WASM can't be compiled"); + let module = compile_with_config(&module.into_vec(), config) + .expect("WASM can't be compiled"); let i = module .instantiate(&spectest_import_object) .expect("WASM can't be instantiated"); @@ -715,10 +704,7 @@ mod tests { }, ..Default::default() }; - compile_with_config( - &module.into_vec(), - config, - ) + compile_with_config(&module.into_vec(), config) }); match result { Ok(module) => { @@ -770,10 +756,7 @@ mod tests { }, ..Default::default() }; - compile_with_config( - &module.into_vec(), - config, - ) + compile_with_config(&module.into_vec(), config) }); match result { @@ -824,11 +807,8 @@ mod tests { }, ..Default::default() }; - let module = compile_with_config( - &module.into_vec(), - config, - ) - .expect("WASM can't be compiled"); + let module = compile_with_config(&module.into_vec(), config) + .expect("WASM can't be compiled"); let result = panic::catch_unwind(AssertUnwindSafe(|| { module .instantiate(&spectest_import_object) @@ -922,11 +902,8 @@ mod tests { }, ..Default::default() }; - let module = compile_with_config( - &module.into_vec(), - config, - ) - .expect("WASM can't be compiled"); + let module = compile_with_config(&module.into_vec(), config) + .expect("WASM can't be compiled"); module.instantiate(&spectest_import_object) })); match result { diff --git a/lib/wasi-tests/src/lib.rs b/lib/wasi-tests/src/lib.rs index 7e3faecf3..a6853b4f5 100644 --- a/lib/wasi-tests/src/lib.rs +++ b/lib/wasi-tests/src/lib.rs @@ -1,5 +1,5 @@ #![cfg(test)] -use wasmer_runtime::{compile, Func, Ctx}; +use wasmer_runtime::{compile, Ctx, Func}; use wasmer_wasi::{state::*, *}; use std::ffi::c_void; diff --git a/lib/wasi-tests/tests/wasitests/_common.rs b/lib/wasi-tests/tests/wasitests/_common.rs index 7aedda0c2..7b26bd8d5 100644 --- a/lib/wasi-tests/tests/wasitests/_common.rs +++ b/lib/wasi-tests/tests/wasitests/_common.rs @@ -5,8 +5,7 @@ macro_rules! assert_wasi_output { use wasmer_wasi::generate_import_object; let wasm_bytes = include_bytes!($file); - let module = wasmer_runtime::compile(&wasm_bytes[..]) - .expect("WASM can't be compiled"); + let module = wasmer_runtime::compile(&wasm_bytes[..]).expect("WASM can't be compiled"); let import_object = generate_import_object(vec![], vec![], $po_dir_args, $mapdir_args); From 31437a1e749f8c0b2154ccbb3a5365c0ab7cdbab Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 21 Nov 2019 17:22:21 -0800 Subject: [PATCH 03/10] Autodetect default backend, add features for architecture type --- Cargo.lock | 1 + Cargo.toml | 8 +++++- lib/middleware-common-tests/Cargo.toml | 5 ++-- lib/runtime-core-tests/Cargo.toml | 2 +- lib/runtime/Cargo.toml | 2 +- lib/runtime/build.rs | 38 ++++++++++++++++++++++++++ 6 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 lib/runtime/build.rs diff --git a/Cargo.lock b/Cargo.lock index 37410c356..9db253282 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1353,6 +1353,7 @@ dependencies = [ "wasmer-middleware-common-tests 0.10.2", "wasmer-runtime 0.10.2", "wasmer-runtime-core 0.10.2", + "wasmer-runtime-core-tests 0.10.2", "wasmer-singlepass-backend 0.10.2", "wasmer-wasi 0.10.2", "wasmer-wasi-tests 0.10.2", diff --git a/Cargo.toml b/Cargo.toml index 8724d91d4..48c4cfce5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ wasmer-kernel-loader = { path = "lib/kernel-loader", optional = true } wasmer-dev-utils = { path = "lib/dev-utils", optional = true } wasmer-wasi-tests = { path = "lib/wasi-tests", optional = true } wasmer-middleware-common-tests = { path = "lib/middleware-common-tests", optional = true } +wasmer-runtime-core-tests = { path = "lib/runtime-core-tests", optional = true } wasmer-emscripten-tests = { path = "lib/emscripten-tests", optional = true } [workspace] @@ -73,8 +74,10 @@ serde = { version = "1", features = ["derive"] } # used by the plugin example typetag = "0.1" # used by the plugin example [features] -default = ["fast-tests", "wasi", "backend-cranelift"] +default = ["fast-tests", "wasi", "x86_64"] "loader-kernel" = ["wasmer-kernel-loader"] +aarch64 = ["backend-singlepass"] +x86_64 = ["backend-cranelift"] debug = ["wasmer-runtime-core/debug"] trace = ["wasmer-runtime-core/trace"] extra-debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] @@ -84,6 +87,7 @@ backend-cranelift = [ "wasmer-runtime-core/backend-cranelift", "wasmer-runtime/cranelift", "wasmer-middleware-common-tests/clif", + "wasmer-runtime-core-tests/backend-cranelift", "wasmer-wasi-tests/clif" ] backend-llvm = [ @@ -91,6 +95,7 @@ backend-llvm = [ "wasmer-runtime-core/backend-llvm", "wasmer-runtime/llvm", "wasmer-middleware-common-tests/llvm", + "wasmer-runtime-core-tests/backend-llvm", "wasmer-wasi-tests/llvm" ] backend-singlepass = [ @@ -98,6 +103,7 @@ backend-singlepass = [ "wasmer-runtime-core/backend-singlepass", "wasmer-runtime/singlepass", "wasmer-middleware-common-tests/singlepass", + "wasmer-runtime-core-tests/backend-singlepass", "wasmer-wasi-tests/singlepass" ] wasi = ["wasmer-wasi"] diff --git a/lib/middleware-common-tests/Cargo.toml b/lib/middleware-common-tests/Cargo.toml index 5eb36d959..d598f165c 100644 --- a/lib/middleware-common-tests/Cargo.toml +++ b/lib/middleware-common-tests/Cargo.toml @@ -10,12 +10,13 @@ publish = false [dependencies] wasmer-runtime-core = { path = "../runtime-core", version = "0.10.2" } wasmer-middleware-common = { path = "../middleware-common", version = "0.10.2" } -wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2" } +wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2", optional = true } wasmer-llvm-backend = { path = "../llvm-backend", version = "0.10.2", optional = true } wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.10.2", optional = true } [features] -clif = [] +default = ["clif"] +clif = ["wasmer-clif-backend"] llvm = ["wasmer-llvm-backend"] singlepass = ["wasmer-singlepass-backend"] diff --git a/lib/runtime-core-tests/Cargo.toml b/lib/runtime-core-tests/Cargo.toml index 0191d0e82..b71ed2bb0 100644 --- a/lib/runtime-core-tests/Cargo.toml +++ b/lib/runtime-core-tests/Cargo.toml @@ -15,7 +15,7 @@ wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.10.2" wasmer-llvm-backend = { path = "../llvm-backend", version = "0.10.2", optional = true } [features] -default = ["backend-cranelift"] +default = [] backend-cranelift = ["wasmer-clif-backend"] backend-singlepass = ["wasmer-singlepass-backend"] backend-llvm = ["wasmer-llvm-backend"] diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index 902ea37ac..8574d60a5 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -34,7 +34,7 @@ path = "../llvm-backend" optional = true [features] -default = ["cranelift", "default-backend-cranelift"] +default = ["cranelift"] cranelift = ["wasmer-clif-backend"] cache = ["cranelift"] debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] diff --git a/lib/runtime/build.rs b/lib/runtime/build.rs new file mode 100644 index 000000000..8f986c754 --- /dev/null +++ b/lib/runtime/build.rs @@ -0,0 +1,38 @@ +//! This build script sets the default compiler using special output. +//! +//! See https://doc.rust-lang.org/cargo/reference/build-scripts.html +//! for details. + +/// This function tells Cargo which default backend to use +fn set_default_backend() { + // we must use this rather than `cfg` because the build.rs executes on the + // compiling system. This method works with cross compilation too. + match std::env::var("CARGO_CFG_TARGET_ARCH") + .expect("compilation target env var") + .as_ref() + { + "x86_64" => { + println!("cargo:rustc-cfg=feature=\"default-backend-cranelift\""); + } + "aarch64" => { + println!("cargo:rustc-cfg=feature=\"default-backend-singlepass\""); + } + other => { + println!("cargo:warning=compiling for untested architecture: \"{}\"! Attempting to use LLVM", other); + println!("cargo:rustc-cfg=feature=\"default-backend-llvm\""); + } + } +} + +/// This function checks if the user specified a default backend +fn has_default_backend() -> bool { + std::env::var("CARGO_FEATURE_DEFAULT_BACKEND_SINGLEPASS").is_ok() + || std::env::var("CARGO_FEATURE_DEFAULT_BACKEND_CRANELIFT").is_ok() + || std::env::var("CARGO_FEATURE_DEFAULT_BACKEND_LLVM").is_ok() +} + +fn main() { + if !has_default_backend() { + set_default_backend(); + } +} From 2154ba2ce70715f3e1f6b686f6f9dfdbc65040a6 Mon Sep 17 00:00:00 2001 From: Asami Doi Date: Fri, 22 Nov 2019 11:15:26 +0900 Subject: [PATCH 04/10] Fix no rule to make target 'wasi' --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 277b8a069..f513663f5 100644 --- a/README.md +++ b/README.md @@ -235,7 +235,7 @@ Each integration can be tested separately: * Spec tests: `make spectests` * Emscripten: `make emtests` -* WASI: `make wasi` +* WASI: `make wasitests` * Middleware: `make middleware` * C API: `make capi` From bcdbdf4c23519b496c7ed1d5cebe96913d1508b5 Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 21 Nov 2019 13:53:56 -0800 Subject: [PATCH 05/10] Updated Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df85ffaa2..51c0983c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## **[Unreleased]** - [#995](https://github.com/wasmerio/wasmer/pull/995) Detect when a global is read without being initialized (emit a proper error instead of panicking) +- [#996](https://github.com/wasmerio/wasmer/pull/997) Refactored spectests, emtests and wasitests to use default compiler logic - [#992](https://github.com/wasmerio/wasmer/pull/992) Updates WAPM version to 0.4.1, fix arguments issue introduced in #990 - [#990](https://github.com/wasmerio/wasmer/pull/990) Default wasmer CLI to `run`. Wasmer will now attempt to parse unrecognized command line options as if they were applied to the run command: `wasmer mywasm.wasm --dir=.` now works! - [#987](https://github.com/wasmerio/wasmer/pull/987) Fix `runtime-c-api` header files when compiled by gnuc. From 7b9485320d472624f0282319fd930812d9bf2a73 Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 21 Nov 2019 18:26:31 -0800 Subject: [PATCH 06/10] Revert "Autodetect default backend, add features for architecture type" This reverts commit 31437a1e749f8c0b2154ccbb3a5365c0ab7cdbab. --- Cargo.lock | 1 - Cargo.toml | 8 +----- lib/middleware-common-tests/Cargo.toml | 5 ++-- lib/runtime-core-tests/Cargo.toml | 2 +- lib/runtime/Cargo.toml | 2 +- lib/runtime/build.rs | 38 -------------------------- 6 files changed, 5 insertions(+), 51 deletions(-) delete mode 100644 lib/runtime/build.rs diff --git a/Cargo.lock b/Cargo.lock index 9db253282..37410c356 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1353,7 +1353,6 @@ dependencies = [ "wasmer-middleware-common-tests 0.10.2", "wasmer-runtime 0.10.2", "wasmer-runtime-core 0.10.2", - "wasmer-runtime-core-tests 0.10.2", "wasmer-singlepass-backend 0.10.2", "wasmer-wasi 0.10.2", "wasmer-wasi-tests 0.10.2", diff --git a/Cargo.toml b/Cargo.toml index 86d7152e3..d3799f8e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,6 @@ wasmer-kernel-loader = { path = "lib/kernel-loader", optional = true } wasmer-dev-utils = { path = "lib/dev-utils", optional = true } wasmer-wasi-tests = { path = "lib/wasi-tests", optional = true } wasmer-middleware-common-tests = { path = "lib/middleware-common-tests", optional = true } -wasmer-runtime-core-tests = { path = "lib/runtime-core-tests", optional = true } wasmer-emscripten-tests = { path = "lib/emscripten-tests", optional = true } [workspace] @@ -74,10 +73,8 @@ serde = { version = "1", features = ["derive"] } # used by the plugin example typetag = "0.1" # used by the plugin example [features] -default = ["fast-tests", "wasi", "x86_64"] +default = ["fast-tests", "wasi", "backend-cranelift"] "loader-kernel" = ["wasmer-kernel-loader"] -aarch64 = ["backend-singlepass"] -x86_64 = ["backend-cranelift"] debug = ["wasmer-runtime-core/debug"] trace = ["wasmer-runtime-core/trace"] extra-debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] @@ -87,7 +84,6 @@ backend-cranelift = [ "wasmer-runtime-core/backend-cranelift", "wasmer-runtime/cranelift", "wasmer-middleware-common-tests/clif", - "wasmer-runtime-core-tests/backend-cranelift", "wasmer-wasi-tests/clif" ] backend-llvm = [ @@ -95,7 +91,6 @@ backend-llvm = [ "wasmer-runtime-core/backend-llvm", "wasmer-runtime/llvm", "wasmer-middleware-common-tests/llvm", - "wasmer-runtime-core-tests/backend-llvm", "wasmer-wasi-tests/llvm" ] backend-singlepass = [ @@ -103,7 +98,6 @@ backend-singlepass = [ "wasmer-runtime-core/backend-singlepass", "wasmer-runtime/singlepass", "wasmer-middleware-common-tests/singlepass", - "wasmer-runtime-core-tests/backend-singlepass", "wasmer-wasi-tests/singlepass" ] wasi = ["wasmer-wasi"] diff --git a/lib/middleware-common-tests/Cargo.toml b/lib/middleware-common-tests/Cargo.toml index d598f165c..5eb36d959 100644 --- a/lib/middleware-common-tests/Cargo.toml +++ b/lib/middleware-common-tests/Cargo.toml @@ -10,13 +10,12 @@ publish = false [dependencies] wasmer-runtime-core = { path = "../runtime-core", version = "0.10.2" } wasmer-middleware-common = { path = "../middleware-common", version = "0.10.2" } -wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2", optional = true } +wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2" } wasmer-llvm-backend = { path = "../llvm-backend", version = "0.10.2", optional = true } wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.10.2", optional = true } [features] -default = ["clif"] -clif = ["wasmer-clif-backend"] +clif = [] llvm = ["wasmer-llvm-backend"] singlepass = ["wasmer-singlepass-backend"] diff --git a/lib/runtime-core-tests/Cargo.toml b/lib/runtime-core-tests/Cargo.toml index b71ed2bb0..0191d0e82 100644 --- a/lib/runtime-core-tests/Cargo.toml +++ b/lib/runtime-core-tests/Cargo.toml @@ -15,7 +15,7 @@ wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.10.2" wasmer-llvm-backend = { path = "../llvm-backend", version = "0.10.2", optional = true } [features] -default = [] +default = ["backend-cranelift"] backend-cranelift = ["wasmer-clif-backend"] backend-singlepass = ["wasmer-singlepass-backend"] backend-llvm = ["wasmer-llvm-backend"] diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index 8574d60a5..902ea37ac 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -34,7 +34,7 @@ path = "../llvm-backend" optional = true [features] -default = ["cranelift"] +default = ["cranelift", "default-backend-cranelift"] cranelift = ["wasmer-clif-backend"] cache = ["cranelift"] debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] diff --git a/lib/runtime/build.rs b/lib/runtime/build.rs deleted file mode 100644 index 8f986c754..000000000 --- a/lib/runtime/build.rs +++ /dev/null @@ -1,38 +0,0 @@ -//! This build script sets the default compiler using special output. -//! -//! See https://doc.rust-lang.org/cargo/reference/build-scripts.html -//! for details. - -/// This function tells Cargo which default backend to use -fn set_default_backend() { - // we must use this rather than `cfg` because the build.rs executes on the - // compiling system. This method works with cross compilation too. - match std::env::var("CARGO_CFG_TARGET_ARCH") - .expect("compilation target env var") - .as_ref() - { - "x86_64" => { - println!("cargo:rustc-cfg=feature=\"default-backend-cranelift\""); - } - "aarch64" => { - println!("cargo:rustc-cfg=feature=\"default-backend-singlepass\""); - } - other => { - println!("cargo:warning=compiling for untested architecture: \"{}\"! Attempting to use LLVM", other); - println!("cargo:rustc-cfg=feature=\"default-backend-llvm\""); - } - } -} - -/// This function checks if the user specified a default backend -fn has_default_backend() -> bool { - std::env::var("CARGO_FEATURE_DEFAULT_BACKEND_SINGLEPASS").is_ok() - || std::env::var("CARGO_FEATURE_DEFAULT_BACKEND_CRANELIFT").is_ok() - || std::env::var("CARGO_FEATURE_DEFAULT_BACKEND_LLVM").is_ok() -} - -fn main() { - if !has_default_backend() { - set_default_backend(); - } -} From 9a146c57fc43a0ad7c5e9715eb5700ad54710e33 Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 21 Nov 2019 18:35:19 -0800 Subject: [PATCH 07/10] Make docs compilation happy --- Cargo.toml | 1 + Makefile | 2 +- lib/runtime/Cargo.toml | 1 + lib/runtime/src/lib.rs | 8 +++++--- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d3799f8e9..7f879ec1a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,6 +77,7 @@ default = ["fast-tests", "wasi", "backend-cranelift"] "loader-kernel" = ["wasmer-kernel-loader"] debug = ["wasmer-runtime-core/debug"] trace = ["wasmer-runtime-core/trace"] +docs = ["wasmer-runtime/docs"] extra-debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] # This feature will allow cargo test to run much faster fast-tests = [] diff --git a/Makefile b/Makefile index e8d11bed0..11980bdd4 100644 --- a/Makefile +++ b/Makefile @@ -265,4 +265,4 @@ dep-graph: cargo deps --optional-deps --filter wasmer-wasi wasmer-wasi-tests wasmer-kernel-loader wasmer-dev-utils wasmer-llvm-backend wasmer-emscripten wasmer-emscripten-tests wasmer-runtime-core wasmer-runtime wasmer-middleware-common wasmer-middleware-common-tests wasmer-singlepass-backend wasmer-clif-backend wasmer --manifest-path Cargo.toml | dot -Tpng > wasmer_depgraph.png docs: - cargo doc --features=backend-singlepass,backend-llvm,wasi,managed + cargo doc --features=backend-cranelift,backend-singlepass,backend-llvm,docs,wasi,managed diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index 902ea37ac..59392686f 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -35,6 +35,7 @@ optional = true [features] default = ["cranelift", "default-backend-cranelift"] +docs = [] cranelift = ["wasmer-clif-backend"] cache = ["cranelift"] debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] diff --git a/lib/runtime/src/lib.rs b/lib/runtime/src/lib.rs index 4d3bf4c4f..0f84a8194 100644 --- a/lib/runtime/src/lib.rs +++ b/lib/runtime/src/lib.rs @@ -208,12 +208,14 @@ pub fn default_compiler() -> impl Compiler { #[cfg(any( all( feature = "default-backend-llvm", + not(feature = "docs"), any( feature = "default-backend-cranelift", feature = "default-backend-singlepass" ) ), all( + not(feature = "docs"), feature = "default-backend-cranelift", feature = "default-backend-singlepass" ) @@ -222,13 +224,13 @@ pub fn default_compiler() -> impl Compiler { "The `default-backend-X` features are mutually exclusive. Please choose just one" ); - #[cfg(feature = "default-backend-llvm")] + #[cfg(all(feature = "default-backend-llvm", not(feature = "docs")))] use wasmer_llvm_backend::LLVMCompiler as DefaultCompiler; - #[cfg(feature = "default-backend-singlepass")] + #[cfg(all(feature = "default-backend-singlepass", not(feature = "docs")))] use wasmer_singlepass_backend::SinglePassCompiler as DefaultCompiler; - #[cfg(feature = "default-backend-cranelift")] + #[cfg(any(feature = "default-backend-singlepass", feature = "docs"))] use wasmer_clif_backend::CraneliftCompiler as DefaultCompiler; DefaultCompiler::new() From 27b6acdb16f85f45b8c03a05d1bafa0ee3da5101 Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 21 Nov 2019 18:55:38 -0800 Subject: [PATCH 08/10] Fixed typo --- lib/runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime/src/lib.rs b/lib/runtime/src/lib.rs index 0f84a8194..2ac6c1742 100644 --- a/lib/runtime/src/lib.rs +++ b/lib/runtime/src/lib.rs @@ -230,7 +230,7 @@ pub fn default_compiler() -> impl Compiler { #[cfg(all(feature = "default-backend-singlepass", not(feature = "docs")))] use wasmer_singlepass_backend::SinglePassCompiler as DefaultCompiler; - #[cfg(any(feature = "default-backend-singlepass", feature = "docs"))] + #[cfg(any(feature = "default-backend-cranelift", feature = "docs"))] use wasmer_clif_backend::CraneliftCompiler as DefaultCompiler; DefaultCompiler::new() From 499d42a759d97f5b44b5cffd452ec9e6548a0b35 Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 21 Nov 2019 19:08:48 -0800 Subject: [PATCH 09/10] Fixed tests --- Cargo.toml | 3 --- Makefile | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7f879ec1a..13369c452 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,21 +85,18 @@ backend-cranelift = [ "wasmer-runtime-core/backend-cranelift", "wasmer-runtime/cranelift", "wasmer-middleware-common-tests/clif", - "wasmer-wasi-tests/clif" ] backend-llvm = [ "wasmer-llvm-backend", "wasmer-runtime-core/backend-llvm", "wasmer-runtime/llvm", "wasmer-middleware-common-tests/llvm", - "wasmer-wasi-tests/llvm" ] backend-singlepass = [ "wasmer-singlepass-backend", "wasmer-runtime-core/backend-singlepass", "wasmer-runtime/singlepass", "wasmer-middleware-common-tests/singlepass", - "wasmer-wasi-tests/singlepass" ] wasi = ["wasmer-wasi"] managed = ["backend-singlepass", "wasmer-runtime-core/managed"] diff --git a/Makefile b/Makefile index 11980bdd4..ad8b762c3 100644 --- a/Makefile +++ b/Makefile @@ -220,13 +220,13 @@ check: check-bench # Release release: - cargo build --release --features backend-singlepass,backend-llvm,loader-kernel + cargo build --release --features backend-singlepass,backend-cranelift,backend-llvm,loader-kernel # Only one backend (cranelift) release-clif: # If you are on macOS, you will need mingw-w64 for cross compiling to Windows # brew install mingw-w64 - cargo build --release + cargo build --release --features backend-cranelift release-singlepass: cargo build --release --features backend-singlepass From 180528241d9586c40399cc5f5e10de5dcbd5c52d Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 21 Nov 2019 19:31:17 -0800 Subject: [PATCH 10/10] Fix merge issue in wasi tests --- lib/wasi-tests/tests/wasitests/_common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wasi-tests/tests/wasitests/_common.rs b/lib/wasi-tests/tests/wasitests/_common.rs index c5bc80c09..41bf14e44 100644 --- a/lib/wasi-tests/tests/wasitests/_common.rs +++ b/lib/wasi-tests/tests/wasitests/_common.rs @@ -1,7 +1,7 @@ macro_rules! assert_wasi_output { ($file:expr, $name:expr, $po_dir_args: expr, $mapdir_args:expr, $envvar_args:expr, $expected:expr) => {{ use wasmer_dev_utils::stdio::StdioCapturer; - use wasmer_runtime_core::Func; + use wasmer_runtime::Func; use wasmer_wasi::{generate_import_object_for_version, get_wasi_version}; let wasm_bytes = include_bytes!($file);