Skip to content

Add no_std support for Web #560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,40 @@ jobs:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="rdrand"
run: cargo build --features=std

web:
name: ${{ matrix.target.description }} ${{ matrix.feature.description }} ${{ matrix.atomic.description }}
runs-on: ubuntu-24.04
env:
RUSTFLAGS: --cfg getrandom_backend="wasm_js" ${{ matrix.atomic.flags }}
strategy:
fail-fast: false
matrix:
target: [
{ description: Web, target: wasm32-unknown-unknown },
{ description: WasmV1, target: wasm32v1-none },
]
feature: [
{ description: no_std, feature: "", build-std: "core,alloc", std: false },
{ feature: --features std, build-std: "panic_abort,std", std: true },
]
atomic: [
{ flags: "" },
{ description: with Atomics, flags: "-Ctarget-feature=+atomics,bulk-memory" },
]
exclude:
- target: { target: wasm32v1-none }
feature: { std: true }
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
targets: ${{ matrix.target.target }}
toolchain: nightly-2024-10-24
components: rust-src
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --target ${{ matrix.target.target }} ${{ matrix.feature.feature }} -Zbuild-std=${{ matrix.feature.build-std }}

rdrand:
name: RDRAND
runs-on: ubuntu-24.04
Expand Down
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ 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"

Expand Down