deterministic-wasi-ctx
About this repo
A Rust crate for creating a wasmtime-wasi 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.
Features
wasi-common- Enabling this feature exposes APIs that use thewasi-commoncrate instead ofwasmtime-wasi.
Usage
let engine = default;
let mut wasi_builder = new;
let mut linker = new;
add_determinism_to_wasi_ctx_builder;
let wasi = wasi_builder.build_p1;
add_to_linker_sync?;
replace_scheduling_functions?;
let mut store = new;
let module_path = ...; // path to a Wasm module
let module = from_file.unwrap;
let instance = linker.instantiate.unwrap;
... // invoke functions on `instance`
Contributing
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.
Build dependencies
- rustup
- The latest release of Rust on the stable channel
wasm32-wasip1target, can be installed by runningrustup target add wasm32-wasip1
Building
After all the dependencies are installed, run make build-deterministic-wasi-ctx to build the crate.
Testing
Run make test to run integration tests.
Structure
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.