Skip to content

Run Schist in the browser - #90

Merged
IAmJSD merged 5 commits into
mainfrom
t3code/add-wasm-support
Aug 31, 2026
Merged

IAmJSD merged 5 commits into
mainfrom
t3code/add-wasm-support

Conversation

@IAmJSD

@IAmJSD IAmJSD commented Aug 31, 2026

Copy link
Copy Markdown
Member

Schist now compiles to wasm32-unknown-unknown and runs as a static web page on the gpui fork's new WebGPU backend (rev 75e6ffb). make web assembles the deployment into dist/web/; CI builds it on every push/PR and publishes main to try.schist.app via Cloudflare Workers. docs/web.md is the full write-up.

How it loads

  • The wasm carries no assets. The loading page (logo, byte-accurate progress bar) fetches the module — split into 4 MiB chunks for parallel downloads — alongside the icons and the UI font, parks the bytes on window.__schist_boot, and only then instantiates; the Rust side reads the payload synchronously, so startup never grows an async asset path.
  • The app's panic hook turns the loading page into an error card, so a crash during boot never reads as "still loading".
  • On a first visit the page shows a one-time "the desktop app is the fuller Schist" notice; OK records acceptance in localStorage.

What works in a tab

Everything the kernel does: all tools, filters, adjustments, PSD/PSB/Affinity/PNG/JPEG/WebP/TIFF, text (fonts injected into both text systems), CPU compositing. Open raises a real file picker into an in-memory map behind the existing path-shaped flows; Save/Export leave as downloads with the browser prompt choosing the name (extension picks the format). Preferences live in localStorage. Neural models moved from include_bytes! (11 MB) to files fetched on demand into an in-memory store, through the existing Manage Models dialog; the externally-hosted ones are labelled unavailable (their GitHub URLs redirect through a host that sends no CORS headers) and every neural filter already falls back to its classical path.

What's compiled out, and why

AI sidebar (spawns agent CLIs), both plug-in hosts (subprocesses/dlopen; wasmtime is a JIT), HEIC (dlopen'd libheif), the self-updater, Sentry, font downloads (the catalogue trick needs a spoofed legacy UA to be served TTFs). Menu entries are filtered out rather than left to fail. Everything is cfg(target_arch) — no feature matrix — with two small stubs keeping shared UI compiling.

Build pipeline

tools/web-build.sh: a new [profile.web] (release minus debuginfo — DWARF was a third of the bytes), wasm-bindgen pinned to Cargo.lock's exact version, wasm-opt behind a version gate — binaryen ≤108 (Ubuntu's package) silently corrupts the externref table rustc now emits and the module dies at init, so the script refuses anything older than 116 (123 verified: 45→28 MB) — then chunking and a manifest. Portable to macOS (BSD split, missing wasm-opt handled).

Also fixed on the way: codec-affinity's export stamp used SystemTime::now(), which panics on wasm (now web-time), and tract's getrandom needed the wasm_js backend.

Verification

  • Native: cargo test --workspace, clippy -D warnings-clean, fmt clean; wasm target compiles warning-free.
  • Headless Chromium: full boot path end-to-end — chunked fetch, instantiation, all 13 first-party plugins, window open, loading-page handoff, clean console at 60fps. The notice's show/accept/suppress cycle verified via CDP.
  • The dev box only has SwiftShader WebGPU, which presents no pixels even for gpui's own hello_web, so rendered-frame verification happened on a real browser separately.
  • wrangler deploy --dry-run validates the config; the deploy step skips itself politely until the CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID secrets exist.

🤖 Generated with Claude Code

IAmJSD and others added 5 commits August 31, 2026 22:16
Schist now compiles to wasm32-unknown-unknown and runs as a static web
page, on the gpui fork's new WebGPU backend (rev 75e6ffb). `make web`
assembles dist/web/; docs/web.md documents the deployment, what works
and what does not.

The wasm carries no assets. The loading page (web/index.html +
web/loader.js) fetches the module -- split into 4 MiB chunks for
parallel downloads and a byte-accurate progress bar -- alongside the
icons and the UI font, parks the bytes on window.__schist_boot, and
instantiates; the Rust side reads the payload synchronously, so startup
never grows an async asset path. The app's panic hook turns the loading
page into an error card, so a crash during boot never reads as "still
loading". The neural models moved from include_bytes! to files served
under assets/models/, fetched on demand (streamed, with progress) into
an in-memory store; the externally-hosted models are labelled
unavailable, since their GitHub URLs redirect through a host that sends
no CORS headers. Every neural filter already falls back to its
classical path when a model is absent.

