Skip to content

Commit b564e9e

Browse files
committed
Add no_std support for Web
1 parent 5fbfd2e commit b564e9e

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

.github/workflows/build.yml

+34
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,40 @@ jobs:
131131
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="rdrand"
132132
run: cargo build --features=std
133133

134+
web:
135+
name: ${{ matrix.target.description }} ${{ matrix.feature.description }} ${{ matrix.atomic.description }}
136+
runs-on: ubuntu-24.04
137+
env:
138+
RUSTFLAGS: --cfg getrandom_backend="wasm_js" ${{ matrix.atomic.flags }}
139+
strategy:
140+
fail-fast: false
141+
matrix:
142+
target: [
143+
{ description: Web, target: wasm32-unknown-unknown },
144+
{ description: WasmV1, target: wasm32v1-none },
145+
]
146+
feature: [
147+
{ description: no_std, feature: "", build-std: "core,alloc", std: false },
148+
{ feature: --features std, build-std: "panic_abort,std", std: true },
149+
]
150+
atomic: [
151+
{ flags: "" },
152+
{ description: with Atomics, flags: "-Ctarget-feature=+atomics,bulk-memory" },
153+
]
154+
exclude:
155+
- target: { target: wasm32v1-none }
156+
feature: { std: true }
157+
steps:
158+
- uses: actions/checkout@v4
159+
- uses: dtolnay/rust-toolchain@master
160+
with:
161+
targets: ${{ matrix.target.target }}
162+
toolchain: nightly-2024-10-24
163+
components: rust-src
164+
- uses: Swatinem/rust-cache@v2
165+
- name: Build
166+
run: cargo build --target ${{ matrix.target.target }} ${{ matrix.feature.feature }} -Zbuild-std=${{ matrix.feature.build-std }}
167+
134168
rdrand:
135169
name: RDRAND
136170
runs-on: ubuntu-24.04

.github/workflows/tests.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -245,33 +245,33 @@ jobs:
245245
- name: Test (Node)
246246
env:
247247
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
248-
run: wasm-pack test --node
248+
run: wasm-pack test --node -- --features std
249249
- name: Test (Firefox)
250250
env:
251251
WASM_BINDGEN_USE_BROWSER: 1
252252
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
253-
run: wasm-pack test --headless --firefox
253+
run: wasm-pack test --headless --firefox -- --features std
254254
- name: Test (Chrome)
255255
env:
256256
WASM_BINDGEN_USE_BROWSER: 1
257257
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
258-
run: wasm-pack test --headless --chrome
258+
run: wasm-pack test --headless --chrome -- --features std
259259
- name: Test (dedicated worker)
260260
env:
261261
WASM_BINDGEN_USE_DEDICATED_WORKER: 1
262262
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
263-
run: wasm-pack test --headless --firefox
263+
run: wasm-pack test --headless --firefox -- --features std
264264
- name: Test (shared worker)
265265
env:
266266
WASM_BINDGEN_USE_SHARED_WORKER: 1
267267
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
268-
run: wasm-pack test --headless --firefox
268+
run: wasm-pack test --headless --firefox -- --features std
269269
- name: Test (service worker)
270270
env:
271271
WASM_BINDGEN_USE_SERVICE_WORKER: 1
272272
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
273273
# Firefox doesn't support module service workers and therefor can't import scripts
274-
run: wasm-pack test --headless --chrome
274+
run: wasm-pack test --headless --chrome -- --features std
275275

276276
wasi:
277277
name: WASI

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ windows-targets = "0.52"
6565
# wasm_js
6666
[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 }
68-
js-sys = "0.3.73"
68+
js-sys = { version = "0.3.73", default-features = false }
6969
[target.'cfg(all(getrandom_backend = "wasm_js", target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))'.dev-dependencies]
7070
wasm-bindgen-test = "0.3"
7171

0 commit comments

Comments
 (0)