mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-05 02:20:19 +00:00
Update from feedback, improve docs on new wasi fns
This commit is contained in:
parent
f1e5cd39d8
commit
2b2a0628f7
@ -2,6 +2,8 @@
|
||||
|
||||
## **[Unreleased]**
|
||||
|
||||
- [#957](https://github.com/wasmerio/wasmer/pull/957) Change the meaning of `wasmer_wasi::is_wasi_module` to detect any type of WASI module, add support for new wasi snapshot_preview1
|
||||
|
||||
## 0.10.0 - 2019-11-11
|
||||
|
||||
- [#952](https://github.com/wasmerio/wasmer/pull/952) Use C preprocessor to properly hide trampoline functions on Windows and non-x86_64 targets.
|
||||
|
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1504,6 +1504,7 @@ dependencies = [
|
||||
"tempfile 3.1.0 (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.1",
|
||||
"wasmer-llvm-backend 0.10.1",
|
||||
"wasmer-runtime-core 0.10.1",
|
||||
"wasmer-singlepass-backend 0.10.1",
|
||||
]
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
//! Wasmer's WASI implementation
|
||||
//!
|
||||
//! Use `generate_import_object` to create an `ImportObject`. This `ImportObject`
|
||||
//! Use `generate_import_object` to create an [`ImportObject`]. This [`ImportObject`]
|
||||
//! can be combined with a module to create an `Instance` which can execute WASI
|
||||
//! Wasm functions.
|
||||
//!
|
||||
@ -47,7 +47,8 @@ pub struct ExitCode {
|
||||
pub code: syscalls::types::__wasi_exitcode_t,
|
||||
}
|
||||
|
||||
/// Creates a Wasi [`ImportObject`] with [`WasiState`].
|
||||
/// Creates a Wasi [`ImportObject`] with [`WasiState`] with the latest snapshot
|
||||
/// of WASI.
|
||||
pub fn generate_import_object(
|
||||
args: Vec<Vec<u8>>,
|
||||
envs: Vec<Vec<u8>>,
|
||||
@ -130,7 +131,7 @@ pub fn generate_import_object(
|
||||
}
|
||||
|
||||
#[cfg(feature = "snapshot0")]
|
||||
/// Creates a Wasi [`ImportObject`] with [`WasiState`].
|
||||
/// Creates a legacy Wasi [`ImportObject`] with [`WasiState`].
|
||||
pub fn generate_import_object_snapshot0(
|
||||
args: Vec<Vec<u8>>,
|
||||
envs: Vec<Vec<u8>>,
|
||||
|
@ -1,9 +1,10 @@
|
||||
use wasmer_runtime_core::module::Module;
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Check if a provided module is compiled with WASI support
|
||||
/// Check if a provided module is compiled for some version of WASI.
|
||||
/// Use [`get_wasi_version`] to find out which version of WASI the module is.
|
||||
pub fn is_wasi_module(module: &Module) -> bool {
|
||||
get_wasi_version(module) == Some(WasiVersion::Snapshot1)
|
||||
get_wasi_version(module).is_some()
|
||||
}
|
||||
|
||||
/// The version of WASI. This is determined by the namespace string
|
||||
@ -15,6 +16,7 @@ pub enum WasiVersion {
|
||||
Snapshot1,
|
||||
}
|
||||
|
||||
/// Detect the version of WASI being used from the namespace
|
||||
pub fn get_wasi_version(module: &Module) -> Option<WasiVersion> {
|
||||
let mut import_iter = module
|
||||
.info()
|
||||
@ -25,13 +27,15 @@ pub fn get_wasi_version(module: &Module) -> Option<WasiVersion> {
|
||||
// returns None if empty
|
||||
let first = import_iter.next()?;
|
||||
if import_iter.all(|idx| idx == first) {
|
||||
// once we know that all the namespaces are the same, we can use it to
|
||||
// detect which version of WASI this is
|
||||
match module.info().namespace_table.get(first) {
|
||||
"wasi_unstable" => Some(WasiVersion::Snapshot0),
|
||||
"wasi_snapshot_preview1" => Some(WasiVersion::Snapshot1),
|
||||
_ => None,
|
||||
}
|
||||
} else {
|
||||
// not all funcs have the same namespace: therefore it's not WASI
|
||||
// not all funcs have the same namespace, therefore it's not WASI
|
||||
None
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user