I am trying to compile WASM from go using tinygo for use in go-wasmer. I have the import memory working for AssemblyScript but when I use the flag for the WASM from go and try to create my instance I get this error
Host env initialization error: Missing export memory
Is there a way to manually export memory that will then be replaced by the imported memory?
Here is my target.json
{
"inherits": ["wasm"],
"linker": "wasm-ld",
"libc": "wasi-libc",
"goarch": "wasm",
"cflags": [
"--target=wasm32--wasi",
"--sysroot={root}/lib/wasi-libc/sysroot",
"-Oz"
],
"ldflags": [
"--import-memory",
"--max-memory=1310720",
"--initial-memory=131072"
]
}
Where did you get that
target.json
from, and why do you need it? Just using-target wasi
should give you something that works.But more specifically: the error is telling you that
Missing export memory
, but you're trying to--import-memory
. You can delete the--import-memory
, and the memory import will turn into an export. If that doesn't work, you should probably paste your code setting upgo-wasmer
. Also, have a look atwasmer inspect yourbinary.wasm
, to see what's going on with the list of imports and exports.By the way, by
inherit
ing fromwasm
, you get requirements for nasty Go wasm-js implementation specific imports likeenv
.syscall/js.valueGet
. There are implementations for those (this e.g.), but since you're already usingwasi
, you can justinherit
fromwasi
(and deletegoarch
). Your life will probably be easier.