Skip to content

Commit

Permalink
Add no_std support for Web
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Dec 5, 2024
1 parent 5fbfd2e commit ac1d843
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,33 +245,33 @@ jobs:
- name: Test (Node)
env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
run: wasm-pack test --node
run: wasm-pack test --node -- --features std
- name: Test (Firefox)
env:
WASM_BINDGEN_USE_BROWSER: 1
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
run: wasm-pack test --headless --firefox
run: wasm-pack test --headless --firefox -- --features std
- name: Test (Chrome)
env:
WASM_BINDGEN_USE_BROWSER: 1
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
run: wasm-pack test --headless --chrome
run: wasm-pack test --headless --chrome -- --features std
- name: Test (dedicated worker)
env:
WASM_BINDGEN_USE_DEDICATED_WORKER: 1
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
run: wasm-pack test --headless --firefox
run: wasm-pack test --headless --firefox -- --features std
- name: Test (shared worker)
env:
WASM_BINDGEN_USE_SHARED_WORKER: 1
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
run: wasm-pack test --headless --firefox
run: wasm-pack test --headless --firefox -- --features std
- name: Test (service worker)
env:
WASM_BINDGEN_USE_SERVICE_WORKER: 1
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
# Firefox doesn't support module service workers and therefor can't import scripts
run: wasm-pack test --headless --chrome
run: wasm-pack test --headless --chrome -- --features std

wasi:
name: WASI
Expand Down
20 changes: 18 additions & 2 deletions .github/workflows/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
# Fixed Nigthly version is used to prevent
# CI failures which are not relevant to PR changes
# on introduction of new Clippy lints.
toolchain: nightly-2024-10-08
toolchain: nightly-2024-10-24
components: clippy,rust-src
- name: std feature
run: cargo clippy --features std
Expand All @@ -48,7 +48,23 @@ jobs:
- name: Web WASM (wasm_js.rs)
env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
run: cargo clippy -Zbuild-std --target wasm32-unknown-unknown
run: cargo clippy --features std -Zbuild-std=panic_abort,std --target wasm32-unknown-unknown
- name: Web WASM no_std (wasm_js.rs)
env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
run: cargo clippy -Zbuild-std=core,alloc --target wasm32-unknown-unknown
- name: Web WASM no_std with atomics (wasm_js.rs)
env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js" -Ctarget-feature=+atomics,+bulk-memory
run: cargo clippy -Zbuild-std=core,alloc --target wasm32-unknown-unknown
- name: Web WASMv1 (wasm_js.rs)
env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js"
run: cargo clippy -Zbuild-std=core,alloc --target wasm32v1-none
- name: Web WASMv1 with atomics (wasm_js.rs)
env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="wasm_js" -Ctarget-feature=+atomics,+bulk-memory
run: cargo clippy -Zbuild-std=core,alloc --target wasm32v1-none
- name: Linux (linux_android.rs)
env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="linux_getrandom"
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ windows-targets = "0.52"
# wasm_js
[target.'cfg(all(getrandom_backend = "wasm_js", target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))'.dependencies]
wasm-bindgen = { version = "0.2.96", default-features = false }
js-sys = "0.3.73"
js-sys = { version = "0.3.73", default-features = false }
[target.'cfg(all(getrandom_backend = "wasm_js", target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))'.dev-dependencies]
wasm-bindgen-test = "0.3"

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

Expand Down

0 comments on commit ac1d843

Please sign in to comment.