Simplify compiler test options

This commit is contained in:
Syrus
2019-11-21 13:36:44 -08:00
parent 5e728ae893
commit aeb66ee48e
13 changed files with 105 additions and 257 deletions

5
Cargo.lock generated
View File

@ -1436,7 +1436,7 @@ dependencies = [
"wasmer-dev-utils 0.10.2", "wasmer-dev-utils 0.10.2",
"wasmer-emscripten 0.10.2", "wasmer-emscripten 0.10.2",
"wasmer-llvm-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", "wasmer-singlepass-backend 0.10.2",
] ]
@ -1574,7 +1574,7 @@ dependencies = [
"wabt 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "wabt 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-clif-backend 0.10.2", "wasmer-clif-backend 0.10.2",
"wasmer-llvm-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", "wasmer-singlepass-backend 0.10.2",
] ]
@ -1604,7 +1604,6 @@ dependencies = [
"wasmer-dev-utils 0.10.2", "wasmer-dev-utils 0.10.2",
"wasmer-llvm-backend 0.10.2", "wasmer-llvm-backend 0.10.2",
"wasmer-runtime 0.10.2", "wasmer-runtime 0.10.2",
"wasmer-runtime-core 0.10.2",
"wasmer-singlepass-backend 0.10.2", "wasmer-singlepass-backend 0.10.2",
"wasmer-wasi 0.10.2", "wasmer-wasi 0.10.2",
] ]

View File

@ -10,8 +10,8 @@ build = "build/mod.rs"
[dependencies] [dependencies]
wasmer-emscripten = { path = "../emscripten", version = "0.10.2" } wasmer-emscripten = { path = "../emscripten", version = "0.10.2" }
wasmer-runtime-core = { path = "../runtime-core", 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" } 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-llvm-backend = { path = "../llvm-backend", version = "0.10.2", optional = true }
wasmer-singlepass-backend = { path = "../singlepass-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" glob = "0.3"
[features] [features]
clif = [] clif = ["wasmer-clif-backend", "wasmer-runtime/default-backend-cranelift"]
llvm = ["wasmer-llvm-backend"] singlepass = ["wasmer-singlepass-backend", "wasmer-runtime/default-backend-singlepass"]
singlepass = ["wasmer-singlepass-backend"] llvm = ["wasmer-llvm-backend", "wasmer-runtime/default-backend-llvm"]

View File

@ -3,40 +3,14 @@ mod tests {
use std::sync::Arc; use std::sync::Arc;
use wabt::wat2wasm; use wabt::wat2wasm;
use wasmer_emscripten::is_emscripten_module; use wasmer_emscripten::is_emscripten_module;
use wasmer_runtime_core::backend::Compiler; use wasmer_runtime::compile;
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()
}
#[test] #[test]
fn should_detect_emscripten_files() { fn should_detect_emscripten_files() {
const WAST_BYTES: &[u8] = include_bytes!("tests/is_emscripten_true.wast"); 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 wasm_binary = wat2wasm(WAST_BYTES.to_vec()).expect("Can't convert to wasm");
let module = 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); let module = Arc::new(module);
assert!(is_emscripten_module(&module)); assert!(is_emscripten_module(&module));
} }
@ -46,7 +20,7 @@ mod tests {
const WAST_BYTES: &[u8] = include_bytes!("tests/is_emscripten_false.wast"); 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 wasm_binary = wat2wasm(WAST_BYTES.to_vec()).expect("Can't convert to wasm");
let module = 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); let module = Arc::new(module);
assert!(!is_emscripten_module(&module)); assert!(!is_emscripten_module(&module));
} }

View File

@ -5,39 +5,12 @@ macro_rules! assert_emscripten_output {
EmscriptenGlobals, EmscriptenGlobals,
generate_emscripten_env, generate_emscripten_env,
}; };
use wasmer_runtime_core::{ use wasmer_runtime::compile;
backend::Compiler,
};
use wasmer_dev_utils::stdio::StdioCapturer; 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 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"); .expect("WASM can't be compiled");
// let module = compile(&wasm_bytes[..]) // let module = compile(&wasm_bytes[..])

