Skip to main content

Crate wamrx

Crate wamrx 

Source
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 Linker owns that registration.
  • Host functions support the four numeric types and at most one result (a limitation of WAMR’s raw calling convention).
  • A Module owns its Wasm bytes because WAMR mutates and retains the input buffer.
  • The runtime is single-threaded; Engine is neither Send nor Sync.

Structs§

Engine
The engine owns global WAMR runtime state.
Func
A handle to a function exported by an Instance.
FuncType
The signature of a Wasm function: its parameter and result types.
Global
A handle to a global exported by an Instance.
GlobalType
The type of a Wasm global: its content type and mutability.
Instance
An instantiated Wasm module.
InstanceConfig
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 wamrx operations.
Mutability
Whether a Wasm global may be mutated after instantiation.
Val
A typed Wasm value.
ValType
A Wasm value type.

Type Aliases§

HostFunc
The boxed Rust closure backing a wamrx host function.
Result
Convenience result alias for wamrx.