deislabs / wagi

Write HTTP handlers in WebAssembly with a minimal amount of work
Apache License 2.0
889 stars 45 forks source link

Failed to parse GoLang WebAssembly module #161

Open k33g opened 2 years ago

k33g commented 2 years ago

When loading a wasm GoLang module (build with TinyGo), I get this error:

Error: failed to parse WebAssembly module

Caused by:
    Invalid input WebAssembly code at offset 294: duplicate import name `wasi_snapshot_preview1::fd_write` already defined

I use wagi v0.6.2 (and it works with v0.4.0)

My source code is:

package main

import "fmt"

func main() {
    fmt.Println("content-type: text/plain;utf-8")
    fmt.Println("")
    fmt.Println("👋 Hello World 🌍")
}
radu-matei commented 2 years ago

Hi, @k33g, thanks a lot for the report! What version of the TinyGo compiler should I use to replicate this?

Thanks!

k33g commented 2 years ago

@radu-matei I use tinygo version 0.21.0 linux/amd64 (using go version go1.17.5 and LLVM version 11.0.0)

technosophos commented 2 years ago

Have you tried running with the wasmtime CLI? I am wondering if the LLVM version is to old.

I pasted your exact code into main.go and then compiled with the following command:

$ tinygo build -o test.wasm -target wasi main.go

Then I used the following modules.toml:

[[module]]
module = "test.wasm"
route = "/"

I ran it with:

wagi -c modules.toml 
No log_dir specified, using temporary directory /var/folders/rk/mkbs8vx12zs0gkm680h_gth00000gn/T/.tmpUebthv for logs
Ready: serving on 127.0.0.1:3000

And hitting it with curl gave me this:

$ curl -v localhost:3000
*   Trying 127.0.0.1:3000...
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET / HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.77.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< content-type: text/plain;utf-8
< content-length: 22
< date: Sat, 05 Mar 2022 00:36:47 GMT
<
👋 Hello World 🌍
* Connection #0 to host localhost left intact

Version of TinyGo:

$ tinygo version
tinygo version 0.22.0 darwin/amd64 (using go version go1.17.6 and LLVM version 13.0.0)
k33g commented 2 years ago

@technosophos I will try, thanks 👍

k33g commented 2 years ago

Sorry @technosophos for the late delay I did tests again:

No log_dir specified, using temporary directory /tmp/.tmpSgTNHp for logs
Error: Failed to compile one or more Wasm modules

Caused by:
    0: Error compiling Wasm module ./hello/main.wasm
    1: failed to parse WebAssembly module
    2: Invalid input WebAssembly code at offset 294: duplicate import name `wasi_snapshot_preview1::fd_write` already defined

And everything is ok with the 0.4.0 version of wagi