rust, WebAssembly, and passing arguments for increased total memory

I have a rust project I am compiling to webasm per http://asquera.de/blog/2017-04-10/the-path-to-rust-on-the-web/

Project compiles. When I run it in Chrome Canary, it runs out of memory and gives me a very helpful error message:

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, 
...

Problem is, its not clear how to pass those flags to rustc / the build tool chain.

Neither setting EMMAKEN_CFLAGS or the following work:

cargo  rustc -v --target=wasm32-unknown-emscripten --release -- -Clink-args="-s TOTAL_MEMORY=33554432" 

This blog post offers a solution that I think can be applied in your case too:

As best as I can tell there is no way to pass most linker arguments through cargo. Instead, hack around the limitation by specifying a custom linker that is actually a shell script wrapping the real linker.

Create a shell script like emcc_link that calls emscripten with the appropriate options:

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

(You may need other options to make it work. Check the blog post for details.)

And specify to use it for your project by editing/creating .cargo/config :

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

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

I ruthlessly assumed the build environment is Linux or the like. On Windows the shell script should probably be a batch script and I'm not sure if there are any differences in .cargo/config .

Disclaimer: I have not tried any of this.

链接地址: http://www.djcxy.com/p/40260.html

上一篇: 在同一端口上运行websocket和http服务器(Rust,hyper)

下一篇: 生锈,WebAssembly和传递参数以增加总内存