How to run separate WASI Components that call other components

I'm trying to figure out how to use cargo-component to build WebAssembly components that call other local components, and the dependency management is kickin' my butt.

The idea is to have an application host (Rust, for now) call a component that can call extensions to said component. See my wasm-playground repo for the project files.

I'm getting the following cargo-component build error when trying to build *pluggable*:

error: failed to create a target world for package `pluggable` (/home/slanden/Projects/wasm-playground/component_calling_plugins/rust/pluggable/Cargo.toml)
Caused by:
    0: failed to parse local target from directory `/home/slanden/Projects/wasm-playground/component_calling_plugins/rust/pluggable/wit`
    1: name `plugin-interface` is not defined
            --> /home/slanden/Projects/wasm-playground/component_calling_plugins/rust/pluggable/wit/pluggable.wit:6:35
             |
           6 |   get: func(index: u32) -> option;

The error was because I was trying to return an interface from a function in the WIT file, which is invalid:

get: func(index: u32) -> option<plugin-interface>; // Wrong

To summarize the project setup, I have several crates:

  • application - a Rust host using Wasmtime
  • plugin_api - convenience for plugin implementers
  • pluggable - the component that is plugged into
  • plugin_host_api - bindings for the host

The project compiles, but I get a runtime error when I try to instantiate the pluggable component:

no exported instance named `example:plugin-host/pluggable-interface`

I think this happens because in this line

// PluginWorld is the host struct returned from `wasmtime::component::bindgen!`
PluginWorld::instantiate(store, component, linker)

tries to instantiate a host component, but I need to instantiate a pluggable component, except there's not instantiate method for it.

If interested, the parent directory in the repo has a working example of a Rust host calling plugins I finally got working with help from numerous watchings of Alexandru Radovici's step-by-step talk and an easily digestible article from @benwis (Ben, your site link died since then).

1 Like