build-web.sh now generates the browser package with wasm-bindgen (web/pkg/tethercore.js + tethercore_bg.wasm, --target web) after building the cdylib. web/index.html is a tiny demo: import the bindings, derive the room from an account, new WasmEngine(...).start(onMessage)/send — relay-only iroh peer in the browser. Generated web/pkg/ is git-ignored. End to end now proven buildable: Rust core → wasm32 → wasm-bindgen JS (exports WasmEngine + roomForAccount) → importable in a browser. A live in-browser run needs serving web/ + a reachable rendezvous/relay. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
35 lines
1.6 KiB
Bash
Executable File
35 lines
1.6 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
|
|
PROFILE="${PROFILE:-release}"
|
|
echo "▸ building tethercore for wasm32 ($PROFILE; iroh, relay-only in-browser)…"
|
|
cargo build --target wasm32-unknown-unknown --features iroh-transport --lib \
|
|
$([ "$PROFILE" = release ] && echo --release) "$@"
|
|
|
|
WASM="target/wasm32-unknown-unknown/$PROFILE/tethercore.wasm"
|
|
if command -v wasm-bindgen >/dev/null; then
|
|
echo "▸ generating JS bindings → web/pkg/ (wasm-bindgen)…"
|
|
wasm-bindgen "$WASM" --out-dir web/pkg --target web
|
|
echo "✅ web/pkg/tethercore.js + tethercore_bg.wasm — import into the browser app."
|
|
else
|
|
echo "⚠ wasm-bindgen CLI not found — built $WASM but skipped JS bindings."
|
|
echo " install: cargo install wasm-bindgen-cli --version <match Cargo.lock>"
|
|
fi
|