簡體   English   中英

生銹,WebAssembly和傳遞參數以增加總內存

[英]rust, WebAssembly, and passing arguments for increased total memory

我有一個生銹的項目,我正在編寫webasm每http://asquera.de/blog/2017-04-10/the-path-to-rust-on-the-web/

項目編譯。 當我在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" 

這篇博文提供了一個我認為可以在你的案例中應用的解決方案:

盡我所知,沒有辦法通過貨物傳遞大多數鏈接器參數。 相反,通過指定自定義鏈接器來破解限制,該鏈接器實際上是包裝真實鏈接器的shell腳本。

創建一個像emcc_link這樣的shell腳本,它使用適當的選項調用emscripten:

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是否存在任何差異。

免責聲明:我沒有嘗試過這些。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM