英文:
How do I make --import-memory work for WASM compiled by tinygo
问题
我正在尝试使用tinygo从go编译WASM,以便在go-wasmer中使用。我已经成功导入了AssemblyScript的内存,但是当我使用来自go的WASM标志并尝试创建实例时,我遇到了以下错误:
Host env initialization error: Missing export memory
有没有办法手动导出内存,然后再由导入的内存替换掉?
这是我的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"
]
}
英文:
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
得分: 1
你从哪里得到了target.json
,为什么需要它?只使用-target wasi
应该可以得到一个可用的结果。
但更具体地说,错误提示是告诉你Missing export memory
,但你正在尝试使用--import-memory
。你可以删除--import-memory
,内存导入将变为导出。如果这样还不行,你应该将设置go-wasmer
的代码粘贴出来。另外,使用wasmer inspect yourbinary.wasm
查看导入和导出列表的情况。
顺便说一下,通过从wasm
继承,你会得到对恶心的Go wasm-js实现特定导入(例如env.syscall/js.valueGet
)的要求。有一些实现可以解决这些问题(例如这个),但由于你已经在使用wasi
,你可以直接从wasi
继承(并删除goarch
)。这样你的生活可能会更轻松一些。
英文:
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 inherit
ing 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论