997: Compiler tests r=MarkMcCaskey a=syrusakbary

# Description
This PR simplifies the testing part, making `wasmer_runtime_core` the one responsible for picking the default backend.

This makes tests much simpler, and reliable when trying to run in different backends (this PR solves an issue when trying to run wasitests on ARM machines).

<!-- 
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->

# Review

- [x] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Syrus <me@syrusakbary.com>
Co-authored-by: Mark McCaskey <mark@wasmer.io>
Co-authored-by: Mark McCaskey <5770194+markmccaskey@users.noreply.github.com>
This commit is contained in:
bors[bot] 2019-11-22 03:32:27 +00:00 committed by GitHub
commit 7bb570a7f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 106 additions and 290 deletions

View File

@ -3,6 +3,7 @@
## **[Unreleased]** ## **[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) - [#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 - [#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! - [#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. - [#987](https://github.com/wasmerio/wasmer/pull/987) Fix `runtime-c-api` header files when compiled by gnuc.

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

@ -77,6 +77,7 @@ default = ["fast-tests", "wasi", "backend-cranelift"]
"loader-kernel" = ["wasmer-kernel-loader"] "loader-kernel" = ["wasmer-kernel-loader"]
debug = ["wasmer-runtime-core/debug"] debug = ["wasmer-runtime-core/debug"]
trace = ["wasmer-runtime-core/trace"] trace = ["wasmer-runtime-core/trace"]
docs = ["wasmer-runtime/docs"]
extra-debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] extra-debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"]
# This feature will allow cargo test to run much faster # This feature will allow cargo test to run much faster
fast-tests = [] fast-tests = []
@ -84,21 +85,18 @@ backend-cranelift = [
"wasmer-runtime-core/backend-cranelift", "wasmer-runtime-core/backend-cranelift",
"wasmer-runtime/cranelift", "wasmer-runtime/cranelift",
"wasmer-middleware-common-tests/clif", "wasmer-middleware-common-tests/clif",
"wasmer-wasi-tests/clif"
] ]
backend-llvm = [ backend-llvm = [
"wasmer-llvm-backend", "wasmer-llvm-backend",
"wasmer-runtime-core/backend-llvm", "wasmer-runtime-core/backend-llvm",
"wasmer-runtime/llvm", "wasmer-runtime/llvm",
"wasmer-middleware-common-tests/llvm", "wasmer-middleware-common-tests/llvm",
"wasmer-wasi-tests/llvm"
] ]
backend-singlepass = [ backend-singlepass = [
"wasmer-singlepass-backend", "wasmer-singlepass-backend",
"wasmer-runtime-core/backend-singlepass", "wasmer-runtime-core/backend-singlepass",
"wasmer-runtime/singlepass", "wasmer-runtime/singlepass",
"wasmer-middleware-common-tests/singlepass", "wasmer-middleware-common-tests/singlepass",
"wasmer-wasi-tests/singlepass"
] ]
wasi = ["wasmer-wasi"] wasi = ["wasmer-wasi"]
managed = ["backend-singlepass", "wasmer-runtime-core/managed"] managed = ["backend-singlepass", "wasmer-runtime-core/managed"]

View File