Files keep their path-shaped flows over an in-memory map: Open raises a
real file picker and stores the bytes under an invented path; Save and
Export run the codec and leave as downloads, the browser's own prompt
choosing the name (whose extension picks the format). Preferences
persist in localStorage. Compositing runs on the CPU reference backend
-- the GPU compositor's second wgpu device sits behind a blocking wait
the browser's single thread cannot service -- and rayon degrades to
sequential execution.

Compiled out on wasm32, each for want of an OS facility: the AI sidebar
(spawns agent CLIs), both plug-in hosts (helper subprocesses and dlopen;
wasmtime is a JIT), HEIC (dlopen'd libheif), the self-updater, Sentry,
and font downloads (the catalogue trick needs a spoofed legacy user
agent to be served TTFs). Their menu entries are filtered out rather
than left to fail. Two stubs (ai_stub.rs, update_stub.rs) keep the
shared UI compiling; everything is cfg(target_arch), no feature matrix.

Two latent wasm panics fixed on the way: codec-affinity's creation
stamp used std's SystemTime::now(), which panics on this target
(web-time now), and tract's getrandom needed the wasm_js backend.
tools/web-build.sh pins wasm-bindgen-cli to Cargo.lock's version and
refuses binaryen older than 116: Ubuntu's packaged 108 silently mangles
the externref table rustc now emits, and the module then dies at init
with "Table.grow(): failed to grow table".

Verified: native cargo test --workspace, clippy and fmt all clean; the
wasm target compiles warning-free; in headless Chromium the full boot
path works end to end (chunked fetch, instantiation, all 13 first-party
plugins, window open, overlay handoff, clean console at 60fps). This
box only has SwiftShader WebGPU, which presents no pixels for gpui's
own hello_web either, so the first rendered frame in a real browser is
still owed.

Co-Authored-By: Claude Fable 5 <[email protected]>
Two macOS failures in one script. `WASM_OPT_VER=$(wasm-opt --version …)`
under `set -e` kills the whole build with a bare exit 127 when binaryen
isn't installed at all — the probe now sits behind `command -v`, and a
missing wasm-opt skips optimization with the same pointer at the
binaryen releases page the too-old case prints. And BSD split has no
`-d`, so the chunks now take alphabetic suffixes (.aaa, .aab, …), which
sort exactly the same everywhere the manifest and loader care.

Co-Authored-By: Claude Fable 5 <[email protected]>
On a first visit the loading page shows a card saying the web version
is the lighter build (CPU compositing, no plug-ins/AI panel/HEIC/font
downloads, saves are downloads) and links the desktop releases. OK
records the acceptance in localStorage (schist.desktop-notice-accepted,
an ISO timestamp) and the notice never shows again; a browser whose
storage throws just sees it each visit. Pure loading-page DOM, so it is
readable while the chunks are still downloading and costs the app
nothing.

Co-Authored-By: Claude Fable 5 <[email protected]>
A new Web workflow builds dist/web/ on every push to main and on PRs
that could change it, uploading the result as an artifact either way;
pushes to main then deploy it to Cloudflare Workers as an assets-only
Worker. wrangler.jsonc names the Worker (schist-try) and binds the
try.schist.app custom domain, so wrangler manages the DNS record and
certificate itself.

The build installs wasm-bindgen-cli at exactly the version Cargo.lock
records (read from the lock, not pinned twice) and a known-good
binaryen release, since Ubuntu's packaged 108 is the one
tools/web-build.sh refuses. The deploy step is gated on the
CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID secrets and skips itself
politely where they don't exist, so forks and the pre-secret repository
still get the full build and artifact. Verified locally: the workflow
parses, both release downloads extract as written, and `wrangler deploy
--dry-run` reads all 105 asset files without complaint.

Co-Authored-By: Claude Fable 5 <[email protected]>
@IAmJSD
IAmJSD merged commit cdc4308 into main Aug 31, 2026
4 checks passed
@IAmJSD
IAmJSD deleted the t3code/add-wasm-support branch August 31, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant