Skip to content

Commit 680e68f

Browse files
committed
Add wasm64-unknown-unknown support
We can build and link just fine, but we cannot actually run the tests as `wasm-bindgen-test-runner` hasn't yet added support. Signed-off-by: Joe Richey <joerichey@google.com>
1 parent bd0654f commit 680e68f

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

.cargo/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Allow normal use of "cargo run" and "cargo test" on these wasm32 platforms.
22
[target.wasm32-unknown-unknown]
33
runner = 'wasm-bindgen-test-runner'
4+
[target.wasm64-unknown-unknown]
5+
runner = 'wasm-bindgen-test-runner'
46
[target.wasm32-wasi]
57
runner = 'wasmtime'
68

.github/workflows/tests.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,22 @@ jobs:
217217
- name: Test (custom getrandom)
218218
run: cargo test --target=wasm32-unknown-unknown --features=custom
219219

220+
wasm64-tests:
221+
name: WASM memory64
222+
runs-on: ubuntu-latest
223+
steps:
224+
- uses: actions/checkout@v2
225+
- uses: actions-rs/toolchain@v1
226+
with:
227+
profile: minimal
228+
toolchain: nightly
229+
- uses: Swatinem/rust-cache@v1
230+
- name: Build and Link tests (build-std)
231+
# This target is Tier 3, so we have to build libstd ourselves.
232+
# We currently cannot run these tests because wasm-bindgen-test-runner
233+
# does not yet support memory64.
234+
run: cargo test --no-run -Z build-std=std,panic_abort --target=wasm64-unknown-unknown --features=js
235+
220236
wasi-tests:
221237
name: WASI test
222238
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ libc = { version = "0.2.120", default-features = false }
2323
[target.'cfg(target_os = "wasi")'.dependencies]
2424
wasi = "0.11"
2525

26-
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
26+
[target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown"))'.dependencies]
2727
wasm-bindgen = { version = "0.2.62", default-features = false, optional = true }
2828
js-sys = { version = "0.3", optional = true }
29-
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
29+
[target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown"))'.dev-dependencies]
3030
wasm-bindgen-test = "0.3.18"
3131

3232
[features]
3333
# Implement std-only traits for getrandom::Error
3434
std = []
3535
# Feature to enable fallback RDRAND-based implementation on x86/x86_64
3636
rdrand = []
37-
# Feature to enable JavaScript bindings on wasm32-unknown-unknown
37+
# Feature to enable JavaScript bindings on wasm*-unknown-unknown
3838
js = ["wasm-bindgen", "js-sys"]
3939
# Feature to enable custom RNG implementations
4040
custom = []

src/lib.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
//! | ESP-IDF | `*‑espidf` | [`esp_fill_random`]
3131
//! | Emscripten | `*‑emscripten` | `/dev/random` (identical to `/dev/urandom`)
3232
//! | WASI | `wasm32‑wasi` | [`random_get`]
33-
//! | Web Browser and Node.js | `wasm32‑*‑unknown` | [`Crypto.getRandomValues`] if available, then [`crypto.randomFillSync`] if on Node.js, see [WebAssembly support]
33+
//! | Web Browser and Node.js | `wasm*‑*‑unknown` | [`Crypto.getRandomValues`] if available, then [`crypto.randomFillSync`] if on Node.js, see [WebAssembly support]
3434
//! | SOLID | `*-kmc-solid_*` | `SOLID_RNG_SampleRandomBytes`
3535
//! | Nintendo 3DS | `armv6k-nintendo-3ds` | [`getrandom`][1]
3636
//!
@@ -256,21 +256,25 @@ cfg_if! {
256256
} else if #[cfg(all(feature = "rdrand",
257257
any(target_arch = "x86_64", target_arch = "x86")))] {
258258
#[path = "rdrand.rs"] mod imp;
259-
} else if #[cfg(all(feature = "js",
260-
target_arch = "wasm32", target_os = "unknown"))] {
261-
#[path = "js.rs"] mod imp;
259+
} else if #[cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"),
260+
target_os = "unknown"))] {
261+
cfg_if! {
262+
if #[cfg(feature = "js")] {
263+
#[path = "js.rs"] mod imp;
264+
} else {
265+
compile_error!("the wasm*-unknown-unknown targets are not \
266+
supported by default, you may need to enable \
267+
the \"js\" feature. For more information see: \
268+
https://docs.rs/getrandom/#webassembly-support");
269+
}
270+
}
262271
} else if #[cfg(all(target_os = "horizon", target_arch = "arm"))] {
263272
// We check for target_arch = "arm" because the Nintendo Switch also
264273
// uses Horizon OS (it is aarch64).
265274
mod util_libc;
266275
#[path = "3ds.rs"] mod imp;
267276
} else if #[cfg(feature = "custom")] {
268277
use custom as imp;
269-
} else if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
270-
compile_error!("the wasm32-unknown-unknown target is not supported by \
271-
default, you may need to enable the \"js\" feature. \
272-
For more information see: \
273-
https://docs.rs/getrandom/#webassembly-support");
274278
} else {
275279
compile_error!("target is not supported, for more information see: \
276280
https://docs.rs/getrandom/#unsupported-targets");

0 commit comments

Comments
 (0)