wasm4: Can't run Go template

Steps to reproduce:

  1. Create new Go template with w4 new foobar --go
  2. Build it: make
  3. Run it: w4 run build/cart.wasm
  4. See in the console:
LinkError: WebAssembly.instantiate(): Import #0 module="env" function="tinygo_getCurrentStackPointer" error: function import requires a callable

Environment:

  • Fedora 37
  • wasm4 version 2.5.3
  • tinygo version 0.26.0 linux/amd64 (using go version go1.19.3 and LLVM version 15.0.0)

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

ok so for now here is how to use wasm-4 with go without docker image

  1. installing proper version of tinygo (0.21.0) https://github.com/tinygo-org/tinygo/releases/tag/v0.21.0

  2. installing proper go version (1.17) !!! upd. for go versioning it is better to use https://github.com/moovweb/gvm if you use gvm, skip all things related to go and go version (2. 4.) !!!

I had go 1.22.1 installed globally. I installed the second version of go: run: go install golang.org/dl/go1.17@latest find your GOPATH with go env explicitly add GOPATH/bin path to the ~/.bashrc It is needed because go install installs go versions in the gopath/bin folder run: go1.17 download

  1. install wasm-opt https://github.com/WebAssembly/binaryen/releases just unpack the archive and add /bin to the path

  2. run go1.17 env and add to the path its GOROOT and GOPATH

At the end you will have your ~/.bashrc something similar to this:

export PATH=$PATH:/home/ryzh/Downloads/Programs/w4/w4-linux
export PATH=$PATH:/home/ryzh/go/bin
export PATH=$PATH:/home/ryzh/Downloads/Programs/w4/binaryen-version_117/bin
export GOROOT=/home/ryzh/sdk/go1.17
export GOPATH=/home/ryzh/go

Now you can run w4 commands and all will (hopefully) work.

BigAngryBob ran into other issues with the tinygo. Tinygo was invoking wasm-opt on its own, but not providing --enable-bulk-memory.

[wasm-validator error in function 0] unexpected false: Bulk memory operations require bulk memory [--enable-bulk-memory], on

His versions:

% w4 --version
2.5.4
% tinygo version
tinygo version 0.27.0 darwin/amd64 (using go version go1.20.4 and LLVM version 15.0.0)
% wasm-opt --version
wasm-opt version 113

It seems that the problem with the latest versions of Go and TinyGo is still in the incorrect target.json. With these settings, Wasm-4 works for me without errors. In my case, versions Go 1.22.2 and TinyGo 0.31.2

target.json content: { “llvm-target”: “wasm32-unknown-unknown”, “cpu”: “generic”, “features”: “+mutable-globals,+nontrapping-fptoint,+sign-ext,+bulk-memory”, “build-tags”: [ “tinygo.wasm”, “wasm_unknown” ], “goos”: “linux”, “goarch”: “arm”, “linker”: “wasm-ld”, “rtlib”: “compiler-rt”, “scheduler”: “none”, “cflags”: [ “-mno-bulk-memory”, “-mnontrapping-fptoint”, “-msign-ext” ], “ldflags”: [ “–allow-undefined”, “–no-demangle”, “–import-memory”, “–initial-memory=65536”, “–max-memory=65536”, “–stack-first”, “–no-entry”, “-zstack-size=14752” ] }

This is still an issue, was trying the same thing and same error on the console. Any leads?

Hi, thanks for reporting this!

I’m actually not able to repro, but I wonder if something changed with the tinygo’s default wasm.json in 0.26, and we need to mirror any changes into the wasm4 project’s target.json. Eg: default-stack-size looks suspicious.