Files
tether/core/build-web.sh
Patrick Ecord 2ec5d892aa wasm: tethercore compiles for wasm32 — runtime Spawner + n0-future timers
The web client is real: `tethercore` with the full iroh stack now builds for
wasm32-unknown-unknown, producing tethercore.wasm.

- Runtime abstraction: a `Spawner` replaces the bare tokio runtime Handle across
  the Transport trait + Engine + all transports — tokio Handle on native, the
  browser event loop (wasm-bindgen-futures::spawn_local) on wasm. The engine no
  longer builds a tokio multi-thread runtime on wasm (there are no OS threads).
- IrohTransport's internal tasks (re-register loop, blob fetch) route through the
  Spawner; its 30s timer uses n0-future (iroh's cross-platform async) instead of
  tokio::time, which isn't available on wasm.
- iroh on wasm: default-features=false + tls-ring (ring builds for wasm with a
  wasm-capable clang) + iroh-gossip net; getrandom uses its wasm_js backend.
- build-web.sh documents the toolchain (Homebrew LLVM clang for ring's C, the
  getrandom rustflag) and produces the .wasm.

Native (default + iroh + all clients) is byte-unaffected and verified clean
throughout. Remaining for a running web app: wasm-bindgen JS bindings + a browser
shim (relay-only in-browser).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 17:28:37 -05:00

25 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Builds tethercore for the browser (wasm32). The core compiles to wasm with the
# iroh Mesh (relay-only in-browser). The NEXT step — wasm-bindgen JS bindings +
# a browser shim for the web app — is still TODO; this just produces the .wasm.
#
# Requires:
# rustup target add wasm32-unknown-unknown
# Homebrew LLVM (`brew install llvm`) for a wasm-capable clang — ring's build
# script compiles C for wasm and Apple's clang has no wasm backend.
set -euo pipefail
cd "$(dirname "$0")"
# A clang/llvm-ar that can target wasm (override with LLVM_PREFIX if elsewhere).
LLVM="${LLVM_PREFIX:-/opt/homebrew/opt/llvm}"
export CC_wasm32_unknown_unknown="$LLVM/bin/clang"
export AR_wasm32_unknown_unknown="$LLVM/bin/llvm-ar"
# getrandom has no OS rng in the browser — use its wasm_js backend.
export RUSTFLAGS="${RUSTFLAGS:-} --cfg getrandom_backend=\"wasm_js\""
rustup target add wasm32-unknown-unknown >/dev/null 2>&1 || true
echo "▸ building tethercore for wasm32 (iroh, relay-only in-browser)…"
cargo build --target wasm32-unknown-unknown --features iroh-transport --lib "$@"
echo "✅ target/wasm32-unknown-unknown/debug/tethercore.wasm"
echo " next: wasm-bindgen bindings + a JS shim for the browser app."