7

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

项目编译。当我在 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" 
4

1 回答 1

3

这篇博文提供了一个我认为也可以应用于您的案例的解决方案:

据我所知,没有办法通过货物传递大多数链接器参数。相反,通过指定一个自定义链接器来绕过限制,该链接器实际上是一个包装真实链接器的 shell 脚本。

使用适当的选项创建一个调用 emscripten 的 shell 脚本emcc_link

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

(您可能需要其他选项才能使其正常工作。请查看博客文章了解详细信息。)

并通过编辑/创建指定将其用于您的项目.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.

免责声明:我没有尝试过任何这些。

于 2017-08-22T06:50:15.447 回答