Files
tether/core/Cargo.toml
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

80 lines
3.2 KiB
TOML

[package]
name = "tethercore"
version = "0.1.0"
edition = "2021"
description = "Shared tether sync engine: codec + SSE client + reconnect, FFI-exported via UniFFI."
[lib]
# lib → examples/tests can link it natively
# staticlib → iOS .a / desktop agent
# cdylib → Android .so / bindgen library mode
crate-type = ["lib", "staticlib", "cdylib"]
name = "tethercore"
[[bin]]
name = "uniffi-bindgen"
path = "src/bin/uniffi-bindgen.rs"
# Common, wasm-safe dependencies (no OS sockets / threads).
[dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = "1"
futures-util = "0.3"
sha2 = "0.11.0"
bytes = "1.12.0"
chacha20poly1305 = "0.10.1"
base64 = "0.22.1"
# n0-future: iroh's cross-platform async (works native + wasm) — used for the
# IrohTransport's timers so it doesn't depend on tokio's time on wasm.
n0-future = { version = "0.3", optional = true }
[features]
default = []
iroh-transport = ["dep:iroh", "dep:iroh-gossip", "dep:iroh-blobs", "dep:n0-future"]
# ── Native (desktop/mobile): legacy transports + UniFFI + full tokio ──
# The hand-rolled SSE/RTC/LAN stack and its OS-socket deps live here; none of it
# compiles to wasm. iroh (behind the feature) takes full default features.
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
uniffi = { version = "0.28", features = ["cli"] }
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls", "stream", "json"] }
tokio = { version = "1", features = ["rt-multi-thread", "time", "sync", "macros", "net", "io-util"] }
webrtc = "0.17.1"
mdns-sd = "0.20.0"
getrandom = "0.4.3"
iroh = { version = "1", optional = true }
iroh-gossip = { version = "0.101", optional = true }
iroh-blobs = { version = "0.103", optional = true }
# ── wasm32 (browser): iroh-only, no OS sockets / UniFFI ──
# Browser iroh is relay-only; reqwest uses fetch; the runtime is the JS event
# loop (wasm-bindgen-futures) instead of a tokio runtime.
[target.'cfg(target_arch = "wasm32")'.dependencies]
tokio = { version = "1", features = ["sync", "macros"] }
reqwest = { version = "0.12", default-features = false, features = ["json"] }
# wasm rng: getrandom 0.4 uses a build-cfg (--cfg getrandom_backend="wasm_js"),
# but a transitive getrandom 0.2 needs the `js` *feature* — enable it via the
# rename-alias trick (cargo unifies it with the transitive copy).
getrandom = "0.4.3"
getrandom_02 = { package = "getrandom", version = "0.2", features = ["js"] }
wasm-bindgen-futures = "0.4"
# Browser iroh: default-features off (drops native portmapper/apple-datapath),
# but keep tls-ring — ring works on wasm and presets::N0 needs it. (Matches n0's
# own browser-chat example.)
iroh = { version = "1", optional = true, default-features = false, features = ["tls-ring"] }
iroh-gossip = { version = "0.101", optional = true, default-features = false, features = ["net"] }
iroh-blobs = { version = "0.103", optional = true, default-features = false }
[dev-dependencies]
# Iroh spikes (examples/iroh_*.rs) link iroh directly regardless of the feature.
iroh = "1"
iroh-gossip = "0.101"
anyhow = "1"
# The M4 integration example drives the real Engine over IrohTransport, so it
# needs the feature (and Engine::iroh_id, which only exists under it).
[[example]]
name = "iroh_engine"
required-features = ["iroh-transport"]