Skip to content

Commit 2eedfa6

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 <[email protected]>
1 parent bd0654f commit 2eedfa6

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,23 @@ 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+
components: rust-src
230+
- uses: Swatinem/rust-cache@v1
231+
- name: Build and Link tests (build-std)
232+
# This target is Tier 3, so we have to build libstd ourselves.
233+
# We currently cannot run these tests because wasm-bindgen-test-runner
234+
# does not yet support memory64.
235+
run: cargo test --no-run -Z build-std=std,panic_abort --target=wasm64-unknown-unknown --features=js
236+
220237
wasi-tests:
221238
name: WASI test
222239
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: 6 additions & 4 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
//!
@@ -257,7 +257,8 @@ cfg_if! {
257257
any(target_arch = "x86_64", target_arch = "x86")))] {
258258
#[path = "rdrand.rs"] mod imp;
259259
} else if #[cfg(all(feature = "js",
260-
target_arch = "wasm32", target_os = "unknown"))] {
260+
any(target_arch = "wasm32", target_arch = "wasm64"),
261+
target_os = "unknown"))] {
261262
#[path = "js.rs"] mod imp;
262263
} else if #[cfg(all(target_os = "horizon", target_arch = "arm"))] {
263264
// We check for target_arch = "arm" because the Nintendo Switch also
@@ -266,8 +267,9 @@ cfg_if! {
266267
#[path = "3ds.rs"] mod imp;
267268
} else if #[cfg(feature = "custom")] {
268269
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 \
270+
} else if #[cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"),
271+
target_os = "unknown"))] {
272+
compile_error!("the wasm*-unknown-unknown targets are not supported by \
271273
default, you may need to enable the \"js\" feature. \
272274
For more information see: \
273275
https://docs.rs/getrandom/#webassembly-support");

0 commit comments

Comments
 (0)