1

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"
    ]
}

1 Answers1

1

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 up go-wasmer. Also, have a look at wasmer inspect yourbinary.wasm, to see what's going on with the list of imports and exports.

By the way, by inheriting from wasm, you get requirements for nasty Go wasm-js implementation specific imports like env.syscall/js.valueGet. There are implementations for those (this e.g.), but since you're already using wasi, you can just inherit from wasi (and delete goarch). Your life will probably be easier.

Caesar
  • 6,733
  • 4
  • 38
  • 44
  • Do you know if there is a way to limit which memory addresses are available to Go, like some sort of upper bound? I have been using string pointers as returns for my functions in the Go code compiled to WASM and for the most part it works but every now and then I get a string whose pointer is well above the memory limit of the WASM module. – alexpitsikoulis Feb 16 '23 at 00:50
  • Comments are not for additional questions. For one, the likelihood of anybody else seeing this comment is low. Better post this as a separate question. Also: No, I don't know. (But eh, it at least explains what you want the `target.json` for. Memory limits.) – Caesar Feb 16 '23 at 02:42