Library restructure (#104)

* Move wasmer-runtime to wasmer-runtime-core

* Add the runtime library

* Fix issue with macros using wasmer_runtime, fmt

* Make default compiler dependency optional

* Add instantiate and validate functions
This commit is contained in:
Brandon Fish 2019-01-22 13:02:06 -06:00 committed by Lachlan Sneff
parent 62b8e7cc2d
commit 74875ed554
129 changed files with 218 additions and 130 deletions

14
Cargo.lock generated
View File

@ -1100,6 +1100,7 @@ dependencies = [
"wasmer-clif-backend 0.1.0",
"wasmer-emscripten 0.1.1",
"wasmer-runtime 0.1.0",
"wasmer-runtime-core 0.1.0",
"wasmparser 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1117,7 +1118,7 @@ dependencies = [
"libffi 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"nix 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-runtime 0.1.0",
"wasmer-runtime-core 0.1.0",
"wasmparser 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1132,12 +1133,20 @@ dependencies = [
"time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
"wabt 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-clif-backend 0.1.0",
"wasmer-runtime 0.1.0",
"wasmer-runtime-core 0.1.0",
]
[[package]]
name = "wasmer-runtime"
version = "0.1.0"
dependencies = [
"wasmer-clif-backend 0.1.0",
"wasmer-runtime-core 0.1.0",
]
[[package]]
name = "wasmer-runtime-core"
version = "0.1.0"
dependencies = [
"errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"field-offset 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1146,6 +1155,7 @@ dependencies = [
"page_size 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"wabt 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-clif-backend 0.1.0",
"wasmparser 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]

View File

@ -52,11 +52,12 @@ libffi = "0.6.4"
time = "0.1.41"
wasmer-clif-backend = { path = "lib/clif-backend" }
wasmer-runtime = { path = "lib/runtime" }
wasmer-runtime-core = { path = "lib/runtime-core" }
wasmer-emscripten = { path = "lib/emscripten" }
libc = { git = "https://github.com/rust-lang/libc" }
[workspace]
members = ["lib/clif-backend", "lib/runtime", "lib/emscripten"]
members = ["lib/clif-backend", "lib/runtime", "lib/runtime-core", "lib/emscripten"]
[build-dependencies]
wabt = "0.7.2"

View File

@ -7,7 +7,7 @@ endif
# This will re-generate the Rust test files based on spectests/*.wast
spectests:
WASMER_RUNTIME_GENERATE_SPECTESTS=1 cargo build -p wasmer-runtime
WASMER_RUNTIME_GENERATE_SPECTESTS=1 cargo build -p wasmer-runtime-core
emtests:
WASM_EMSCRIPTEN_GENERATE_EMTESTS=1 cargo build -p wasmer-emscripten
@ -36,7 +36,7 @@ test:
# We use one thread so the emscripten stdouts doesn't collide
# cargo test --all -- --test-threads=1 $(runargs)
# cargo test --all --exclude wasmer-emscripten -- --test-threads=1 $(runargs)
cargo test -p wasmer-runtime -- --test-threads=1 $(runargs)
cargo test -p wasmer-runtime-core -- --test-threads=1 $(runargs)
release:
# If you are in OS-X, you will need mingw-w64 for cross compiling to windows

View File

@ -5,7 +5,7 @@ authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]
edition = "2018"
[dependencies]
wasmer-runtime = { path = "../runtime" }
wasmer-runtime-core = { path = "../runtime-core" }
cranelift-native = "0.26.0"
cranelift-codegen = "0.26.0"
cranelift-entity = "0.26.0"

View File

@ -7,7 +7,7 @@ use crate::call::recovery::call_protected;
use hashbrown::HashSet;
use libffi::high::{arg as libffi_arg, call as libffi_call, CodePtr};
use std::iter;
use wasmer_runtime::{
use wasmer_runtime_core::{
backend::{ProtectedCaller, Token},
error::RuntimeResult,
export::Context,

View File

@ -12,7 +12,7 @@ use nix::sys::signal::{Signal, SIGBUS, SIGFPE, SIGILL, SIGSEGV};
use std::cell::{Cell, UnsafeCell};
use std::ptr;
use std::sync::Once;
use wasmer_runtime::{
use wasmer_runtime_core::{
error::{RuntimeError, RuntimeResult},
structures::TypedIndex,
types::{MemoryIndex, TableIndex},

View File

@ -16,7 +16,7 @@ use cranelift_wasm::{
use hashbrown::HashMap;
use std::mem;
use target_lexicon;
use wasmer_runtime::{
use wasmer_runtime_core::{
backend::SigRegistry,
memory::LinearMemory,
module::{

View File

@ -5,7 +5,7 @@ use cranelift_codegen::{
isa,
};
use cranelift_wasm::{self, FuncEnvironment, ModuleEnvironment};
use wasmer_runtime::{
use wasmer_runtime_core::{
memory::LinearMemory,
structures::TypedIndex,
types::{FuncIndex, GlobalIndex, LocalOrImport, MemoryIndex, TableIndex},

View File

@ -12,7 +12,7 @@ use cranelift_codegen::{
settings::{self, Configurable},
};
use target_lexicon::Triple;
use wasmer_runtime::{
use wasmer_runtime_core::{
backend::{Compiler, Token},
error::{CompileError, CompileResult},
module::ModuleInner,

View File

@ -7,7 +7,7 @@ use std::{
ops::{Deref, DerefMut},
ptr::NonNull,
};
use wasmer_runtime::{
use wasmer_runtime_core::{
backend::SigRegistry,
backend::{FuncResolver, ProtectedCaller, Token},
error::{CompileResult, RuntimeResult},

View File

@ -4,7 +4,7 @@ use crate::{
};
use cranelift_codegen::{ir, isa};
use cranelift_wasm::{self, translate_module, FuncTranslator, ModuleEnvironment};
use wasmer_runtime::{
use wasmer_runtime_core::{
error::{CompileError, CompileResult},
module::{DataInitializer, ExportIndex, ImportName, TableInitializer},
structures::{Map, TypedIndex},

View File

@ -6,7 +6,7 @@ use cranelift_codegen::binemit;
pub use cranelift_codegen::binemit::Reloc;
use cranelift_codegen::ir::{self, ExternalName, LibCall, SourceLoc, TrapCode};
use hashbrown::HashMap;
use wasmer_runtime::{structures::TypedIndex, types::LocalFuncIndex};
use wasmer_runtime_core::{structures::TypedIndex, types::LocalFuncIndex};
#[derive(Debug, Clone)]
pub struct Relocation {

View File

@ -7,7 +7,7 @@ use byteorder::{ByteOrder, LittleEndian};
use cranelift_codegen::{ir, isa, Context};
use std::mem;
use std::ptr::{write_unaligned, NonNull};
use wasmer_runtime::{
use wasmer_runtime_core::{
self,
backend::{
self,
@ -206,7 +206,7 @@ impl FuncResolver {
impl backend::FuncResolver for FuncResolver {
fn get(
&self,
_module: &wasmer_runtime::module::ModuleInner,
_module: &wasmer_runtime_core::module::ModuleInner,
index: LocalFuncIndex,
) -> Option<NonNull<vm::Func>> {
self.lookup(index)

View File

@ -7,7 +7,7 @@ build = "build/mod.rs"
[dependencies]
hashbrown = "0.1"
wasmer-runtime = { path = "../runtime" }
wasmer-runtime-core = { path = "../runtime-core" }
libc = { git = "https://github.com/rust-lang/libc" }
byteorder = "1"
time = "0.1.41"

View File

@ -8,7 +8,7 @@ use std::mem;
use std::os::raw::c_char;
use super::utils::{allocate_on_stack, copy_cstr_into_wasm, copy_terminated_array_of_cstrs};
use wasmer_runtime::{types::Value, Instance};
use wasmer_runtime_core::{types::Value, Instance};
//use super::EmscriptenData;
//impl Instance {

View File

@ -1,6 +1,6 @@
use super::env;
use super::process::_abort;
use wasmer_runtime::Instance;
use wasmer_runtime_core::Instance;
/// emscripten: ___cxa_allocate_exception
pub extern "C" fn ___cxa_allocate_exception(size: u32, instance: &mut Instance) -> u32 {

View File

@ -1,6 +1,6 @@
use libc::printf as _printf;
use wasmer_runtime::Instance;
use wasmer_runtime_core::Instance;
/// putchar
pub use libc::putchar;

View File

@ -1,5 +1,5 @@
use libc::{c_int, c_void};
use wasmer_runtime::Instance;
use wasmer_runtime_core::Instance;
/// setjmp
pub extern "C" fn __setjmp(env_addr: u32, instance: &mut Instance) -> c_int {

View File

@ -1,10 +1,10 @@
#[macro_use]
extern crate wasmer_runtime;
extern crate wasmer_runtime_core;
use byteorder::{ByteOrder, LittleEndian};
use hashbrown::HashMap;
use std::mem;
use wasmer_runtime::{
use wasmer_runtime_core::{
export::{Context, Export, FuncPointer, GlobalPointer},
import::{ImportObject, Namespace},
memory::LinearMemory,

View File

@ -1,4 +1,4 @@
use wasmer_runtime::Instance;
use wasmer_runtime_core::Instance;
// TODO: Need to implement.

View File

@ -1,5 +1,5 @@
use libc::c_int;
use wasmer_runtime::Instance;
use wasmer_runtime_core::Instance;
// NOTE: Not implemented by Emscripten
pub extern "C" fn ___lock(which: c_int, varargs: c_int, _instance: &mut Instance) {

View File

@ -1,6 +1,6 @@
use super::process::abort_with_message;
use libc::{c_int, c_void, memcpy, size_t};
use wasmer_runtime::Instance;
use wasmer_runtime_core::Instance;
/// emscripten: _emscripten_memcpy_big
pub extern "C" fn _emscripten_memcpy_big(

View File

@ -1,5 +1,5 @@
use super::process::abort_with_message;
use wasmer_runtime::Instance;
use wasmer_runtime_core::Instance;
pub extern "C" fn nullfunc_ii(x: u32, _instance: &Instance) {
debug!("emscripten::nullfunc_ii {}", x);

View File

@ -1,7 +1,7 @@
use libc::{abort, c_char, c_int, exit, pid_t, EAGAIN};
use std::ffi::CStr;
use wasmer_runtime::Instance;
use wasmer_runtime_core::Instance;
pub extern "C" fn abort_with_message(message: &str) {
debug!("emscripten::abort_with_message");

View File

@ -1,5 +1,5 @@
// use super::varargs::VarArgs;
use wasmer_runtime::Instance;
use wasmer_runtime_core::Instance;
#[allow(clippy::cast_ptr_alignment)]
pub extern "C" fn _sigemptyset(set: u32, instance: &mut Instance) -> i32 {

View File

@ -70,7 +70,7 @@ use libc::{
SO_REUSEADDR,
TIOCGWINSZ,
};
use wasmer_runtime::Instance;
use wasmer_runtime_core::Instance;
use super::env;
use std::mem;

View File

@ -6,7 +6,7 @@ use std::time::SystemTime;
use time;
use super::env;
use wasmer_runtime::Instance;
use wasmer_runtime_core::Instance;
#[cfg(target_os = "linux")]
use libc::{CLOCK_MONOTONIC, CLOCK_MONOTONIC_COARSE, CLOCK_REALTIME};

View File

@ -1,5 +1,5 @@
use wasmer_runtime::{module::Module, Instance};
//use wasmer_runtime::Instance;
use wasmer_runtime_core::{module::Module, Instance};
//use wasmer_runtime_core::Instance;
use super::env;
use libc::stat;
use std::ffi::CStr;
@ -144,7 +144,7 @@ mod tests {
use std::sync::Arc;
use wabt::wat2wasm;
use wasmer_clif_backend::CraneliftCompiler;
use wasmer_runtime::{compile, module::Module};
use wasmer_runtime_core::{compile, module::Module};
#[test]
fn should_detect_emscripten_files() {

View File

@ -1,5 +1,5 @@
use std::mem;
use wasmer_runtime::Instance;
use wasmer_runtime_core::Instance;
#[repr(transparent)]
pub struct VarArgs {

View File

@ -10,7 +10,7 @@ macro_rules! assert_emscripten_output {
let wasm_bytes = include_bytes!($file);
let module = wasmer_runtime::compile(&wasm_bytes[..], &CraneliftCompiler::new())
let module = wasmer_runtime_core::compile(&wasm_bytes[..], &CraneliftCompiler::new())
.expect("WASM can't be compiled");
// let module = compile(&wasm_bytes[..])

View File

@ -0,0 +1,33 @@
[package]
name = "wasmer-runtime-core"
version = "0.1.0"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]
edition = "2018"
build = "build/mod.rs"
[dependencies]
hashbrown = "0.1"
nix = "0.12.0"
page_size = "0.4.1"
wasmparser = "0.23.0"
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["memoryapi"] }
[target.'cfg(unix)'.dependencies]
errno = "0.2.4"
[build-dependencies]
wabt = "0.7.2"
[dev-dependencies]
wasmer-clif-backend = { path = "../clif-backend" }
wabt = "0.7.2"
field-offset = "0.1.1"
[features]
default = ["fast-tests"]
debug = []
# This feature will allow cargo test to compile much faster
fast-tests = []

View File

@ -78,10 +78,10 @@ static COMMON: &'static str = r##"
use std::{{f32, f64}};
use wabt::wat2wasm;
use wasmer_clif_backend::CraneliftCompiler;
use wasmer_runtime::import::ImportObject;
use wasmer_runtime::types::Value;
use wasmer_runtime::{{Instance, module::Module}};
use wasmer_runtime::error::Result;
use wasmer_runtime_core::import::ImportObject;
use wasmer_runtime_core::types::Value;
use wasmer_runtime_core::{{Instance, module::Module}};
use wasmer_runtime_core::error::Result;
static IMPORT_MODULE: &str = r#"
(module
@ -96,7 +96,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::compile(&wasm_binary[..], &CraneliftCompiler::new())
let module = wasmer_runtime_core::compile_with(&wasm_binary[..], &CraneliftCompiler::new())
.expect("WASM can't be compiled");
let instance = module
.instantiate(ImportObject::new())
@ -292,8 +292,8 @@ impl WastTestGenerator {
// //use wabt::wat2wasm;
// use std::{{f32, f64}};
// use wasmer_runtime::types::Value;
// use wasmer_runtime::{{Instance, module::Module}};
// use wasmer_runtime_core::types::Value;
// use wasmer_runtime_core::{{Instance, module::Module}};
// //use crate::spectests::_common::{{
// // generate_imports,
@ -357,7 +357,7 @@ fn test_module_{}() {{
let module_str = \"{}\";
println!(\"{{}}\", module_str);
let wasm_binary = wat2wasm(module_str.as_bytes()).expect(\"WAST not valid or malformed\");
let module = wasmer_runtime::compile(&wasm_binary[..], &CraneliftCompiler::new()).expect(\"WASM can't be compiled\");
let module = wasmer_runtime_core::compile_with(&wasm_binary[..], &CraneliftCompiler::new()).expect(\"WASM can't be compiled\");
module.instantiate(generate_imports()).expect(\"WASM can't be instantiated\")
}}\n",
self.last_module,
@ -397,7 +397,7 @@ fn test_module_{}() {{
"#[test]
fn {}_assert_invalid() {{
let wasm_binary = {:?};
let module = wasmer_runtime::compile(&wasm_binary, &CraneliftCompiler::new());
let module = wasmer_runtime_core::compile_with(&wasm_binary, &CraneliftCompiler::new());
assert!(module.is_err(), \"WASM should not compile as is invalid\");
}}\n",
command_name,
@ -528,7 +528,7 @@ fn {}_assert_invalid() {{
"#[test]
fn {}_assert_malformed() {{
let wasm_binary = {:?};
let compilation = wasmer_runtime::compile(&wasm_binary, &CraneliftCompiler::new());
let compilation = wasmer_runtime_core::compile_with(&wasm_binary, &CraneliftCompiler::new());
assert!(compilation.is_err(), \"WASM should not compile as is malformed\");
}}\n",
command_name,

View File

@ -1,12 +1,12 @@
use wabt::wat2wasm;
use wasmer_clif_backend::CraneliftCompiler;
use wasmer_runtime::{self as runtime, error::Result, prelude::*};
use wasmer_runtime_core::{error::Result, prelude::*};
static EXAMPLE_WASM: &'static [u8] = include_bytes!("simple.wasm");
fn main() -> Result<()> {
let wasm_binary = wat2wasm(IMPORT_MODULE.as_bytes()).expect("WAST not valid or malformed");
let inner_module = runtime::compile(&wasm_binary, &CraneliftCompiler::new())?;
let inner_module = wasmer_runtime_core::compile_with(&wasm_binary, &CraneliftCompiler::new())?;
let import_object = imports! {
"env" => {
@ -20,7 +20,7 @@ fn main() -> Result<()> {
"env" => inner_instance,
};
let outer_module = runtime::compile(EXAMPLE_WASM, &CraneliftCompiler::new())?;
let outer_module = wasmer_runtime_core::compile_with(EXAMPLE_WASM, &CraneliftCompiler::new())?;
let mut outer_instance = outer_module.instantiate(outer_imports)?;
let ret = outer_instance.call("main", &[Value::I32(42)])?;
println!("ret: {:?}", ret);

View File

@ -1,6 +1,6 @@
use wabt::wat2wasm;
use wasmer_clif_backend::CraneliftCompiler;
use wasmer_runtime::{import::ImportObject, Instance};
use wasmer_runtime_core::{import::ImportObject, Instance};
fn main() {
let mut instance = create_module_1();
@ -24,7 +24,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 = wasmer_runtime::compile(&wasm_binary[..], &CraneliftCompiler::new())
let module = wasmer_runtime_core::compile_with(&wasm_binary[..], &CraneliftCompiler::new())
.expect("WASM can't be compiled");
module
.instantiate(generate_imports())
@ -44,7 +44,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::compile(&wasm_binary[..], &CraneliftCompiler::new())
let module = wasmer_runtime_core::compile_with(&wasm_binary[..], &CraneliftCompiler::new())
.expect("WASM can't be compiled");
let instance = module
.instantiate(ImportObject::new())

Some files were not shown because too many files have changed in this diff Show More