hook up wasi to wasmer

This commit is contained in:
Mark McCaskey 2019-03-28 12:19:23 -07:00
parent c045da3de6
commit bc863fcf0c
6 changed files with 33 additions and 1 deletions

1
Cargo.lock generated
View File

@ -1339,6 +1339,7 @@ dependencies = [
"wasmer-llvm-backend 0.1.0",
"wasmer-runtime 0.2.1",
"wasmer-runtime-core 0.2.1",
"wasmer-wasi 0.1.0",
]
[[package]]

View File

@ -28,6 +28,7 @@ wasmer-runtime-core = { path = "lib/runtime-core" }
wasmer-emscripten = { path = "lib/emscripten" }
wasmer-llvm-backend = { path = "lib/llvm-backend", optional = true }
wasmer-dynasm-backend = { path = "lib/dynasm-backend", optional = true }
wasmer-wasi = { path = "lib/wasi", optional = true }
[workspace]
members = ["lib/clif-backend", "lib/dynasm-backend", "lib/runtime", "lib/runtime-core", "lib/emscripten", "lib/spectests", "lib/win-exception-handler", "lib/runtime-c-api", "lib/llvm-backend", "lib/wasi"]
@ -42,4 +43,5 @@ default = ["fast-tests"]
# This feature will allow cargo test to run much faster
fast-tests = []
llvm = ["wasmer-llvm-backend"]
dynasm = ["wasmer-dynasm-backend"]
dynasm = ["wasmer-dynasm-backend"]
wasi = ["wasmer-wasi"]

View File

@ -1,6 +1,10 @@
mod syscalls;
mod utils;
use syscalls::*;
pub use self::utils::is_wasi_module;
use wasmer_runtime_core::{func, import::ImportObject, imports};
pub fn generate_import_object() -> ImportObject {

8
lib/wasi/src/utils.rs Normal file
View File

@ -0,0 +1,8 @@
use wasmer_runtime_core::{module::Module, vm::Ctx};
// Cargo culting this from our emscripten implementation for now, but it seems like a
// good thing to check; TODO: verify this is useful
pub fn is_wasi_module(module: &Module) -> bool {
true
// TODO:
}

View File

@ -15,6 +15,7 @@ use wasmer::*;
use wasmer_emscripten;
use wasmer_runtime::cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH};
use wasmer_runtime_core::backend::CompilerConfig;
use wasmer_wasi;
#[derive(Debug, StructOpt)]
#[structopt(name = "wasmer", about = "Wasm execution runtime.")]
@ -200,6 +201,8 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
.map_err(|e| format!("Can't compile module: {:?}", e))?
};
// TODO: refactor this
#[cfg(not(features = "wasi"))]
let (_abi, import_object, _em_globals) = if wasmer_emscripten::is_emscripten_module(&module) {
let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module);
(
@ -215,6 +218,19 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
)
};
#[cfg(features = "wasi")]
let (_abi, import_object) = if wasmer_wasi::is_wasi_module(&module) {
(
InstanceABI::WASI,
wasmer_emscripten::generate_import_object(),
)
} else {
(
InstanceABI::None,
wasmer_runtime_core::import::ImportObject::new(),
)
};
let mut instance = module
.instantiate(&import_object)
.map_err(|e| format!("Can't instantiate module: {:?}", e))?;

View File

@ -21,6 +21,7 @@ pub struct ResultObject {
#[derive(PartialEq)]
pub enum InstanceABI {
Emscripten,
WASI,
None,
}