Skip to content

Instantly share code, notes, and snippets.

@awwsmm
Created April 4, 2024 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awwsmm/0c98f4c1bfe88ffcf6b33b4c3ad28fd0 to your computer and use it in GitHub Desktop.
Save awwsmm/0c98f4c1bfe88ffcf6b33b4c3ad28fd0 to your computer and use it in GitHub Desktop.
Bash script to compile Rust code to WASM and generate JavaScript bindings
#!/usr/bin/env bash
# $1: package name from Cargo.toml
# run with e.g.: bash build-and-bind.sh flappy-bevy
# build
rustup target add wasm32-unknown-unknown
cargo build --release --target wasm32-unknown-unknown
# bind
cargo install -q wasm-bindgen-cli
wasm-bindgen --out-dir target --target web target/wasm32-unknown-unknown/release/"$1".wasm
# ...and then run with live-server
cargo install live-server
live-server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment