

You can install bindgen with the following command: cargo install wasm-bindgen-cli

Note that when you update your Rust setup, you’ll want to repeat this process to get the newest wasm-bindgen tool. Instead, the wasm-bindgen program can do the work for you. You could create this by hand, but it’s really tedious. You also need some JavaScript to connect your WASM program to the browser’s execution engine.

Install BindgenĬompiling to WebAssembly isn’t quite enough to make your programs work in your browser. Rust will download and install the current wasm32-unknown-unknown toolchain support for you. Install wasm support on your computer with the following command: rustup target add wasm32-unknown-unknown The Rust install tool ( rustup) can install toolchains for you. The official name of the WASM platform is: wasm32-unknown-unknown. WASM is supported as another platform, so you cross-compile your programs into WASM format. For example, you can make Linux builds of your game without leaving Windows. Cross-compilation allows you to compile programs for a platform other than the one you are currently using. Rust’s cargo system natively supports cross-compilation. You need a recent version of bracket-lib for this article. So with those caveats in mind, let’s get started making your Rust games work in your web browser.īefore you start: Run cargo update on projects you want to publish to the web. It can be running locally, but most browsers refuse to execute WASM programs loaded locally with file: links. This is alleviated by embedding your assets into your program. WASM doesn’t have a native filesystem, so loading assets from your webserver is difficult.Large games can take a while to download.It works great in Chrome and Firefox, not so well in Safari. This means you can’t take advantage of the multi-threading built into Legion (and similar ECS systems). Threading works differently in a web browser, and was largely disabled in response to the Spectre line of vulnerabilities.With a little bit of automated work to map web assembly bindings to native JavaScript, you can run your games in your browser. Rust natively supports compiling to WebAssembly (aka. One of the great things about using Rust and bracket-lib is that you can compile your games for the web.
