Stream: general

Topic: wasmtime component linking


view this post on Zulip Sehyo Chang (Sep 29 2023 at 23:44):

Hi, is there examples of linking two wasm component in the wasmtime?
In my example, 2nd component imports interface from 1st component.
first wit

package acme:first
interface first-service {
     hello: func(msg: string)
}

world first-world {
    export first-service
}

2nd wit depends on first

package acme:second
interface second-service {
     hello: drive()
}

world second-world {
   import first-service
    export second-service
}

I tried something like this:

....
let first_comp  = Component::from_file(&engine, &path1)?
let second_comp = Component::from_file(&engine, &path2)?;
let first_instance = linker.instantiate(&mut store, &first_comp)?;   // this works
let second_instance  =  linker.instantiate(&mut store, &second_comp)?;.  // this doesn't work

but result in error message something like
Error: import acme:first/first-service has the wrong type

Caused by:
0: instance export hello has the wrong type
1: expected func found nothing


view this post on Zulip Pat Hickey (Sep 29 2023 at 23:55):

nope, unlike the wasmtime module linker, the only thing the wasmtime component linker can do is link a component to host function definitions.

view this post on Zulip Pat Hickey (Sep 29 2023 at 23:55):

if you need to link components, we recommend you use wasm-tools compose or the wasm-compose crate

view this post on Zulip Sehyo Chang (Sep 30 2023 at 00:48):

Got it. Linking thru compose works. Thanks

view this post on Zulip Banna Jack (Dec 01 2023 at 08:39):

Hi bro. I'm got this error too. but I'm a newer for wasmtime and wasm. please help me. how to use it link to wasmtime


Last updated: Nov 22 2024 at 16:03 UTC