Skip to content

Commit c4a27ca

Browse files
committed
Add wasm32v1-none support
1 parent 1fc27b1 commit c4a27ca

File tree

7 files changed

+35
-24
lines changed

7 files changed

+35
-24
lines changed

.cargo/config.toml

+2
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.wasm32v1-unknown]
5+
runner = 'wasm-bindgen-test-runner'
46
[target.wasm32-wasip1]
57
runner = 'wasmtime'
68
[target.wasm32-wasip2]

.github/workflows/tests.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,15 @@ jobs:
257257
- name: Test (Node)
258258
env:
259259
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
260-
run: wasm-pack test --node
260+
run: wasm-pack test --node -- --features std
261261
- name: Test (Firefox)
262262
env:
263263
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js" --cfg getrandom_browser_test
264-
run: wasm-pack test --headless --firefox
264+
run: wasm-pack test --headless --firefox -- --features std
265265
- name: Test (Chrome)
266266
env:
267267
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js" --cfg getrandom_browser_test
268-
run: wasm-pack test --headless --chrome
268+
run: wasm-pack test --headless --chrome -- --features std
269269

270270
wasi:
271271
name: WASI

.github/workflows/workspace.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
# Fixed Nigthly version is used to prevent
2424
# CI failures which are not relevant to PR changes
2525
# on introduction of new Clippy lints.
26-
toolchain: nightly-2024-10-08
26+
toolchain: nightly-2024-10-12
2727
components: clippy,rust-src
2828
- name: std feature
2929
run: cargo clippy --features std
@@ -49,6 +49,10 @@ jobs:
4949
env:
5050
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
5151
run: cargo clippy -Zbuild-std --target wasm32-unknown-unknown
52+
- name: Web WASMv1 (wasm_js.rs)
53+
env:
54+
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
55+
run: cargo clippy -Zbuild-std=panic_abort,core,alloc --target wasm32v1-none
5256
- name: Linux (linux_android.rs)
5357
env:
5458
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="linux_getrandom"

Cargo.toml

+10-5
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ wasi = { version = "0.13", default-features = false }
6363
windows-targets = "0.52"
6464

