This issue can help: https://github.com/bytecodealliance/wasmtime-go/issues/80
And yet another example: https://github.com/bytecodealliance/wasmtime-go/blob/a1a8116cf3965d0e228229f3b3a497ba6da6a9b7/func_test.go#L422
You should use wasmtime.Linker.DefineFunc()
to link host-func by name. Something like this:
...
linker := wasmtime.NewLinker(engine)
err := linker.DefineWasi()
if err != nil {
return err
}
store := wasmtime.NewStore(engine)
wasiConfig := wasmtime.NewWasiConfig()
...
store.SetWasi(wasiConfig)
err = linker.DefineFunc(store, "env", "HostFunc", func() {
fmt.Println("HOSTCALL!!!")
})
if err != nil {
return err
}
instance, err := linker.Instantiate(store, module)
if err != nil {
return err
}
...
And in the guest:
package main
//export HostFunc
func HostFunc()
func main() {
HostFunc()
}