Skip to content

Commit

Permalink
Auto merge of #107221 - kleisauke:getentropy-emscripten, r=ChrisDenton
Browse files Browse the repository at this point in the history
Use `getentropy()` instead of `/dev/urandom` on Emscripten

`/dev/urandom` is usually available on Emscripten, except when using
the special `NODERAWFS` filesystem backend, which replaces all normal
filesystem access with direct Node.js operations.

Since this filesystem backend directly access the filesystem on the
OS, it is not recommended to depend on `/dev/urandom`, especially
when trying to run the Wasm binary on OSes that are not Unix-based.

This can be considered a non-functional change, since Emscripten
implements `/dev/urandom` in the same way as `getentropy()` when not
linking with `-sNODERAWFS`.
  • Loading branch information
bors committed Mar 30, 2023
2 parents 2fb0e8d + 7b40eb7 commit 1033857
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions library/std/src/sys/unix/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub fn hashmap_random_keys() -> (u64, u64) {
not(target_os = "netbsd"),
not(target_os = "fuchsia"),
not(target_os = "redox"),
not(target_os = "vxworks")
not(target_os = "vxworks"),
not(target_os = "emscripten")
))]
mod imp {
use crate::fs::File;
Expand Down Expand Up @@ -174,7 +175,7 @@ mod imp {
}
}

#[cfg(target_os = "openbsd")]
#[cfg(any(target_os = "openbsd", target_os = "emscripten"))]
mod imp {
use crate::sys::os::errno;

Expand Down
4 changes: 2 additions & 2 deletions src/ci/docker/scripts/emscripten.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ exit 1

git clone https://github.com/emscripten-core/emsdk.git /emsdk-portable
cd /emsdk-portable
hide_output ./emsdk install 1.39.20
./emsdk activate 1.39.20
hide_output ./emsdk install 2.0.5
./emsdk activate 2.0.5

0 comments on commit 1033857

Please sign in to comment.