View File

@ -87,11 +87,11 @@
//! [`wasmer-clif-backend`]: https://crates.io/crates/wasmer-clif-backend //! [`wasmer-clif-backend`]: https://crates.io/crates/wasmer-clif-backend
//! [`compile_with`]: fn.compile_with.html //! [`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::codegen::{MiddlewareChain, StreamingCompiler};
pub use wasmer_runtime_core::export::Export; pub use wasmer_runtime_core::export::Export;
pub use wasmer_runtime_core::global::Global; 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::instance::{DynFunc, Instance};
pub use wasmer_runtime_core::memory::ptr::{Array, Item, WasmPtr}; pub use wasmer_runtime_core::memory::ptr::{Array, Item, WasmPtr};
pub use wasmer_runtime_core::memory::Memory; pub use wasmer_runtime_core::memory::Memory;
@ -131,9 +131,14 @@ pub mod units {
pub use wasmer_runtime_core::units::{Bytes, Pages}; pub use wasmer_runtime_core::units::{Bytes, Pages};
} }
pub mod types {
//! Various types.
pub use wasmer_runtime_core::types::*;
}
pub mod cache; 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`]. /// Compile WebAssembly binary code into a [`Module`].
/// This function is useful if it is necessary to /// This function is useful if it is necessary to

View File

@ -9,8 +9,8 @@ edition = "2018"
[dependencies] [dependencies]
glob = "0.3" glob = "0.3"
wasmer-runtime-core = { path = "../runtime-core", 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" } 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-llvm-backend = { path = "../llvm-backend", version = "0.10.2", optional = true }
wasmer-singlepass-backend = { path = "../singlepass-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] [features]
default = ["fast-tests"] default = ["fast-tests"]
fast-tests = [] fast-tests = []
clif = [] clif = ["wasmer-clif-backend", "wasmer-runtime/default-backend-cranelift"]
llvm = ["wasmer-llvm-backend"] singlepass = ["wasmer-singlepass-backend", "wasmer-runtime/default-backend-singlepass"]
singlepass = ["wasmer-singlepass-backend"] llvm = ["wasmer-llvm-backend", "wasmer-runtime/default-backend-llvm"]

View File

@ -1,46 +1,23 @@
use wabt::wat2wasm; use wabt::wat2wasm;
use wasmer_runtime_core::{ use wasmer_runtime::{
backend::Compiler,
error, error,
global::Global, func,
memory::Memory, Global,
prelude::*, Memory,
table::Table, imports,
compile,
Table,
Ctx,
types::{ElementType, MemoryDescriptor, TableDescriptor, Value}, types::{ElementType, MemoryDescriptor, TableDescriptor, Value},
units::Pages, 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"); static EXAMPLE_WASM: &'static [u8] = include_bytes!("simple.wasm");
fn main() -> error::Result<()> { fn main() -> error::Result<()> {
let wasm_binary = wat2wasm(IMPORT_MODULE.as_bytes()).expect("WAST not valid or malformed"); 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_desc = MemoryDescriptor::new(Pages(1), Some(Pages(1)), false).unwrap();
let memory = Memory::new(memory_desc).unwrap(); let memory = Memory::new(memory_desc).unwrap();
@ -71,7 +48,7 @@ fn main() -> error::Result<()> {
"env" => inner_instance, "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 outer_instance = outer_module.instantiate(&outer_imports)?;
let ret = outer_instance.call("main", &[Value::I32(42)])?; let ret = outer_instance.call("main", &[Value::I32(42)])?;
println!("ret: {:?}", ret); println!("ret: {:?}", ret);
@ -79,7 +56,7 @@ fn main() -> error::Result<()> {
Ok(()) Ok(())
} }
fn print_num(ctx: &mut vm::Ctx, n: i32) -> Result<i32, ()> { fn print_num(ctx: &mut Ctx, n: i32) -> Result<i32, ()> {
println!("print_num({})", n); println!("print_num({})", n);
let memory: &Memory = ctx.memory(0); let memory: &Memory = ctx.memory(0);

View File

@ -1,5 +1,5 @@
use wabt::wat2wasm; use wabt::wat2wasm;
use wasmer_runtime_core::{backend::Compiler, import::ImportObject, Instance}; use wasmer_runtime::{ImportObject, Instance, compile};
fn main() { fn main() {
let instance = create_module_1(); let instance = create_module_1();
@ -23,38 +23,13 @@ fn create_module_1() -> Instance {
(elem (;1;) (i32.const 9) 1)) (elem (;1;) (i32.const 9) 1))
"#; "#;
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); 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"); .expect("WASM can't be compiled");
module module
.instantiate(&generate_imports()) .instantiate(&generate_imports())
.expect("WASM can't be instantiated") .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#" static IMPORT_MODULE: &str = r#"
(module (module
(type $t0 (func (param i32))) (type $t0 (func (param i32)))
@ -68,7 +43,7 @@ static IMPORT_MODULE: &str = r#"
pub fn generate_imports() -> ImportObject { pub fn generate_imports() -> ImportObject {
let wasm_binary = wat2wasm(IMPORT_MODULE.as_bytes()).expect("WAST not valid or malformed"); 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"); .expect("WASM can't be compiled");
let instance = module let instance = module
.instantiate(&ImportObject::new()) .instantiate(&ImportObject::new())

View File

@ -1,10 +1,9 @@
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use wabt::wat2wasm; use wabt::wat2wasm;
use wasmer_clif_backend::CraneliftCompiler; use wasmer_runtime::{
use wasmer_runtime_core::{
error::{CallError, RuntimeError}, error::{CallError, RuntimeError},
import::ImportObject, ImportObject,
}; };
// The semantics of stack overflow are documented at: // The semantics of stack overflow are documented at:
@ -22,7 +21,7 @@ mod tests {
(elem (;0;) (i32.const 0) 0)) (elem (;0;) (i32.const 0) 0))
"#; "#;
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); 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"); .expect("WASM can't be compiled");
let instance = module let instance = module
.instantiate(&ImportObject::new()) .instantiate(&ImportObject::new())

View File

@ -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")] #[cfg(feature = "clif")]
fn get_compiler_name() -> &'static str { fn get_compiler_name() -> &'static str {
"clif" "clif"
@ -241,20 +216,23 @@ mod tests {
use std::panic::AssertUnwindSafe; use std::panic::AssertUnwindSafe;
use std::path::PathBuf; use std::path::PathBuf;
use wabt::script::{Action, Command, CommandKind, ScriptParser, Value}; use wabt::script::{Action, Command, CommandKind, ScriptParser, Value};
use wasmer_runtime_core::backend::{Compiler, CompilerConfig, Features}; use wasmer_runtime::{
use wasmer_runtime_core::error::CompileError; CompilerConfig,
use wasmer_runtime_core::import::ImportObject; ImportObject,
use wasmer_runtime_core::Instance; LikeNamespace,
use wasmer_runtime_core::{ Instance,
export::Export, error::{CompileError},
global::Global, Export,
import::LikeNamespace, Global,
memory::Memory, Memory,
table::Table, Table,
types::{ElementType, MemoryDescriptor, TableDescriptor}, types::{ElementType, MemoryDescriptor, TableDescriptor},
units::Pages, units::Pages,
Features,
func, imports, Ctx,
compile_with_config,
}; };
use wasmer_runtime_core::{func, imports, vm::Ctx};
fn parse_and_run( fn parse_and_run(
path: &PathBuf, path: &PathBuf,
@ -328,9 +306,8 @@ mod tests {
}, },
..Default::default() ..Default::default()
}; };
let module = wasmer_runtime_core::compile_with_config( let module = compile_with_config(
&module.into_vec(), &module.into_vec(),
&get_compiler(),
config, config,
) )
.expect("WASM can't be compiled"); .expect("WASM can't be compiled");
@ -375,7 +352,7 @@ mod tests {
&named_modules, &named_modules,
&module, &module,
|instance| { |instance| {
let params: Vec<wasmer_runtime_core::types::Value> = let params: Vec<wasmer_runtime::types::Value> =
args.iter().cloned().map(convert_value).collect(); args.iter().cloned().map(convert_value).collect();
instance.call(&field, &params[..]) instance.call(&field, &params[..])
}, },
@ -507,7 +484,7 @@ mod tests {
} => { } => {
let maybe_call_result = let maybe_call_result =
with_instance(instance.clone(), &named_modules, &module, |instance| { with_instance(instance.clone(), &named_modules, &module, |instance| {
let params: Vec<wasmer_runtime_core::types::Value> = let params: Vec<wasmer_runtime::types::Value> =
args.iter().cloned().map(convert_value).collect(); args.iter().cloned().map(convert_value).collect();
instance.call(&field, &params[..]) instance.call(&field, &params[..])
}); });
@ -578,7 +555,7 @@ mod tests {
} => { } => {
let maybe_call_result = let maybe_call_result =
with_instance(instance.clone(), &named_modules, &module, |instance| { with_instance(instance.clone(), &named_modules, &module, |instance| {
let params: Vec<wasmer_runtime_core::types::Value> = let params: Vec<wasmer_runtime::types::Value> =
args.iter().cloned().map(convert_value).collect(); args.iter().cloned().map(convert_value).collect();
instance.call(&field, &params[..]) instance.call(&field, &params[..])
}); });
@ -649,7 +626,7 @@ mod tests {
} => { } => {
let maybe_call_result = let maybe_call_result =
with_instance(instance.clone(), &named_modules, &module, |instance| { with_instance(instance.clone(), &named_modules, &module, |instance| {
let params: Vec<wasmer_runtime_core::types::Value> = let params: Vec<wasmer_runtime::types::Value> =
args.iter().cloned().map(convert_value).collect(); args.iter().cloned().map(convert_value).collect();
instance.call(&field, &params[..]) instance.call(&field, &params[..])
}); });
@ -667,7 +644,7 @@ mod tests {
); );
} else { } else {
let call_result = maybe_call_result.unwrap(); let call_result = maybe_call_result.unwrap();
use wasmer_runtime_core::error::{CallError, RuntimeError}; use wasmer_runtime::error::{CallError, RuntimeError};
match call_result { match call_result {
Err(e) => { Err(e) => {
match e { match e {
@ -738,9 +715,8 @@ mod tests {
}, },
..Default::default() ..Default::default()
}; };
wasmer_runtime_core::compile_with_config( compile_with_config(
&module.into_vec(), &module.into_vec(),
&get_compiler(),
config, config,
) )
}); });
@ -794,9 +770,8 @@ mod tests {
}, },
..Default::default() ..Default::default()
}; };
wasmer_runtime_core::compile_with_config( compile_with_config(
&module.into_vec(), &module.into_vec(),
&get_compiler(),
config, config,
) )
}); });
@ -849,9 +824,8 @@ mod tests {
}, },
..Default::default() ..Default::default()
}; };
let module = wasmer_runtime_core::compile_with_config( let module = compile_with_config(
&module.into_vec(), &module.into_vec(),
&get_compiler(),
config, config,
) )
.expect("WASM can't be compiled"); .expect("WASM can't be compiled");
@ -891,7 +865,7 @@ mod tests {
&named_modules, &named_modules,
&module, &module,
|instance| { |instance| {
let params: Vec<wasmer_runtime_core::types::Value> = let params: Vec<wasmer_runtime::types::Value> =
args.iter().cloned().map(convert_value).collect(); args.iter().cloned().map(convert_value).collect();
instance.call(&field, &params[..]) instance.call(&field, &params[..])
}, },
@ -948,9 +922,8 @@ mod tests {
}, },
..Default::default() ..Default::default()
}; };
let module = wasmer_runtime_core::compile_with_config( let module = compile_with_config(
&module.into_vec(), &module.into_vec(),
&get_compiler(),
config, config,
) )
.expect("WASM can't be compiled"); .expect("WASM can't be compiled");
@ -987,7 +960,7 @@ mod tests {
); );
} }
Err(e) => match e { Err(e) => match e {
wasmer_runtime_core::error::Error::LinkError(_) => { wasmer_runtime::error::Error::LinkError(_) => {
test_report.count_passed(); test_report.count_passed();
} }
_ => { _ => {
@ -1046,7 +1019,7 @@ mod tests {
} => { } => {
let maybe_call_result = let maybe_call_result =
with_instance(instance.clone(), &named_modules, &module, |instance| { with_instance(instance.clone(), &named_modules, &module, |instance| {
let params: Vec<wasmer_runtime_core::types::Value> = let params: Vec<wasmer_runtime::types::Value> =
args.iter().cloned().map(convert_value).collect(); args.iter().cloned().map(convert_value).collect();
instance.call(&field, &params[..]) instance.call(&field, &params[..])
}); });
@ -1094,29 +1067,29 @@ mod tests {
Ok(test_report) 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 { match val {
wasmer_runtime_core::types::Value::F32(x) => x.is_canonical_nan(), wasmer_runtime::types::Value::F32(x) => x.is_canonical_nan(),
wasmer_runtime_core::types::Value::F64(x) => x.is_canonical_nan(), wasmer_runtime::types::Value::F64(x) => x.is_canonical_nan(),
_ => panic!("value is not a float {:?}", val), _ => 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 { match val {
wasmer_runtime_core::types::Value::F32(x) => x.is_quiet_nan(), wasmer_runtime::types::Value::F32(x) => x.is_quiet_nan(),
wasmer_runtime_core::types::Value::F64(x) => x.is_quiet_nan(), wasmer_runtime::types::Value::F64(x) => x.is_quiet_nan(),
_ => panic!("value is not a float {:?}", val), _ => 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 { match val {
wasmer_runtime_core::types::Value::I32(x) => format!("{:#x}", x), wasmer_runtime::types::Value::I32(x) => format!("{:#x}", x),
wasmer_runtime_core::types::Value::I64(x) => format!("{:#x}", x), wasmer_runtime::types::Value::I64(x) => format!("{:#x}", x),
wasmer_runtime_core::types::Value::F32(x) => format!("{:#x}", x.to_bits()), wasmer_runtime::types::Value::F32(x) => format!("{:#x}", x.to_bits()),
wasmer_runtime_core::types::Value::F64(x) => format!("{:#x}", x.to_bits()), wasmer_runtime::types::Value::F64(x) => format!("{:#x}", x.to_bits()),
wasmer_runtime_core::types::Value::V128(x) => format!("{:#x}", x), wasmer_runtime::types::Value::V128(x) => format!("{:#x}", x),
} }
} }
@ -1129,13 +1102,13 @@ mod tests {
V128(u128), 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 { match other {
wasmer_runtime_core::types::Value::I32(v) => SpectestValue::I32(v), wasmer_runtime::types::Value::I32(v) => SpectestValue::I32(v),
wasmer_runtime_core::types::Value::I64(v) => SpectestValue::I64(v), wasmer_runtime::types::Value::I64(v) => SpectestValue::I64(v),
wasmer_runtime_core::types::Value::F32(v) => SpectestValue::F32(v.to_bits()), wasmer_runtime::types::Value::F32(v) => SpectestValue::F32(v.to_bits()),
wasmer_runtime_core::types::Value::F64(v) => SpectestValue::F64(v.to_bits()), wasmer_runtime::types::Value::F64(v) => SpectestValue::F64(v.to_bits()),
wasmer_runtime_core::types::Value::V128(v) => SpectestValue::V128(v), wasmer_runtime::types::Value::V128(v) => SpectestValue::V128(v),
} }
} }
@ -1149,13 +1122,13 @@ mod tests {
} }
} }
fn convert_value(other: Value<f32, f64>) -> wasmer_runtime_core::types::Value { fn convert_value(other: Value<f32, f64>) -> wasmer_runtime::types::Value {
match other { match other {
Value::I32(v) => wasmer_runtime_core::types::Value::I32(v), Value::I32(v) => wasmer_runtime::types::Value::I32(v),
Value::I64(v) => wasmer_runtime_core::types::Value::I64(v), Value::I64(v) => wasmer_runtime::types::Value::I64(v),
Value::F32(v) => wasmer_runtime_core::types::Value::F32(v), Value::F32(v) => wasmer_runtime::types::Value::F32(v),
Value::F64(v) => wasmer_runtime_core::types::Value::F64(v), Value::F64(v) => wasmer_runtime::types::Value::F64(v),
Value::V128(v) => wasmer_runtime_core::types::Value::V128(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_desc = MemoryDescriptor::new(Pages(1), Some(Pages(2)), false).unwrap();
let memory = Memory::new(memory_desc).unwrap(); let memory = Memory::new(memory_desc).unwrap();
let global_i32 = Global::new(wasmer_runtime_core::types::Value::I32(666)); let global_i32 = Global::new(wasmer_runtime::types::Value::I32(666));
let global_f32 = Global::new(wasmer_runtime_core::types::Value::F32(666.0)); let global_f32 = Global::new(wasmer_runtime::types::Value::F32(666.0));
let global_f64 = Global::new(wasmer_runtime_core::types::Value::F64(666.0)); let global_f64 = Global::new(wasmer_runtime::types::Value::F64(666.0));
let table = Table::new(TableDescriptor { let table = Table::new(TableDescriptor {
element: ElementType::Anyfunc, element: ElementType::Anyfunc,

View File

@ -9,22 +9,21 @@ publish = false
build = "build/mod.rs" build = "build/mod.rs"
[dependencies] [dependencies]
wasmer-runtime-core = { path = "../runtime-core", 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" } wasmer-runtime = { path = "../runtime", version = "0.10.2", default-features = false }
wasmer-wasi = { path = "../wasi", version = "0.10.2" } wasmer-wasi = { path = "../wasi", version = "0.10.2" }
# hack to get tests to work # 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-singlepass-backend = { path = "../singlepass-backend", version = "0.10.2", optional = true }
wasmer-llvm-backend = { path = "../llvm-backend", version = "0.10.2", optional = true } wasmer-llvm-backend = { path = "../llvm-backend", version = "0.10.2", optional = true }
[build-dependencies] [build-dependencies]
glob = "0.3" glob = "0.3"
[dev-dependencies] [dev-dependencies]
wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2" }
wasmer-dev-utils = { path = "../dev-utils", version = "0.10.2"} wasmer-dev-utils = { path = "../dev-utils", version = "0.10.2"}
[features] [features]
clif = [] clif = ["wasmer-clif-backend", "wasmer-runtime/default-backend-cranelift"]
singlepass = ["wasmer-singlepass-backend"] singlepass = ["wasmer-singlepass-backend", "wasmer-runtime/default-backend-singlepass"]
llvm = ["wasmer-llvm-backend"] llvm = ["wasmer-llvm-backend", "wasmer-runtime/default-backend-llvm"]

View File

@ -1,6 +1,5 @@
#![cfg(test)] #![cfg(test)]
use wasmer_runtime::{compile, Func}; use wasmer_runtime::{compile, Func, Ctx};
use wasmer_runtime_core::vm::Ctx;
use wasmer_wasi::{state::*, *}; use wasmer_wasi::{state::*, *};
use std::ffi::c_void; use std::ffi::c_void;

View File

@ -1,36 +1,11 @@
macro_rules! assert_wasi_output { macro_rules! assert_wasi_output {
($file:expr, $name:expr, $po_dir_args: expr, $mapdir_args:expr, $envvar_args:expr, $expected:expr) => {{ ($file:expr, $name:expr, $po_dir_args: expr, $mapdir_args:expr, $envvar_args:expr, $expected:expr) => {{
use wasmer_dev_utils::stdio::StdioCapturer; use wasmer_dev_utils::stdio::StdioCapturer;
use wasmer_runtime_core::{backend::Compiler, Func}; use wasmer_runtime::Func;
use wasmer_wasi::generate_import_object; 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 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"); .expect("WASM can't be compiled");
let import_object = generate_import_object(vec![], vec![], $po_dir_args, $mapdir_args); let import_object = generate_import_object(vec![], vec![], $po_dir_args, $mapdir_args);