Stream: wit-bindgen

Topic: How to pass host function to guest


view this post on Zulip Ralph Deters (Feb 24 2023 at 21:01):

Hello,
I am having problems in passing a host function to the guest (component). Below is the wit file

default world myworld {
import foo: func(input:string) -> string
export demo: interface {
myfunction: func(input: string) -> string
}
}

how do I define and pass the "foo" function in the host to the component?

the component is created with

let component = Component::from_binary(&engine, &component)?;
let (myworld,_) = Myworld::instantiate(&mut store, &component, &linker)?;

view this post on Zulip Ramon Klass (Feb 24 2023 at 21:03):

you need to use the wasmtime::component::bindgen!macro to generate the traits and then you need to implement those traits

view this post on Zulip Ramon Klass (Feb 24 2023 at 21:04):

it needs the component-model feature flag on wasmtime

view this post on Zulip Ramon Klass (Feb 24 2023 at 21:05):

example here https://docs.rs/wasmtime/latest/wasmtime/component/macro.bindgen.html

view this post on Zulip Ralph Deters (Feb 24 2023 at 22:29):

thanks for the link - but I am still running into issues e.g Error: module requires an import interface named env
I guess I will have to read a bit more.

view this post on Zulip Ralph Deters (Feb 24 2023 at 23:20):

(deleted)

view this post on Zulip Ramon Klass (Feb 24 2023 at 23:25):

if this is a wasi component you need the experimental host prototype from https://github.com/bytecodealliance/preview2-prototyping/tree/main/host

Polyfill adapter for preview1-using wasm modules to call preview2 functions. - preview2-prototyping/host at main · bytecodealliance/preview2-prototyping

view this post on Zulip Ralph Deters (Feb 25 2023 at 02:34):

Ramon Klass said:

if this is a wasi component you need the experimental host prototype from https://github.com/bytecodealliance/preview2-prototyping/tree/main/host

thanks

ralph


Last updated: Dec 23 2024 at 12:05 UTC