Compiling Rust to WebAssembly

#1

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?

0 Likes

#2

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:

0 Likes

#3

Whats the one command to compile Rust to WASM?

0 Likes

#4

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: https://www.hellorust.com/demos/canvas/index.html

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

0 Likes