wasm_runtime_layer
wasm_runtime_layer
creates a thin abstraction over WebAssembly runtimes, allowing for backend-agnostic host code. The interface is based upon the wasmtime
and wasmi
crates, but may be implemented for any runtime.
Usage
To use this crate, first instantiate a backend runtime. The runtime may be any
value that implements backend::WasmEngine
. Some runtimes are already implemented as additional crates.
Then, one can create an Engine
from the backend runtime, and use it to initialize modules and instances:
// 1. Instantiate a runtime
let engine = new;
let mut store = new;
// 2. Create modules and instances, similar to other runtimes
let module_bin = parse_str
.unwrap;
let module = new.unwrap;
let instance = new.unwrap;
let add_one = instance
.get_export
.unwrap
.into_func
.unwrap;
let mut result = ;
add_one
.call
.unwrap;
assert_eq!;
Backends
- wasmi_runtime_layer - Implements the
WasmEngine
trait for wrappers aroundwasmtime::Engine
instances. - wasmtime_runtime_layer - Implements the
WasmEngine
trait for wrappers aroundwasmtime::Engine
instances. - js_wasm_runtime_layer - Implements a wasm engine targeting the browser's WebAssembly API on
wasm32-unknown-unknown
targets. - pyodide-webassembly-runtime-layer - Implements a wasm engine targeting the browser's WebAssembly API when running as a Python extension module inside Pyodide.
Contributions for additional backend implementations are welcome!
Testing
To run the tests for wasmi and wasmtime, run:
For the wasm32 target, you can use the slower interpreter wasmi, or the native JIT accelerated browser backend.
To test the backends, you need to install wasm-pack
.
You can then run: