5 releases
0.3.6 | Mar 26, 2024 |
---|---|
0.3.5 | Mar 26, 2024 |
0.3.4 | Mar 26, 2024 |
0.3.3 | Mar 26, 2024 |
0.3.2 | Mar 24, 2024 |
#473 in Operating systems
21KB
497 lines
A library to run wasi modules as pseudo-processes.
use wasmer_wasi::{WasiEnv, WasiState, WasiVersion};
use wasi_process::WasiProcess;
let store = wasmer::Store::default();
let wasm = include_bytes!("../helloworld.wasm"); // just write(1, "Hello, World!\n", 14)
let module = wasmer::Module::new(&store, wasm)?;
let mut state = WasiState::new("progg");
wasi_process::add_stdio(&mut state);
state.args(&["foo", "bar"]);
let imports = wasmer_wasi::generate_import_object_from_env(
&store,
WasiEnv::new(state.build()?),
wasmer_wasi::get_wasi_version(&module, false).unwrap_or(WasiVersion::Latest),
);
let instance = wasmer::Instance::new(&module, &imports)?;
let mut wasi = WasiProcess::new(&instance, wasi_process::MaxBufSize::default())?;
let mut stdout = wasi.stdout.take().unwrap();
wasi.spawn();
let mut out = String::new();
stdout.read_to_string(&mut out).await?;
assert_eq!(out, "Hello, World!\n");
Dependencies
~11–21MB
~306K SLoC