9

I've tried everything in here:

Golang to wasm compilation

And I can't get past:

WebAssembly.instantiate(buffer, {wasi_snapshot_preview1: ""})
WebAssembly.instantiate(buffer, {go: {debug: ""}})

// (i'm making them empty strings just to show I need to add the key but obviously they are not strings.)

i.e. I get errors like:

Failed to load WebAssembly module: TypeError: WebAssembly.instantiate(): Import #0 module="wasi_snapshot_preview1" error: module is not an object or function

or module debug or runtime.resetMemoryDataView or everything in wasm_exec.js

But if I use the simple.wasm from:

https://github.com/inflatablegrade/Extension-with-WASM

it works! That wasm must have been compiled by c or rust and NOT golang? Is there a way to make this work from go?

P.S. that Extension-with-WASM is manifest 2.0 but I got it work with 3.0:

https://github.com/inflatablegrade/Extension-with-WASM/issues/1

Jak2k
  • 57
  • 1
  • 7
Andrew Arrow
  • 4,248
  • 9
  • 53
  • 80
  • I'm not totally sure about this but I believe the WASI snapshot error from Go lang could be because of Go still not supporting WASI (Go 1.21 will support this, in this August https://tip.golang.org/doc/go1.21). – Joy Singh Jul 13 '23 at 19:15
  • ah thank you this helps! – Andrew Arrow Jul 13 '23 at 19:17

1 Answers1

0

try compiling with -Oz flag GOOS=js GOARCH=wasm go build -o main.wasm -ldflags="-s -w" -gcflags="-trimpath=${PWD}" -trimpath .

and build GOOS=js GOARCH=wasm go build -o main.wasm -tags=js_wasm_profiling -ldflags="-s -w" -gcflags="-trimpath=${PWD}" -trimpath .