wasmerio / wasmer-go

🐹🕸️ WebAssembly runtime for Go
https://pkg.go.dev/github.com/wasmerio/wasmer-go
MIT License
2.84k stars 161 forks source link

NewInstance() function returning nil as primary value and an error. #368

Closed KILLinefficiency closed 1 year ago

KILLinefficiency commented 1 year ago

Thanks for the bug report!

Describe the bug

I have written a simple Go module with a simple function and generated a .wasm file via the Go compiler. While loading the same .wasm file in another Go module, the NewInstance() function returns an error:

Missing import: `go`.`debug`

Expected behavior

The NewInstance() function should return a value of type *wasmer.Instance and nil as error.

Actual behavior

The NewInstance function returns nil as the primary value instead of *wasmer.Instance variable. And the error is returned to be:

Missing import: `go`.`debug`

The exact line is:

instance, err := wasmer.NewInstance(module, importObject)
regnaio commented 1 year ago

@KILLinefficiency how did you solve this issue?

KILLinefficiency commented 1 year ago

@regnaio I didn't. I was no longer working on it, so I closed the issue.

regnaio commented 1 year ago

@KILLinefficiency I was trying this library today

https://github.com/regnaio/havok-go/blob/main/main.go

Missing import: `go`.`debug`

means that debug (a function?) under namespace go was not registered to importObject

In the code snippet above, there's an example of registering env._emval_get_method_caller and more

I uploaded the .wasm file to https://webassembly.github.io/wabt/demo/wasm2wat/ to get a more readable .wat text showing the namespaces and names we need to register. For example:

(import "env" "_emval_get_method_caller" (func $env._emval_get_method_caller (type $t4)))
(import "env" "_emval_call_void_method" (func $env._emval_call_void_method (type $t6)))
(import "env" "_embind_register_value_array" (func $env._embind_register_value_array (type $t7)))
...

Hopefully this can help