Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hook up wasi to wasmer #300

Merged
merged 6 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"]
4 changes: 4 additions & 0 deletions lib/wasi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions lib/wasi/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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:
}
16 changes: 16 additions & 0 deletions src/bin/wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")]
Expand Down Expand Up @@ -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);
(
Expand All @@ -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(),
MarkMcCaskey marked this conversation as resolved.
Show resolved Hide resolved
)
} 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))?;
Expand Down
1 change: 1 addition & 0 deletions src/webassembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct ResultObject {
#[derive(PartialEq)]
pub enum InstanceABI {
Emscripten,
WASI,
None,
}

Expand Down