我有一个正在编译为http://asquera.de/blog/2017-04-10/the-path-to-rust-on-the-web/的webasm的rust项目

项目编译。当我在Chrome Canary中运行它时,它的内存不足,并给了我一个非常有用的错误消息:

abort("Cannot enlarge memory arrays. Either (1) compile with  -s
TOTAL_MEMORY=X  with X higher than the current value 16777216, (2) compile
with  -s ALLOW_MEMORY_GROWTH=1  which allows increasing the size at runtime,
...

问题是,不清楚如何将这些标志传递给rustc/构建工具链。

既不设置EMMAKEN_CFLAGS也不执行以下工作:
cargo  rustc -v --target=wasm32-unknown-emscripten --release -- -Clink-args="-s TOTAL_MEMORY=33554432"

最佳答案

This博客文章提供了一种解决方案,我认为也可以应用于您的情况:



创建一个像emcc_link这样的shell脚本,该脚本使用适当的选项调用emscripten:

emcc "-s" "TOTAL_MEMORY=33554432" $@

(您可能需要其他选项才能使其正常工作。有关详细信息,请检查blog post。)

并通过编辑/创建 .cargo/config 指定将其用于您的项目:
[target.wasm32-unknown-emscripten]
linker = "/your/project/dir/emcc_sdl"

[target.asmjs-unknown-emscripten]
linker = "/your/project/dir/emcc_sdl"

我无情地假设构建环境是Linux或类似的系统。在Windows上,shell脚本可能应该是批处理脚本,我不确定.cargo/config是否有任何区别。

免责声明:我没有尝试过任何一种方法。

关于rust - rust ,WebAssembly和传递参数以增加总内存,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45807869/

10-12 14:41
查看更多