Compiling Rust to WebAssembly


I want to make a game using Armory using WebAssembly Rust as shown in the link.

I believe I have to first compile Rust to WebAssembly then I can execute the code.

Not finding a very good source on how to compile from Rust to WebAssembly. I have already installed wasm by typing on cmd cargo install wasm-pack on Windows.

Now what do I do from here? How do I compile Rust to WASM?



The Rust & WebAssembly working group has extensive material to get you started with it. Check out the book on Rust :crab: and WebAssembly :spider_web:



Whats the one command to compile Rust to WASM?



cargo build --release --target wasm32-unknown-unknown after you’ve installed WASM target with rustup target add wasm32-unknown-unknown. But you will have to manually mark functions with pub extern and #[no_mangle], and write a certain amount of JS boilerplate. See for example this small demo:

But probably you don’t want such low-level approach, if so follow the link posted by @jer.