mirror of
https://github.com/fluencelabs/wasmer
synced 2025-04-25 10:22:19 +00:00
hook up wasi to wasmer
This commit is contained in:
parent
c045da3de6
commit
bc863fcf0c
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1339,6 +1339,7 @@ dependencies = [
|
|||||||
"wasmer-llvm-backend 0.1.0",
|
"wasmer-llvm-backend 0.1.0",
|
||||||
"wasmer-runtime 0.2.1",
|
"wasmer-runtime 0.2.1",
|
||||||
"wasmer-runtime-core 0.2.1",
|
"wasmer-runtime-core 0.2.1",
|
||||||
|
"wasmer-wasi 0.1.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -28,6 +28,7 @@ wasmer-runtime-core = { path = "lib/runtime-core" }
|
|||||||
wasmer-emscripten = { path = "lib/emscripten" }
|
wasmer-emscripten = { path = "lib/emscripten" }
|
||||||
wasmer-llvm-backend = { path = "lib/llvm-backend", optional = true }
|
wasmer-llvm-backend = { path = "lib/llvm-backend", optional = true }
|
||||||
wasmer-dynasm-backend = { path = "lib/dynasm-backend", optional = true }
|
wasmer-dynasm-backend = { path = "lib/dynasm-backend", optional = true }
|
||||||
|
wasmer-wasi = { path = "lib/wasi", optional = true }
|
||||||
|
|
||||||
[workspace]
|
[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"]
|
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"]
|
||||||
@ -43,3 +44,4 @@ default = ["fast-tests"]
|
|||||||
fast-tests = []
|
fast-tests = []
|
||||||
llvm = ["wasmer-llvm-backend"]
|
llvm = ["wasmer-llvm-backend"]
|
||||||
dynasm = ["wasmer-dynasm-backend"]
|
dynasm = ["wasmer-dynasm-backend"]
|
||||||
|
wasi = ["wasmer-wasi"]
|
@ -1,6 +1,10 @@
|
|||||||
mod syscalls;
|
mod syscalls;
|
||||||
|
mod utils;
|
||||||
|
|
||||||
use syscalls::*;
|
use syscalls::*;
|
||||||
|
|
||||||
|
pub use self::utils::is_wasi_module;
|
||||||
|
|
||||||
use wasmer_runtime_core::{func, import::ImportObject, imports};
|
use wasmer_runtime_core::{func, import::ImportObject, imports};
|
||||||
|
|
||||||
pub fn generate_import_object() -> ImportObject {
|
pub fn generate_import_object() -> ImportObject {
|
||||||
|
8
lib/wasi/src/utils.rs
Normal file
8
lib/wasi/src/utils.rs
Normal 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:
|
||||||
|
}
|
@ -15,6 +15,7 @@ use wasmer::*;
|
|||||||
use wasmer_emscripten;
|
use wasmer_emscripten;
|
||||||
use wasmer_runtime::cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH};
|
use wasmer_runtime::cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH};
|
||||||
use wasmer_runtime_core::backend::CompilerConfig;
|
use wasmer_runtime_core::backend::CompilerConfig;
|
||||||
|
use wasmer_wasi;
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
#[structopt(name = "wasmer", about = "Wasm execution runtime.")]
|
#[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))?
|
.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 (_abi, import_object, _em_globals) = if wasmer_emscripten::is_emscripten_module(&module) {
|
||||||
let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&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
|
let mut instance = module
|
||||||
.instantiate(&import_object)
|
.instantiate(&import_object)
|
||||||
.map_err(|e| format!("Can't instantiate module: {:?}", e))?;
|
.map_err(|e| format!("Can't instantiate module: {:?}", e))?;
|
||||||
|
@ -21,6 +21,7 @@ pub struct ResultObject {
|
|||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub enum InstanceABI {
|
pub enum InstanceABI {
|
||||||
Emscripten,
|
Emscripten,
|
||||||
|
WASI,
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user