liveBook · Manning

Wasmtime component bindgen macro

As explained in Server-Side WebAssembly

The Wasmtime component bindgen macro generates Rust binding and glue code from WebAssembly component interfaces.

Wasmtime's component bindgen macro turns a WIT world into Rust bindings and glue code, giving a host typed interfaces for implementing imports and calling component exports. section 3.4.2

SmartCMS host

Add the macro with the WIT path and world name. It generates the Host trait and application API. Implement the key-value store with a Rust HashMap, register it through the generated linker helper, instantiate the component, and call run. section 3.4.2

wasmtime::component::bindgen!({
    path: "./smart_cms.wit",
    world: "app",
});

Inspect the macro invocation that selects the WIT file and app world used for code generation. section 3.4.2

How Server-Side WebAssembly covers it

How deep it goes
Explains generated glue, the Host trait, linker registration, component instantiation, and export calls.
Examples
Uses a SmartCMS host, a kvstore interface, HashMap-backed state, and a guest.wasm component.
What it assumes
Uses a Rust project, a WIT definition, and a Wasmtime dependency before generating bindings.
What you can do after
Builds a Rust Wasmtime host that implements WIT imports and calls a component's run function.
How it connects
Connects WIT, the WebAssembly component model, Rust traits, Linker, Store, Engine, and component instantiation.

This explainer was generated by Manning's knowledge graph from the text of Server-Side WebAssembly. The section links point to the parts of the book it draws on.