Crates.io | deterministic-wasi-ctx |
lib.rs | deterministic-wasi-ctx |
version | 0.1.26 |
source | src |
created_at | 2022-05-27 21:17:38.639365 |
updated_at | 2024-10-23 13:34:27.260087 |
description | A wasi-common WasiCtx implementation that is fully deterministic |
homepage | |
repository | https://github.com/Shopify/deterministic-wasi-ctx |
max_upload_size | |
id | 595320 |
size | 11,605 |
A Rust crate for creating a wasi-common WASI context implementation that is fully deterministic.
Determinism refers to the property that a provided WASI function will always return the same series of results for the same series of invocations. For example, invoking clock_time_get
against the system clock will always return the same timestamp. Or invoking random_get
will always return 155
on the first invocation followed by always returning 111
on the second invocation.
This can be useful in a variety of contexts. For example, caching the results of invoking a function in a Wasm module.
let wasi = deterministic_wasi_ctx::build_wasi_ctx();
let engine = Engine::default();
let mut linker = Linker::new(&engine);
wasmtime_wasi::add_to_linker(&mut linker, |s| s).unwrap();
let module_path = ...; // path to a Wasm module
let module = Module::from_file(&engine, module_path).unwrap();
let mut store = Store::new(&engine, wasi);
linker.module(&mut store, "", &module).unwrap();
let instance = linker.instantiate(&mut store, &module).unwrap();
... // invoke functions on `instance`
deterministic-wasi-ctx
is a beta project and will be under major development. We welcome feedback, bug reports and bug fixes. We're also happy to discuss feature development but please discuss the features in an issue before contributing.
wasm32-wasi
target, can be installed by running rustup target add wasm32-wasi
After all the dependencies are installed, run make build-deterministic-wasi-ctx
to build the crate.
Run make test
to run integration tests.
The deterministic-wasi-ctx-test-programs
crate is used to build a collection of Wasm files invoking WASI functions that the integration tests in the deterministic-wasi-ctx
crate use to verify the output from those Wasm files is deterministic.