Skip to content

Commit a48e020

Browse files
committed
Add wasm32v1-none support
1 parent 37db8c1 commit a48e020

File tree

7 files changed

+28
-17
lines changed

7 files changed

+28
-17
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/workspace.yml

+8
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ jobs:
5757
env:
5858
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js" -Ctarget-feature=+atomics,+bulk-memory
5959
run: cargo clippy -Zbuild-std=core,alloc --target wasm32-unknown-unknown
60+
- name: Web WASMv1 (wasm_js.rs)
61+
env:
62+
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
63+
run: cargo clippy -Zbuild-std=core,alloc --target wasm32v1-none
64+
- name: Web WASMv1 with atomics (wasm_js.rs)
65+
env:
66+
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js" -Ctarget-feature=+atomics,+bulk-memory
67+
run: cargo clippy -Zbuild-std=core,alloc --target wasm32v1-none
6068
- name: Linux (linux_android.rs)
6169
env:
6270
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="linux_getrandom"

Cargo.toml

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

6565
# wasm_js
66-
[target.'cfg(all(getrandom_backend = "wasm_js", target_arch = "wasm32", target_os = "unknown"))'.dependencies]
66+
[target.'cfg(all(getrandom_backend = "wasm_js", target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))'.dependencies]
6767
wasm-bindgen = { version = "0.2.96", default-features = false }
6868
js-sys = { version = "0.3.73", default-features = false }
6969
once_cell = { version = "1", default-features = false }
70-
[target.'cfg(all(getrandom_backend = "wasm_js", getrandom_browser_test, target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
70+
[target.'cfg(all(getrandom_backend = "wasm_js", getrandom_browser_test, target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))'.dev-dependencies]
7171
wasm-bindgen-test = { version = "0.3", default-features = false }
7272

7373
[features]

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 | `wasm32‑unknown‑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 | `wasm32‑unknown‑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-4
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,12 @@ cfg_if! {
150150
pub use rdrand::*;
151151
} else if #[cfg(all(
152152
target_arch = "wasm32",
153-
target_os = "unknown",
153+
any(target_os = "unknown", target_os = "none"),
154154
))] {
155-
compile_error!("the wasm32-unknown-unknown targets are not supported \
156-
by default, you may need to enable the \"wasm_js\" \
157-
configuration flag. For more information see: \
155+
compile_error!("the wasm32-unknown-unknown and wasm32v1-none targets \
156+
are not supported by default, you may need to enable \
157+
the \"wasm_js\" configuration flag. For more \
158+
information see: \
158159
https://docs.rs/getrandom/#webassembly-support");
159160
} else {
160161
compile_error!("target is not supported. You may need to define \

src/backends/wasm_js.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use core::mem::MaybeUninit;
77

88
pub use crate::util::{inner_u32, inner_u64};
99

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

1313
use js_sys::{global, Function, Uint8Array};

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
all(
1616
getrandom_backend = "wasm_js",
1717
any(target_arch = "wasm32", target_arch = "wasm64"),
18-
target_os = "unknown",
18+
any(target_os = "unknown", target_os = "none"),
1919
not(feature = "std"),
2020
target_feature = "atomics"
2121
),

0 commit comments

Comments
 (0)