Skip to content

Commit 847c4c5

Browse files
Frando“ramfox”
andauthored
feat: compile to wasm for browsers (#187)
## Description Depends on n0-computer/irpc#54 (merged but not released) This makes iroh-blobs compile on wasm, with memstore only though. I had started on this a while back but it got much easier now with the fs-store behind a feature flag. Example: n0-computer/iroh-examples#139 Deployed at https://n0-computer.github.io/iroh-examples/pr/139/browser-blobs/index.html ## Breaking Changes <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> --------- Co-authored-by: “ramfox” <“[email protected]”>
1 parent db54e36 commit 847c4c5

28 files changed

+240
-136
lines changed

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[target.wasm32-unknown-unknown]
2+
runner = "wasm-bindgen-test-runner"
3+
rustflags = ['--cfg', 'getrandom_backend="wasm_js"']

.github/workflows/ci.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,40 @@ jobs:
277277
- uses: actions/checkout@v5
278278
- run: pip install --user codespell[toml]
279279
- run: codespell --ignore-words-list=ans,atmost,crate,inout,ratatui,ser,stayin,swarmin,worl --skip=CHANGELOG.md
280+
281+
wasm_build:
282+
name: Build & test wasm32
283+
runs-on: ubuntu-latest
284+
env:
285+
RUSTFLAGS: '--cfg getrandom_backend="wasm_js"'
286+
steps:
287+
- name: Checkout sources
288+
uses: actions/checkout@v4
289+
290+
- name: Install Node.js
291+
uses: actions/setup-node@v4
292+
with:
293+
node-version: 20
294+
295+
- name: Install stable toolchain
296+
uses: dtolnay/rust-toolchain@stable
297+
298+
- name: Add wasm target
299+
run: rustup target add wasm32-unknown-unknown
300+
301+
- name: Install wasm-tools
302+
uses: bytecodealliance/actions/wasm-tools/setup@v1
303+
304+
- name: Install wasm-pack
305+
uses: taiki-e/install-action@v2
306+
with:
307+
tool: wasm-bindgen,wasm-pack
308+
309+
- name: wasm32 build
310+
run: cargo build --target wasm32-unknown-unknown --no-default-features
311+
312+
# If the Wasm file contains any 'import "env"' declarations, then
313+
# some non-Wasm-compatible code made it into the final code.
314+
- name: Ensure no 'import "env"' in wasm
315+
run: |
316+
! wasm-tools print --skeleton target/wasm32-unknown-unknown/debug/iroh_blobs.wasm | grep 'import "env"'

0 commit comments

Comments
 (0)