Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning/Error with host functions #60

Closed
amlwwalker opened this issue Jan 11, 2024 · 2 comments
Closed

Warning/Error with host functions #60

amlwwalker opened this issue Jan 11, 2024 · 2 comments

Comments

@amlwwalker
Copy link

Hi,
I have

// The host functions embedded into the plugin
// go:plugin type=host
service HostService {
  rpc Log(LogRequest) returns (google.protobuf.Empty) {}
}
message LogRequest {
  string message = 1;
}

and on compilation with

	protoc -I pkg/plugins/interop/service --go-plugin_out=pkg/plugins/interop --go-plugin_opt=paths=source_relative pkg/plugins/interop/service/interop.proto

and generating my plugin with

	tinygo build -o pkg/plugins/examples/basic.wasm -scheduler=none -target=wasi --no-debug pkg/plugins/examples/basic.go

I then have in my plugin

func main() {
	interop.RegisterPluginService(MyPlugin{})
}

type MyPlugin struct{}

func (m MyPlugin) SendMessage(ctx context.Context, request *interop.DataMessage) (*interop.DataMessage, error) {

	hostFunctions := interop.NewHostService()
	hostFunctions.Log(ctx, &interop.LogRequest{
		Message: "Sending a log...",
	})

where SendMessage is one of the plugin functions that the host calls, I then want to call the logger on the host as you can see.

In my host I have

func (PluginFunctions) Log(ctx context.Context, request *interop.LogRequest) (*emptypb.Empty, error) {
	// Use the host logger
	log.Println("logging ", request.GetMessage())
	return &emptypb.Empty{}, nil
}

where the plugin was registered with

		if this, err := p.Load(ctx, path, PluginFunctions{}); err != nil {

now, If I remove in the plugin the `hostFunctions.Log` call everything works as expected. However when I add this back and compile the plugin I get

tinygo build -o pkg/plugins/examples/basic.wasm -scheduler=none -target=wasi --no-debug pkg/plugins/examples/basic.go
tinygo:wasm-ld: warning: function signature mismatch: log

defined as (i32, i32) -> i64 in lto.tmp
defined as (f64) -> f64 in /opt/homebrew/Cellar/tinygo/0.30.0/lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a(log.o)


its a warning, however when i run the host I get

2024/01/11 12:04:49 error starting plugin service wasm error: unreachable
wasm stack trace:
.(main.MyPlugin).SendMessage(i32)
.plugin_service_send_message(i32,i32) i64


- this is hard to debug. Could it be the version of wasm is wasm32 and for some reason the host function needs 64 or something? 
thanks
@inliquid
Copy link
Contributor

inliquid commented Jan 11, 2024

Try to rename Log to HostLog or something to not interfere with log from libc (this worked with older versions of tinygo because of bug, that many other packages start to rely on it at some point).

Also please take a look at related issues:

@amlwwalker
Copy link
Author

nice thanks. Solved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants