Skip to content

Commit 3095fdf

Browse files
committed
Add wasm64-unknown-unknown support for wasm_js backend
1 parent 626df8d commit 3095fdf

4 files changed

Lines changed: 19 additions & 13 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ wasip2 = { version = "1", default-features = false }
8686
wasip3 = ">=0.3, <=0.4"
8787

8888
# wasm_js
89-
[target.'cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))'.dependencies]
89+
[target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), any(target_os = "unknown", target_os = "none")))'.dependencies]
9090
wasm-bindgen = { version = "0.2.98", default-features = false, optional = true }
91-
[target.'cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"), target_feature = "atomics"))'.dependencies]
91+
[target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), any(target_os = "unknown", target_os = "none"), target_feature = "atomics"))'.dependencies]
9292
js-sys = { version = "0.3.77", default-features = false, optional = true }
93-
[target.'cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))'.dev-dependencies]
93+
[target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), any(target_os = "unknown", target_os = "none")))'.dev-dependencies]
9494
wasm-bindgen-test = "0.3"
9595

9696
[lints.rust.unexpected_cfgs]

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ Pull Requests that add support for new targets to `getrandom` are always welcome
6767

6868
### WebAssembly support
6969

70-
This crate fully supports the [WASI] and [Emscripten] targets. However,
71-
the `wasm32-unknown-unknown` target (i.e. the target used by `wasm-pack`)
72-
is not automatically supported since, from the target name alone, we cannot deduce
70+
This crate fully supports the [WASI] and [Emscripten] targets. However, the `wasm32-unknown-unknown`
71+
and `wasm64-unknown-unknown` targets (i.e. the target used by `wasm-pack`)
72+
are not automatically supported since, from the target name alone, we cannot deduce
7373
which JavaScript interface should be used (or if JavaScript is available at all).
7474

75-
We do not include support for this target in the default configuration because our JS backend
75+
We do not include support for these targets in the default configuration because our JS backend
7676
(supporting web browsers, web workers and Node.js v19 or later) requires [`wasm-bindgen`],
7777
**bloating `Cargo.lock`** and **potentially breaking builds** on non-web WASM platforms.
7878

79-
To enable `getrandom`'s functionality on `wasm32-unknown-unknown` using
79+
To enable `getrandom`'s functionality on `wasm32/64-unknown-unknown` using
8080
[`Crypto.getRandomValues`] via [`wasm-bindgen`], enable the `wasm_js` crate feature.
8181

8282
WARNING: We strongly recommend against enabling this feature in libraries (except for tests)

src/backends.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,18 @@ cfg_if! {
167167
} else if #[cfg(all(target_arch = "x86_64", target_env = "sgx"))] {
168168
mod rdrand;
169169
pub use rdrand::*;
170-
} else if #[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))] {
170+
} else if #[cfg(all(
171+
any(target_arch = "wasm32", target_arch = "wasm64"),
172+
any(target_os = "unknown", target_os = "none"),
173+
))] {
171174
cfg_if! {
172175
if #[cfg(feature = "wasm_js")] {
173176
mod wasm_js;
174177
pub use wasm_js::*;
175178
} else {
176179
compile_error!(concat!(
177-
"The wasm32-unknown-unknown targets are not supported by default; \
178-
you may need to enable the \"wasm_js\" crate feature. \
180+
"The wasm32-unknown-unknown and wasm64-unknown-unknown targets are not supported
181+
by default; you may need to enable the \"wasm_js\" crate feature. \
179182
For more information see: \
180183
https://docs.rs/getrandom/", env!("CARGO_PKG_VERSION"), "/#webassembly-support"
181184
));

src/backends/wasm_js.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ use core::mem::MaybeUninit;
44

55
pub use crate::util::{inner_u32, inner_u64};
66

7-
#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"))))]
7+
#[cfg(not(all(
8+
any(target_arch = "wasm32", target_arch = "wasm64"),
9+
any(target_os = "unknown", target_os = "none"),
10+
)))]
811
compile_error!("`wasm_js` backend can be enabled only for OS-less WASM targets!");
912

10-
use wasm_bindgen::{prelude::wasm_bindgen, JsValue};
13+
use wasm_bindgen::{JsValue, prelude::wasm_bindgen};
1114

1215
// Maximum buffer size allowed in `Crypto.getRandomValuesSize` is 65536 bytes.
1316
// See https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues

0 commit comments

Comments
 (0)