Embed Wasmd in Rust
Own the engine, host imports, and execution state inside your application.
Compile, instantiate, invoke
Engine owns compilation configuration; Linker supplies imports; Store owns mutable execution state. This example uses the Rust API in the Wasmd workspace.
use wasmd::{Engine, Linker, Value};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let engine = Engine::default();
let module = engine.compile_text(
r#"(module (func (export "answer") (result i32) i32.const 42))"#,
)?;
let mut store = engine.new_store();
let instance = engine.instantiate(&module, &Linker::new(), &mut store)?;
assert_eq!(instance.invoke(&mut store, "answer", &[])?,
vec![Value::from_i32(42)]);
Ok(())
}Prepare repeated instantiation
Engine::preinstantiate checks and resolves imports once. InstancePre::instantiate creates independent module-owned state for each Store. Imported host resources remain shared. InstancePool provides bounded admission; PoolReuseConfig can reuse cleared buffers without reusing live instances.
Choose an execution backend deliberately
The interpreter is the default. Optional Cranelift execution combines native integer functions and arithmetic with interpreter fallback. backend_coverage() distinguishes native, mixed, and interpreted code. Signed Core machine-code caches require explicit compiler-key trust and matching Wasm, target, CPU, and versions.
Other language integrations
C ABI 1.1 provides controlled numeric calls, host callbacks, and memory copies. Python bindings are a development preview. macOS SDK validation and final ABI freeze remain outstanding; Go and .NET have integration contracts, not delivered SDKs.
Based on the current repository documentation. Check your installed version and the linked acceptance records when adopting development features.
Read the Wasmd source document ↗