6565
# wasm_js
66-
[target.'cfg(all(getrandom_backend = "wasm_js", any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown"))'.dependencies]
66+
[target.'cfg(all(getrandom_backend = "wasm_js", any(target_arch = "wasm32", target_arch = "wasm64"), any(target_os = "unknown", target_os = "none")))'.dependencies]
6767
wasm-bindgen = { version = "0.2.89", default-features = false }
68-
js-sys = "0.3"
69-
[target.'cfg(all(getrandom_backend = "wasm_js", getrandom_browser_test, target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
70-
wasm-bindgen-test = "0.3.39"
68+
js-sys = { version = "0.3", default-features = false }
69+
[target.'cfg(all(getrandom_backend = "wasm_js", getrandom_browser_test, target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))'.dev-dependencies]
70+
wasm-bindgen-test = { version = "0.3.39", default-features = false }
7171

7272
[features]
7373
# Implement std::error::Error for getrandom::Error and
7474
# use std to retrieve OS error descriptions
75-
std = []
75+
std = ["wasm-bindgen/std", "js-sys/std", "wasm-bindgen-test/std"]
7676
# Unstable feature to support being a libstd dependency
7777
rustc-dep-of-std = ["compiler_builtins", "core"]
7878

@@ -99,3 +99,8 @@ pre-build = [
9999
"rm base.tar.xz",
100100
"rm -rf /tmp/netbsd",
101101
]
102+
103+
[patch.crates-io]
104+
js-sys = { git = "https://github.com/daxpedda/wasm-bindgen", branch = "web-time" }
105+
wasm-bindgen = { git = "https://github.com/daxpedda/wasm-bindgen", branch = "web-time" }
106+
wasm-bindgen-test = { git = "https://github.com/daxpedda/wasm-bindgen", branch = "web-time" }

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ Pull Requests that add support for new targets to `getrandom` are always welcome
7676
`getrandom` also provides optional (opt-in) backends, which allow users to customize the source
7777
of randomness based on their specific needs:
7878

79-
| Backend name | Target | Target Triple | Implementation
80-
| ----------------- | -------------------- | -------------------- | --------------
81-
| `linux_getrandom` | Linux, Android | `*‑linux‑*` | [`getrandom`][1] system call (without `/dev/urandom` fallback). Bumps minimum supported Linux kernel version to 3.17 and Android API level to 23 (Marshmallow).
82-
| `linux_rustix` | Linux, Android | `*‑linux‑*` | Same as `linux_getrandom`, but uses [`rustix`] instead of `libc`.
83-
| `rdrand` | x86, x86-64 | `x86_64-*`, `i686-*` | [`RDRAND`] instruction
84-
| `rndr` | AArch64 | `aarch64-*` | [`RNDR`] register
85-
| `esp_idf` | ESP-IDF | `*‑espidf` | [`esp_fill_random`]. WARNING: can return low-quality entropy without proper hardware configuration!
86-
| `wasm_js` | Web Browser, Node.js | `wasm*‑*‑unknown` | [`Crypto.getRandomValues`] if available, then [`crypto.randomFillSync`] if on Node.js (see [WebAssembly support])
87-
| `custom` | All targets | `*` | User-provided custom implementation (see [custom backend])
79+
| Backend name | Target | Target Triple | Implementation
80+
| ----------------- | -------------------- | ---------------------------------- | --------------
81+
| `linux_getrandom` | Linux, Android | `*‑linux‑*` | [`getrandom`][1] system call (without `/dev/urandom` fallback). Bumps minimum supported Linux kernel version to 3.17 and Android API level to 23 (Marshmallow).
82+
| `linux_rustix` | Linux, Android | `*‑linux‑*` | Same as `linux_getrandom`, but uses [`rustix`] instead of `libc`.
83+
| `rdrand` | x86, x86-64 | `x86_64-*`, `i686-*` | [`RDRAND`] instruction
84+
| `rndr` | AArch64 | `aarch64-*` | [`RNDR`] register
85+
| `esp_idf` | ESP-IDF | `*‑espidf` | [`esp_fill_random`]. WARNING: can return low-quality entropy without proper hardware configuration!
86+
| `wasm_js` | Web Browser, Node.js | `wasm*‑*‑unknown`, `wasm32v1-none` | [`Crypto.getRandomValues`] if available, then [`crypto.randomFillSync`] if on Node.js (see [WebAssembly support])
87+
| `custom` | All targets | `*` | User-provided custom implementation (see [custom backend])
8888

8989
Opt-in backends can be enabled using the `getrandom_backend` configuration flag.
9090
The flag can be set either by specifying the `rustflags` field in

src/backends.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ cfg_if! {
138138
pub use rdrand::*;
139139
} else if #[cfg(all(
140140
any(target_arch = "wasm32", target_arch = "wasm64"),
141-
target_os = "unknown",
141+
any(target_os = "unknown", target_os = "none"),
142142
))] {
143-
compile_error!("the wasm*-unknown-unknown targets are not supported by \
144-
default, you may need to enable the \"wasm_js\" \
145-
configuration flag. For more information see: \
146-
https://docs.rs/getrandom/#webassembly-support");
143+
compile_error!("the wasm*-unknown-unknown and wasm32v1-none targets are \
144+
not supported by default, you may need to enable the \
145+
\"wasm_js\" configuration flag. For more information \
146+
see: https://docs.rs/getrandom/#webassembly-support");
147147
} else {
148148
compile_error!("target is not supported. You may need to define \
149149
a custom backend see: \

src/backends/wasm_js.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{mem::MaybeUninit, thread_local};
66

77
#[cfg(not(all(
88
any(target_arch = "wasm32", target_arch = "wasm64"),
9-
target_os = "unknown",
9+
any(target_os = "unknown", target_os = "none"),
1010
)))]
1111
compile_error!("`wasm_js` backend can be enabled only for OS-less WASM targets!");
1212

0 commit comments

Comments
 (0)