Hi!
Like the title says, I'm trying to run a wasi component in a host program by using the wasmtime c-API. I created a component following the example in the component book:
package docs:adder@0.1.0;
interface add {
add: func(x: u32, y: u32) -> u32;
}
world adder {
export add;
}
And I'm trying to access the add function with the following code but it fails.
// Finding the add interface
wasmtime_component_export_index_t *interface_export = wasmtime_component_instance_get_export_index(&instance, context, nullptr, "add", 3);
if (interface_export == nullptr) {
LOGE("Failed to find interface export 'add'");
return;
}
The documentation for the c-api only shows how to load and run a module. Does anyone know where I can find info on how to load a component's world, interface, functions, etc...?
you'll need to lookup the instance named docs:adder/add@0.1.0 and then lookup the add function from that instance
That didn't work neither. I tried to create a simple rust host that would run the same component based on this example but I get the same error "Cannot get docs:adder@0.1.0 interface" from this :
let interface_idx = instance
.get_export_index(&mut store, None, "docs:adder/add@0.1.0")
.expect("Cannot get `docs:adder/add@0.1.0` interface");
I tried with "adder" and "add", but that didn't work neither.
When looking at this example instead, I see the snippet uses bindgen. Are component makers supposed to bundle their wit files with the wasm file so host applications can read them?
Could you share a reproduction of this?
Are component makers supposed to bundle their wit files with the wasm file so host applications can read them?
A WIT can be inferred from a wasm, so no, that's not required. The host would typically be originally built with a WIT, however, but that would be independent from wasms loaded at runtime.
Right, that's actually what I ended up doing. My host library defines the wit and the wasi component implements it. Thanks!
Last updated: Dec 06 2025 at 05:03 UTC