From 10366b642c29d39ee27b6dadd3ffe054245c5500 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Tue, 29 Jul 2025 18:14:46 -0500 Subject: [PATCH] Add wasm-specific feature for RNG child dependency The `rand` crate eventually depends on `getrandom` which requires a different feature set when running in the browser. WASM has no OS, and so no RNG provider... but the browser, specifically, has one that the JavaScript runtime can touch. Enabling the "wasm_js" feature on `getrandom` allowes it to use this backend. An extra config option must *also* be passed to `rustc`. THis can be set through the environment, or the config.toml. I've chosen the latter so I don't need to think about it very often. --- .cargo/config.toml | 3 +++ Cargo.toml | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..dc0beed --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,3 @@ + +[target.wasm32-unknown-unknown] +rustflags = ["--cfg", "getrandom_backend=\"wasm_js\""] diff --git a/Cargo.toml b/Cargo.toml index f312dc2..dba76f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,6 @@ rand = "0.9.2" [features] dynamic_linking = ["bevy/dynamic_linking"] debug_ui = ["bevy_rapier2d/debug-render-2d"] + +[target.'cfg(target_arch = "wasm32")'.dependencies] +getrandom = { version = "0.3.3", features = ["wasm_js"] }