Skip to content

A weekend project to learn the Bevy Game Engine, how to implement a custom and rudimentary physics engine using an Entity Component System, and using WASM with Rust.

Notifications You must be signed in to change notification settings

jsimms22/WASM_Rust-N-Body

Repository files navigation

For a detailed write up see the article below by Josh Finnie

https://www.joshfinnie.com/blog/using-webassembly-created-in-rust-for-fast-react-components/

First time set-up for up your local environment step-by-step:

  1. Ensure the Rust application can build independently without errors

    $ cargo build

  2. Add a useful taraget for your build

    $ rustup target add wasm32-unknown-unknown

  3. Build the Rust application to the target that was just added

    $ cargo build --target wasm32-unknown-unknown --release

  4. Install the wasm-bindgen-cli command-line application

    $ cargo install -f wasm-bindgen-cli

  5. Now we can take our WebAssembly code generated by Rust and create a wrapping for the React application

    $ wasm-bindgen target/wasm32-unknown-unknown/release/nbody_wasm.wasm --out-dir build

To build the Rust, WebAssembly, and JavaScript:

$ npm run build

Hosting a Local Server

$ npm run dev

Scripts Embedded in Package.json

"dev": "webpack server",
"build:wasm": "cargo build --target wasm32-unknown-unknown",
"build:bindgen": "wasm-bindgen target/wasm32-unknown-unknown/debug/nbody_wasm.wasm --out-dir build",
"build": "npm run build:wasm && npm run build:bindgen && npx webpack"

Note: if there is an error building the stdweb crate when building the wasm binary, make sure wasm-pack is installed

$ npm install -g wasm-pack

About

A weekend project to learn the Bevy Game Engine, how to implement a custom and rudimentary physics engine using an Entity Component System, and using WASM with Rust.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published