【问题标题】:rust, WebAssembly, and passing arguments for increased total memoryrust、WebAssembly 和传递参数以增加总内存
【发布时间】:2017-08-22 02:04:08
【问题描述】:

我有一个 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" 

【问题讨论】:

    标签: rust asm.js webassembly


    【解决方案1】:

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

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

    创建一个类似于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 是否有任何差异。

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

    【讨论】:

    • 这似乎不起作用。但需要做一些挖掘才能确定。特别是,似乎从未使用项目目录中的 .cargo/config 调用特殊链接器
    • 这很难调试。只要是有效的 Toml,cargo 不会抱怨配置文件中的无效设置。如果您使用 -C linker= 将链接器直接传递给 rustc 会发生什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-07
    • 1970-01-01
    • 2019-11-03
    • 1970-01-01
    • 1970-01-01
    • 2013-03-21
    • 2016-07-23
    相关资源
    最近更新 更多