-
Notifications
You must be signed in to change notification settings - Fork 164
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
load wasm that build with golang #18
Comments
This is likely to be happening because some of the required imports are not present. We probably need to improve the error message to show the detailed error. |
Thanks for the bug report! However, maybe you can find a better definition with package main
import (
"fmt"
wasm "github.com/wasmerio/go-ext-wasm/wasmer"
)
func main() {
bytes, err := wasm.ReadBytes("wa.wasm")
if err != nil {
fmt.Println(err)
return
}
inst, err := wasm.NewInstance(bytes)
if err != nil {
fmt.Println(err)
fmt.Println(wasm.GetLastError())
return
}
defer inst.Close()
} Then I run it with
I suggest to use |
See #29 to see how to import functions in multiple namespaces. |
Hi @Hywan can you provide a quick example how to import functions into multiple namespaces? Like the parent, I tried running a go-compiled "hello world" wasm, and I get the following: Any help would be appreciated. |
You can check https://github.com/wasmerio/go-ext-wasm/blob/722faa9f1b902d404e87c40ea2bb6bdd5e228a51/wasmer/test/imports.go#L36-L52. Basically, it looks like: imports, _ :=
wasm.NewImports().
Namespace("env1").
Append("f", f, C.f).
Append("g", g, C.g).
Namespace("env2").
Append("h", h, C.h)
instance, _ := wasm.NewInstanceWithImports(wasm_bytes, imports)
… Does it help? |
51: test(import) Test that all WAsm types can be used in imported functions r=Hywan a=Hywan Related to #18. Co-authored-by: Ivan Enderlin <[email protected]>
is it not possible for wasmer to parse out the imports when it reads the bytes and creates the instance? our nodejs version is able to load our wasm bytes just fine.. |
It is possible to read the imports and exports from the module. Check the type Module struct {
Exports []ExportDescriptor
Imports []ImportDescriptor
} |
Hello, I am new to wasm and just trying out wasmer go-ext-wasm. Getting the same one
And I see that the issue is closed with that example: imports, _ :=
wasm.NewImports().
Namespace("env1").
Append("f", f, C.f).
Append("g", g, C.g).
Namespace("env2").
Append("h", h, C.h)
instance, _ := wasm.NewInstanceWithImports(wasm_bytes, imports) But I am still not sure how does this help? What are these and where they are coming from? Namespace("env1").
Append("f", f, C.f).
Append("g", g, C.g).
Namespace("env2").
Append("h", h, C.h) Is there anything specific that we need to do before running Go? Tried tinygo and go, both have slightly different errors :| |
The Go compiler emits a WebAssembly module with specific host functions (imports). It is very JavaScript centric. The TinyGo compiler emits a WebAssembly module that works for JS but also other hosts, like a server. See #95, which is likely to help. One question though: What's your usecase to compile Go to Wasm, to then run it in Go? |
Currently writing a side project for my other side project (https://webhookrelay.com/) that will allow users to upload their wasm code snippets to modify webhooks before they are forwarded to their final destination. Initially started just with Lua but wasm seems so much more interesting, therefore after some time I decided to try out wasmer :) For example to modify webhook method when it comes as a PUT request to POST: extern "C" {
fn ext_set_request_method(ptr: *const u8, len: usize);
}
#[no_mangle]
pub extern fn handleRequest(_ptr: i32, _len: i32) {
let method = "POST";
unsafe {
ext_set_request_method(method.as_ptr(), method.len());
}
} As a Go developer myself I would prefer using Go, although Rust is also fun, not sure about other people though :) |
@Hywan Hello! So if I understand correctly there's no way to import a .wasm file that was compiled from Go. Is that right? |
Thanks for the bug report!
Describe the bug
when I build wasm with go and wasm.NewInstance from the wasm bin, error result with:
A clear and concise description of what the bug is.
Steps to reproduce
GOARCH=wasm GOOS=js go build -o wa.wasm wa.go
cat wa.go:
go build main.go
cat main.go:
Failed to compile the module.
The text was updated successfully, but these errors were encountered: