liveBook · Manning

Wasmtime linker

As explained in Server-Side WebAssembly

A Wasmtime linker resolves host-provided imports and guest interfaces when instantiating WebAssembly modules or components.

A Wasmtime component linker connects host capabilities to guest code: it registers the host implementation that the guest can call, then supports component instantiation. section 3.4.2

Connecting SmartCMS state

A Rust host enables the component model, creates an Engine and Store containing State, loads guest.wasm, and registers the kvstore interface. The generated add_to_linker function maps linker calls to state.key_value; the component can then be instantiated and its run function called. section 3.4.2

// ...
fn main() {
    // ...
    let mut linker = wasmtime::component::Linker::new(&engine);
    component::smartcms::kvstore::add_to_linker
    ➥(&mut linker, |state: &mut State| &mut state.key_value).unwrap();
}

Inspect the central registration call that connects generated kvstore bindings to the host's mutable KeyValue state. section 3.4.2

How Server-Side WebAssembly covers it

How deep it goes
Shows configuration, engine and store setup, component loading, linker registration, instantiation, and invocation, without detailing linker internals.
Examples
Uses SmartCMS State containing a KeyValue store and exposes kvstore get and set functions to guest code.
What you can do after
Build it from scratch: register host state with a component Linker and invoke the instantiated guest.
How it connects
Ties host interfaces to component bindings, Store state, Engine configuration, and guest component instantiation.

Related concepts

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.