This project uses the Rust GDExtension (via godot-rust) to speed up fragment shader ↔ physics utilities in Godot 4.4.x.
- Rust & Cargo (via rustup)
- LLVM (needed for Web builds and
aubio-sys
) - Emscripten SDK (for
wasm32-unknown-emscripten
)
winget install --id=Rustlang.Rustup -e
nix profile install nixpkgs#rustup <- dumb lol
brew install rustup
rustup-init
source "$HOME/.cargo/env"
Download and install LLVM 18.1.8: https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/LLVM-18.1.8-win64.exe
From the project root:
# Get nightly toolchain
rustup toolchain install nightly
# Add WebAssembly target
rustup target add wasm32-unknown-emscripten
Add this to rust/.cargo/config.toml
:
[target.wasm32-unknown-emscripten]
#linker = "emcc" <- if you installed with package manager, but package managers are dangerous with binaryen versions, see nix note
linker = "C:/Users/pl/emsdk/upstream/emscripten/emcc.bat" <- windows where ever you cloned the emsdk repo
rustflags = [
"--verbose",
"-C", "link-args=-g",
"-C", "link-args=-sSIDE_MODULE=2",
"-C", "link-args=-pthread",
"-C", "target-feature=+atomics",
"-Zlink-native-libraries=no",
"-C", "link-args=-sDISABLE_EXCEPTION_CATCHING=1",
"-C", "llvm-args=-enable-emscripten-cxx-exceptions=0"
]
Note for Nix users: The Nix‐provided
emcc
(required for Godot’s Rust extension) is built against an older Binaryen (v120), which does not support the--enable-bulk-memory-opt
flag needed for threads. To work around this:
Install a newer Binaryen (v121+) in your Nix profile (e.g.
nix profile install nixpkgs#binaryen
).Copy the system‐wide
.emscripten
from/nix/store/...-emscripten-3.1.73/share/emscripten/.emscripten
to~/.emscripten
, and update itsBINARYEN_ROOT
to point at your v123 store path (e.g./nix/store/<hash>-binaryen-123
).Before building for Web, run:
export EM_CONFIG="$HOME/.emscripten"This forces
emcc
to use your v123 Binaryen (which understands bulk‐memory/thread flags) instead of the built‐in v120. Without this override, a release build will fail with “Unknown option ‘--enable-bulk-memory-opt’.”
cd rust
cargo build --lib
cd rust
cargo build --lib --release
cd rust
cargo run --example tests --features tests-only
cd rust
cargo +nightly build -Zbuild-std --target wasm32-unknown-emscripten --lib
cd rust
cargo +nightly build -Zbuild-std --target wasm32-unknown-emscripten --lib --release
The resulting .wasm
and support files are in rust/target/wasm32-unknown-emscripten
.
Before committing, run (in the bath/godot
directory):
gdformat --use-spaces=4 .
Raylib:
nix shell nixpkgs#raylib nixpkgs#pkg-config nixpkgs#cmake \
--command bash -lc '
export RAYLIB_SYS_USE_PKG_CONFIG=1
export PKG_CONFIG_PATH="$(nix eval --raw nixpkgs#raylib)/lib/pkgconfig:$PKG_CONFIG_PATH"
cargo clean
cargo run --example raylib_tests
'