Crate wasi_process

Source
Expand description

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");

Structs§

  • A struct to configure the sizes of the internal buffers used for stdio.
  • A handle to a spawned a wasi process.
  • The stderr pseudo-file for wasi processes.
  • The stdin pseudo-file for wasi processes.
  • The stdout pseudo-file for wasi processes.
  • A wasi process. See crate documentation for more details and examples.
  • An AsyncRead type representing a wasi stderr stream.
  • An AsyncWrite type representing a wasi stdin stream.
  • An AsyncRead type representing a wasi stdout stream.

Enums§

  • An error returned from a spawned process. Either an error from tokio’s task::spawn, such as a panic or cancellation, or a wasm/wasi error, like an _exit() call or an unreachable.

Functions§

  • Use the wasi-process stdio pseudo-files for a wasi environment.