Hello Guys, i have two components, called store and cli, store is a lib component while cli like the name signifies is a cli component, .
The Store component has two wit files, they are as follows :
types.wit
package component:store;
interface types {
record key-value-pair {
key: string,
value: string,
}
type key = string;
enum error{
nae,
}
resource store {
constructor();
insert: func(kv: key-value-pair) -> result<_, error>;
search: func(key: key) -> result<key-value-pair, error>;
delete: func(key: key) -> result<_, error>;
}
}
world.wit
package component:store;
interface types {
record key-value-pair {
key: string,
value: string,
}
type key = string;
enum error{
nae,
}
resource store {
constructor();
insert: func(kv: key-value-pair) -> result<_, error>;
search: func(key: key) -> result<key-value-pair, error>;
delete: func(key: key) -> result<_, error>;
}
}
The cli component only has a single main.rs file
#[allow(warnings)]
mod bindings;
use bindings::component::store::types::{KeyValuePair, Store};
fn main() {
let new_store = Store::new();
new_store.insert(&KeyValuePair{ key: "hello".to_owned(), value: "world".to_owned()}).unwrap();
assert_eq!(new_store.search(&"hello".to_owned()).unwrap().value, "world".to_owned())
}
I built both components with cargo component build which ran successfully without errors.
I also composed both components with command wac plug target/wasm32-wasi/debug/cli.wasm --plug target/wasm32-wasi/debug/store.wasm -o composed1.wasm which also ran fine without issues.
The issue comes when i try to run the composed wasm with command wasmtime run --dir /home/WASI_PROJECTS/ -S inherit-network -S cli -S preview2 -S tcp ./composed1.wasm It outputs such error :
Error: failed to run main module
./composed1.wasm
Caused by:
0: component imports instancecomponent:store/types
, but a matching implementation was not found in the linker
1: instance exportstore
has the wrong type
2: resource implementation is missing
Joshua Aruokhai said:
Hello Guys, i have two components, called store and cli, store is a lib component while cli like the name signifies is a cli component, .
The Store component has two wit files, they are as follows :types.wit
package component:store; interface types { record key-value-pair { key: string, value: string, } type key = string; enum error{ nae, } resource store { constructor(); insert: func(kv: key-value-pair) -> result<_, error>; search: func(key: key) -> result<key-value-pair, error>; delete: func(key: key) -> result<_, error>; } }
world.wit
package component:store; interface types { record key-value-pair { key: string, value: string, } type key = string; enum error{ nae, } resource store { constructor(); insert: func(kv: key-value-pair) -> result<_, error>; search: func(key: key) -> result<key-value-pair, error>; delete: func(key: key) -> result<_, error>; } }
The cli component only has a single main.rs file
#[allow(warnings)] mod bindings; use bindings::component::store::types::{KeyValuePair, Store}; fn main() { let new_store = Store::new(); new_store.insert(&KeyValuePair{ key: "hello".to_owned(), value: "world".to_owned()}).unwrap(); assert_eq!(new_store.search(&"hello".to_owned()).unwrap().value, "world".to_owned()) }
I built both components with cargo component build which ran successfully without errors.
I also composed both components with command wac plug target/wasm32-wasi/debug/cli.wasm --plug target/wasm32-wasi/debug/store.wasm -o composed1.wasm which also ran fine without issues.
The issue comes when i try to run the composed wasm with command wasmtime run --dir /home/WASI_PROJECTS/ -S inherit-network -S cli -S preview2 -S tcp ./composed1.wasm It outputs such error :Error: failed to run main module
./composed1.wasm
Caused by:
0: component imports instancecomponent:store/types
, but a matching implementation was not found in the linker
1: instance exportstore
has the wrong type
2: resource implementation is missing
Found my mistake, each component wit file needs to have a package version
Joshua Aruokhai has marked this topic as resolved.
Last updated: Dec 23 2024 at 13:07 UTC