Merge pull request #797 from bushrat011899/wasm32_atomics

Fix `wasm32` with `atomics`
This commit is contained in:
Ashley Mannix 2025-02-05 15:22:56 +10:00 committed by GitHub
commit f175242553
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 2 deletions

View File

@ -133,6 +133,11 @@ jobs:
- name: Fast RNG
run: wasm-pack test --node -- --features "js v4 fast-rng"
- name: +atomics
env:
RUSTFLAGS: '-C target-feature=+atomics'
run: cargo check --target wasm32-unknown-unknown --features "$VERSION_FEATURES $DEP_FEATURES js"
- name: rng-getrandom
env:
RUSTFLAGS: '--cfg getrandom_backend="wasm_js"'

View File

@ -68,7 +68,7 @@ v6 = ["atomic"]
v7 = ["rng"]
v8 = []
js = ["dep:wasm-bindgen"]
js = ["dep:wasm-bindgen", "dep:js-sys"]
rng = ["dep:getrandom"]
rng-getrandom = ["rng", "dep:getrandom", "uuid-rng-internal-lib", "uuid-rng-internal-lib/getrandom"]
@ -173,6 +173,11 @@ version = "0.6"
version = "0.2"
optional = true
# Private
[target.'cfg(all(target_arch = "wasm32", target_vendor = "unknown", target_os = "unknown", target_feature = "atomics"))'.dependencies.js-sys]
version = "0.3"
optional = true
[dev-dependencies.bincode]
version = "1.0"

View File

@ -244,6 +244,9 @@ mod imp {
*/
use wasm_bindgen::{prelude::wasm_bindgen, JsValue};
#[cfg(target_feature = "atomics")]
use core::convert::TryInto;
// Maximum buffer size allowed in `Crypto.getRandomValuesSize` is 65536 bytes.
// See https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
@ -287,7 +290,7 @@ mod imp {
return false;
}
sub_buf.copy_to_uninit(chunk);
sub_buf.copy_to(chunk);
}
true