Skip to content

Enable getrandom support for Emscripten - #2877

Open
guybedford wants to merge 1 commit into
briansmith:mainfrom
guybedford:emscripten
Open

Enable getrandom support for Emscripten#2877
guybedford wants to merge 1 commit into
briansmith:mainfrom
guybedford:emscripten

Conversation

@guybedford

Copy link
Copy Markdown

This enables SystemRandom on wasm32-unknown-emscripten.

getrandom 0.4 implements Emscripten via libc getentropy, which Emscripten's runtime backs with crypto.getRandomValues, so this is the environment's CSPRNG rather than a custom or rdrand implementation, matching the criterion for the existing target_os list.

  • Adds target_os = "emscripten" to the SystemRandom cfg in src/rand.rs.

No build.rs changes were needed; the existing wasm32 C build works as-is with CC=emcc AR=emar.

Tested locally with Emscripten 6.0.10 and Node 22: cargo test --target wasm32-unknown-emscripten with CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_RUNNER=node passes the full suite including rand_tests and doctests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant