Skip to content

Commit 9f659fd

Browse files
committed
examples: show how to build for Wasm
Tink requires cryptographic randomness, and this is provided by the `getrandom` crate. By default, that crate does not include any support for Wasm, but the `js` feature turns on support for randomness via WASI. Modify one of the examples to demonstrate how to build for Wasm by ensuring that `getrandom/js` is in the Cargo build graph. Check this with a CI step.
1 parent 9b1885d commit 9f659fd

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ jobs:
165165
- run: rustc --version
166166
- run: cargo doc --no-deps --document-private-items --all-features
167167

168+
wasm:
169+
runs-on: ubuntu-latest
170+
steps:
171+
- uses: actions/checkout@629c2de402a417ea7690ca6ce3f33229e27606a5 # v2
172+
- uses: actions-rs/toolchain@63eb9591781c46a70274cb3ebdf190fce92702e8 # v1
173+
with:
174+
profile: minimal
175+
toolchain: 1.81.0
176+
target: wasm32-unknown-unknown
177+
- run: (cd examples/aead && cargo +1.81.0 build --target wasm32-unknown-unknown --release)
178+
168179
udeps:
169180
runs-on: ubuntu-latest
170181
steps:

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/aead/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ license = "Apache-2.0"
77
publish = false
88

99
[dependencies]
10+
# Force on the `js` feature of `getrandom` so a build of this example
11+
# for `wasm32-unknown-unknown` works.
12+
getrandom = { version = "^0.2.8", features = ["js"] }
1013
hex = "^0.4.3"
1114
tink-aead = "^0.3"
1215
tink-core = "^0.3"

0 commit comments

Comments
 (0)