Expand description
Safe, Wasmi/Wasmtime-inspired Rust bindings for the WebAssembly Micro Runtime (WAMR) fast interpreter.
These bindings deliberately target only WAMR’s fast interpreter — no classic
interpreter, no AOT, and no JIT tiers — so no LLVM toolchain is required to
build them. Compile-time WAMR proposals map to cargo features (see the
crate’s Cargo.toml).
§Example
use wamrx::{Engine, Linker, Module, Val};
let engine = Engine::new()?;
let wasm = wat::parse_str(r#"(module (func (export "add") (param i32 i32) (result i32)
local.get 0 local.get 1 i32.add))"#)?;
let module = Module::new(&engine, &wasm)?;
let linker = Linker::new(&engine);
let instance = linker.instantiate(module)?;
let mut results = [Val::I32(0)];
instance.get_func("add")?.call(&[Val::I32(2), Val::I32(3)], &mut results)?;
assert_eq!(results[0], Val::I32(5));§Relationship to WAMR’s model
Where WAMR’s invariants differ from Wasmtime, wamrx surfaces them honestly
rather than faking them:
- Host functions are registered in a process-global registry keyed by
module name; the
Linkerowns that registration. - Host functions support the four numeric types and at most one result (a limitation of WAMR’s raw calling convention).
- A
Moduleowns its Wasm bytes because WAMR mutates and retains the input buffer. - The runtime is single-threaded;
Engineis neitherSendnorSync.
Structs§
- Engine
- The engine owns global WAMR runtime state.
- Func
- A handle to a function exported by an
Instance. - Func
Type - The signature of a Wasm function: its parameter and result types.
- Global
- A handle to a global exported by an
Instance. - Global
Type - The type of a Wasm global: its content type and mutability.
- Instance
- An instantiated Wasm module.
- Instance
Config - Per-instance resource sizes used when instantiating a module.
- Linker
- Defines host functions and instantiates
Modules against them. - Module
- A loaded Wasm module, ready to be instantiated via a
Linker.
Enums§
- Error
- Errors returned by
wamrxoperations. - Mutability
- Whether a Wasm global may be mutated after instantiation.
- Val
- A typed Wasm value.
- ValType
- A Wasm value type.