wagi icon indicating copy to clipboard operation
wagi copied to clipboard

Failed to parse GoLang WebAssembly module

Open k33g opened this issue 3 years ago • 5 comments

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 🌍")
}

k33g avatar Feb 15 '22 20:02 k33g

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

Thanks!

radu-matei avatar Feb 15 '22 20:02 radu-matei

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

k33g avatar Feb 16 '22 12:02 k33g

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)

technosophos avatar Mar 05 '22 00:03 technosophos

@technosophos I will try, thanks 👍

k33g avatar Mar 05 '22 11:03 k33g

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

  • wagi: 0.8.1
  • tinygo version 0.21.0 linux/amd64 (using go version go1.17.5 and LLVM version 11.0.0)
  • I ran the wasm module with wasmtime: no problem ✅
  • I try again with wagi:
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

k33g avatar Apr 08 '22 13:04 k33g