Enable WASM support#271
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #271 +/- ##
==========================================
- Coverage 96.20% 96.12% -0.08%
==========================================
Files 80 80
Lines 3136 3073 -63
==========================================
- Hits 3017 2954 -63
Misses 119 119 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| getrandom = { version = "0.2", default-features = false, features = ["js"] } | ||
|
|
There was a problem hiding this comment.
Can you add something like this job to the ci.yaml?
wasm_build:
runs-on: ubuntu-latest
steps:
- uses: Swatinem/rust-cache@v2
with:
key: wasm32-unknown-unknown
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
toolchain: nightly
- run: cargo check --all-features -- -D warningsI'm a bit skeptical it works since "js" does not seem like the correct feature name. https://docs.rs/crate/getrandom/0.3.4/features
Also, what happens if you use getrandom 0.3?
|
In getrandom 0.2, the feature was called js, but it was renamed to wasm_js in 0.3. I've included the features for both v0.2 and v0.3 on wasm32 targets to ensure the rops library compiles properly. Both are needed to prevent compilation errors. [target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", default-features = false, features = ["js"] }
getrandom_03 = { package = "getrandom", version = "0.3", default-features = false, features = ["wasm_js"] }I ended up with the CI task to compile and check the wasm build: wasm_build:
name: WASM build
runs-on: ubuntu-latest
env:
RUSTFLAGS: '--cfg getrandom_backend="wasm_js" -D warnings'
steps:
- name: Checkout sources
uses: actions/checkout@v5
- name: Cache Rust toolchain
uses: Swatinem/rust-cache@v2
with:
key: wasm32-unknown-unknown
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
toolchain: nightly
- run: cargo check -p rops --features wasm --no-default-features --target wasm32-unknown-unknownThe |
|
Apologies for the somewhat late reply. Anyhow, I get what you're saying now. I'm not a huge fan of forcing two versions of the same library into the same project though. If only getrandom 0.3 could be used, that would be great. The rust crypto crates have release candidates with their getrandom dependency updated. Perhaps we can wait a bit for their release? The remaining crate that uses getrandom 0.2 is ring. Are you open to creating a PR there that updates it?
Not sure I like this. We're basically exposing a combined feature just for the same of shortening a CI job. |
Summary:
Adds getrandom dependency with JavaScript feature flag for WASM (WebAssembly) target architecture support.
Impact:
Enables the library to compile and run in WebAssembly (browser) environments