@ -220,13 +220,13 @@ check: check-bench
# Release # Release
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) # Only one backend (cranelift)
release-clif: release-clif:
# If you are on macOS, you will need mingw-w64 for cross compiling to Windows # If you are on macOS, you will need mingw-w64 for cross compiling to Windows
# brew install mingw-w64 # brew install mingw-w64
cargo build --release cargo build --release --features backend-cranelift
release-singlepass: release-singlepass:
cargo build --release --features backend-singlepass cargo build --release --features backend-singlepass
@ -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 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: docs:
cargo doc --features=backend-singlepass,backend-llvm,wasi,managed cargo doc --features=backend-cranelift,backend-singlepass,backend-llvm,docs,wasi,managed

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,13 @@ 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(&wasm_binary[..]).expect("WASM can't be compiled");
compile_with(&wasm_binary[..], &get_compiler()).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));
} }
@ -45,8 +18,7 @@ mod tests {
fn should_detect_non_emscripten_files() { fn should_detect_non_emscripten_files() {
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(&wasm_binary[..]).expect("WASM can't be compiled");
compile_with(&wasm_binary[..], &get_compiler()).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

@ -35,6 +35,7 @@ optional = true
[features] [features]
default = ["cranelift", "default-backend-cranelift"] default = ["cranelift", "default-backend-cranelift"]
docs = []
cranelift = ["wasmer-clif-backend"] cranelift = ["wasmer-clif-backend"]
cache = ["cranelift"] cache = ["cranelift"]
debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"]

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
@ -203,12 +208,14 @@ pub fn default_compiler() -> impl Compiler {
#[cfg(any( #[cfg(any(
all( all(
feature = "default-backend-llvm", feature = "default-backend-llvm",
not(feature = "docs"),
any( any(
feature = "default-backend-cranelift", feature = "default-backend-cranelift",
feature = "default-backend-singlepass" feature = "default-backend-singlepass"
) )
), ),
all( all(
not(feature = "docs"),
feature = "default-backend-cranelift", feature = "default-backend-cranelift",
feature = "default-backend-singlepass" feature = "default-backend-singlepass"
) )
@ -217,13 +224,13 @@ pub fn default_compiler() -> impl Compiler {
"The `default-backend-X` features are mutually exclusive. Please choose just one" "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; 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; use wasmer_singlepass_backend::SinglePassCompiler as DefaultCompiler;
#[cfg(feature = "default-backend-cranelift")] #[cfg(any(feature = "default-backend-cranelift", feature = "docs"))]
use wasmer_clif_backend::CraneliftCompiler as DefaultCompiler; use wasmer_clif_backend::CraneliftCompiler as DefaultCompiler;
DefaultCompiler::new() DefaultCompiler::new()

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,17 @@
use wabt::wat2wasm; use wabt::wat2wasm;
use wasmer_runtime_core::{ use wasmer_runtime::{
backend::Compiler, compile, error, func, imports,
error,
global::Global,
memory::Memory,
prelude::*,
table::Table,
types::{ElementType, MemoryDescriptor, TableDescriptor, Value}, types::{ElementType, MemoryDescriptor, TableDescriptor, Value},
units::Pages, units::Pages,
Ctx, Global, Memory, Table,
}; };
#[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 +42,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 +50,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::{compile, ImportObject, Instance};
fn main() { fn main() {
let instance = create_module_1(); let instance = create_module_1();
@ -23,38 +23,12 @@ 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,8 +42,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())
.expect("WASM can't be instantiated"); .expect("WASM can't be instantiated");

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,8 +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())
.expect("WASM can't be instantiated"); .expect("WASM can't be instantiated");

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,15 @@ 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; compile_with_config,
use wasmer_runtime_core::import::ImportObject; error::CompileError,
use wasmer_runtime_core::Instance; func, imports,
use wasmer_runtime_core::{
export::Export,
global::Global,
import::LikeNamespace,
memory::Memory,
table::Table,
types::{ElementType, MemoryDescriptor, TableDescriptor}, types::{ElementType, MemoryDescriptor, TableDescriptor},
units::Pages, units::Pages,
CompilerConfig, Ctx, Export, Features, Global, ImportObject, Instance, LikeNamespace,
Memory, Table,
}; };
use wasmer_runtime_core::{func, imports, vm::Ctx};
fn parse_and_run( fn parse_and_run(
path: &PathBuf, path: &PathBuf,
@ -328,11 +298,7 @@ mod tests {
}, },
..Default::default() ..Default::default()
}; };
let module = wasmer_runtime_core::compile_with_config( let module = compile_with_config(&module.into_vec(), config)
&module.into_vec(),
&get_compiler(),
config,
)
.expect("WASM can't be compiled"); .expect("WASM can't be compiled");
let i = module let i = module
.instantiate(&spectest_import_object) .instantiate(&spectest_import_object)
@ -375,7 +341,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 +473,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 +544,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 +615,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 +633,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,11 +704,7 @@ mod tests {
}, },
..Default::default() ..Default::default()
}; };
wasmer_runtime_core::compile_with_config( compile_with_config(&module.into_vec(), config)
&module.into_vec(),
&get_compiler(),
config,
)
}); });
match result { match result {
Ok(module) => { Ok(module) => {
@ -794,11 +756,7 @@ mod tests {
}, },
..Default::default() ..Default::default()
}; };
wasmer_runtime_core::compile_with_config( compile_with_config(&module.into_vec(), config)
&module.into_vec(),
&get_compiler(),
config,
)
}); });
match result { match result {
@ -849,11 +807,7 @@ mod tests {
}, },
..Default::default() ..Default::default()
}; };
let module = wasmer_runtime_core::compile_with_config( let module = compile_with_config(&module.into_vec(), config)
&module.into_vec(),
&get_compiler(),
config,
)
.expect("WASM can't be compiled"); .expect("WASM can't be compiled");
let result = panic::catch_unwind(AssertUnwindSafe(|| { let result = panic::catch_unwind(AssertUnwindSafe(|| {
module module
@ -891,7 +845,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,11 +902,7 @@ mod tests {
}, },
..Default::default() ..Default::default()
}; };
let module = wasmer_runtime_core::compile_with_config( let module = compile_with_config(&module.into_vec(), config)
&module.into_vec(),
&get_compiler(),
config,
)
.expect("WASM can't be compiled"); .expect("WASM can't be compiled");
module.instantiate(&spectest_import_object) module.instantiate(&spectest_import_object)
})); }));
@ -987,7 +937,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 +996,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 +1044,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 +1079,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 +1099,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 +1149,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, Ctx, Func};
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,37 +1,12 @@
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_for_version, get_wasi_version}; use wasmer_wasi::{generate_import_object_for_version, get_wasi_version};
#[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 wasi_version = get_wasi_version(&module).expect("WASI module"); let wasi_version = get_wasi_version(&module).expect("WASI module");