Skip to content

Commit fe86710

Browse files
authored
Properly enable getrandom in nanorand (#8098)
1 parent 17a17f7 commit fe86710

File tree

6 files changed

+21
-2
lines changed

6 files changed

+21
-2
lines changed

.cargo/config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
[alias]
22
xtask = "run -p wgpu-xtask --"
3+
4+
# Needed until https://github.com/rust-random/getrandom/issues/675 is resolved.
5+
[target.wasm32-unknown-unknown]
6+
rustflags = ["--cfg", "getrandom_backend=\"wasm_js\""]

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ jobs:
261261
run: |
262262
set -e
263263
264+
export RUSTFLAGS="$RUSTFLAGS --cfg getrandom_backend=\"wasm_js\""
265+
264266
# build for WebGPU
265267
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} --tests --features glsl,spirv,fragile-send-sync-non-atomic-wasm
266268
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} --tests --features glsl,spirv
@@ -487,6 +489,9 @@ jobs:
487489
- name: Execute tests
488490
run: |
489491
cd wgpu
492+
493+
export RUSTFLAGS="$RUSTFLAGS --cfg getrandom_backend=\"wasm_js\""
494+
490495
wasm-pack test --headless --chrome --no-default-features --features wgsl,webgl,web --workspace
491496
492497
gpu-test:

Cargo.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ env_logger = { version = "0.11", default-features = false }
116116
fern = "0.7"
117117
flume = "0.11"
118118
futures-lite = "2"
119+
getrandom = "0.3"
119120
glam = "0.30"
120121
glob = "0.3"
121122
half = { version = "2.5", default-features = false } # We require 2.5 to have `Arbitrary` support.

examples/features/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ bytemuck.workspace = true
3535
cfg-if.workspace = true
3636
encase = { workspace = true, features = ["glam"] }
3737
flume.workspace = true
38+
getrandom = { workspace = true, features = ["wasm_js"] }
3839
glam = { workspace = true, features = ["bytemuck"] }
3940
ktx2.workspace = true
4041
log.workspace = true
41-
nanorand = { workspace = true, features = ["tls"] }
42+
nanorand = { workspace = true, features = ["getrandom"] }
4243
noise.workspace = true
4344
obj.workspace = true
4445
png.workspace = true

examples/features/src/repeated_compute/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ async fn run() {
1313
let mut numbers = [0u32; 256];
1414
let context = WgpuContext::new(size_of_val(&numbers)).await;
1515

16+
let mut rand = nanorand::WyRand::new();
17+
1618
for _ in 0..10 {
1719
for p in numbers.iter_mut() {
18-
*p = nanorand::tls_rng().generate::<u16>() as u32;
20+
*p = rand.generate::<u16>() as u32;
1921
}
2022

2123
compute(&mut numbers, &context).await;

0 commit comments

Comments
 (0)