Design

crust is a bet: you can build a real macOS app with no compiled artifact in the package. Everything below follows from that one constraint. The measurements behind each claim are on the evidence page.

The premise

There is no prebuilt native library, no cargo, no Xcode project. Every AppKit call goes through bun:ffi into the Objective-C runtime. The only C is a shim compiled at launch by the TinyCC that ships inside Bun, which is why brew install compiles nothing and there is no bottle to match to your machine.

Four constraints that follow

objc_msgSend is variadic, and a variadic declaration lies. Declared as void *objc_msgSend(void *, void *, ...) it compiles and runs, then delivers wrong argument values with no diagnostic — a takeInt: sent 41 arrived as 1806466472. Every call site therefore casts to a fixed prototype per arity and return kind (shim_send_p1, shim_send_pq1, shim_send_vb1, …). Zero-argument sends happen to survive; nothing else does.

Structs cannot cross. CGRect, CGSize and CGAffineTransform are the danger zone. The shim builds them on the C stack and calls the initializer itself, so a window is created with initWithContentRect:styleMask:backing:defer: while no struct ever reaches JavaScript. Views are laid out with constraints — four edge pins on the webview, no size of its own — and setFrame: lives inside the shim, which is what window.setSize and window.setPosition reach.

Nothing is typed, and a bad selector kills the process. A selector the receiver does not implement raises an Objective-C exception Bun cannot catch: SIGABRT, no JavaScript error. So every selector is verified once at startup (PREFLIGHT) and an unverified one is never sent.

Framework headers are unreachable. <objc/runtime.h> resolves; <AppKit/AppKit.h> never does, with or without -I. Every symbol is a hand-written extern over void *, and every framework is linked by name (-framework AppKit, -framework Foundation, -framework WebKit, -framework CoreFoundation).

The page follows its window

A window's content view keeps its autoresizing behaviour, and the webview inside it is four edge pins with no width or height of its own. That chain is the whole resize path: the window sizes the content view, the content view's size is the webview's, and the page sees whatever the window became.

Both halves are load-bearing, and each hides the other. A fixed width/height pair added on top of the pins holds the webview at the size the window opened at — measured 2026-11-18, a window resized to 1400x840 with content and webview still 1100x760, which is what "apps can't be resized" looked like from the page. Remove only those constants and the content view, which has no constraints of its own, collapses to 0x0 and takes the webview with it. So the content view keeps autoresizing, the webview keeps the four pins, and nothing sets a size.

bun run e2e:window asks the page for its own innerWidth/innerHeight after the window grows and again after it shrinks, because a one-way constraint passes growing alone.

The run loop

[NSApp run] never returns, so it cannot be called — Bun's event loop would stop. The Cocoa loop is pumped from JavaScript on a 16 ms timer (PUMP_INTERVAL_MS), and each tick drains AppKit's event queue (nextEventMatchingMask: with a 4 ms deadline → sendEvent: → updateWindows) before falling back to a 2 ms CFRunLoopRunInMode.

Slice length decides tick fidelity: a sweep (research/runloop) found 0.25 ms and 0.5 ms both delivered 186 of 187 ticks, 1 ms reached 96.8%, and 4 ms only 82.4% — a 4 ms slice is worse than not pumping at all. That is the tuning evidence for a shorter slice; the shipped shim (shim/50_app.c) passes a 4 ms deadline and a 2 ms fallback, so the measured optimum is not the value in the code. Blocking JavaScript blocks drawing, so long work belongs on a Worker.

The bridge

The page and the backend talk over a loopback HTTP bridge, not a promise inside one process: invoke is a POST with a bearer token, and answers are JSON. The port is derived from app.id (45000–48999, walking upward), so the origin a page loads from is stable and can be named in the content security policy. This is also what makes crust dev work: the window loads dev.url exactly once, so the dev server must already be up.

The gate on /_crust/* is the bearer token; the origin check only rejects a present and foreign Origin. An absent header is not a cross-origin request — a browser always sends Origin on one, and WebKitGTK's EventSource sends none at all on a same-origin GET, so refusing a null Origin killed every plugin event on Linux (ctx.emit to theme, menu, tray, downloads, navigation, shell and network) while POST invoke kept working. A page from another origin still carries its own Origin and is still refused 403 bad-origin; a missing token is still 401.

How a page loads

A page loads from the bridge URL (http://127.0.0.1:<port>/), navigated by the platform's own call — darwin sends -loadRequest:. No platform registers a custom scheme to serve a page: a scheme that cannot serve bytes earns nothing, and crust:// is already taken. urlScheme is optional app config with no default, so crust:// belongs to an app's deep links, never to the framework.

That leaves a new platform one job: implement Platform — the five required methods start, pump, createWindow, window, quit, plus the optional windowLabels?() and lifecycle?() hooks when the platform can answer them. A page-serving scheme invented per platform is how two lanes produced two incompatible loaders for one contract.

Why the page comes over loopback and not a custom scheme

Tauri and Butter both serve the page from a custom URI scheme — tauri://localhost and butter:// — so there is no TCP port listening at all. crust serves it from a loopback HTTP server, which means a port exists. This section is why, because "everyone else does it" is the obvious question and the answer is not "we did not think about it".

A custom scheme is not a web origin

This is the part that surprises people. crust://app/ looks like a URL, but to a browser engine it is not an origin the way http://… is. That has consequences nobody expects:

The workaround every framework lands on is to pretend the scheme is a website: Tauri serves tauri://localhost on macOS but http://tauri.localhost on Windows (or https://tauri.localhost behind a flag), precisely so the page gets a real origin and a secure context. That is one framework shipping two page addresses, and a config flag to choose between two sets of breakage.

What a loopback URL gets for free

http://127.0.0.1:<port>/ is a normal origin, and browsers give loopback a local-trust exemption: it counts as a secure context without a certificate. So crypto.subtle works, service workers are available, location.origin is a real value, and every platform behaves the same because every platform's engine already knows what an http origin is.

That is why crust's page is the same shape under crust dev and in a built app, and why a new platform only implements Platform — five required methods and two optional hooks — instead of also owning a URI scheme.

The one thing a scheme actually buys

With no socket, there is nothing for another local process to connect to. crust's bearer token exists to make up for that: a page that cannot present it is refused 401. Since the token moved onto the navigation URL it is no longer readable from a document fetch, so the practical gap is narrow — a local process can no longer get the app's authority, it can only try to guess it.

Weighing that against three platforms needing their own scheme handler, a dev-server/production split, and the secure-context workaround above, the socket was kept. The decision was reviewed on 2026-11-17 and the transport row is marked accepted difference in the Tauri parity table.

If it is ever revisited

The change is contained: src/bridge/server/ plus one page loader per platform. None of the plugins move. The four things a first attempt must prove, because an earlier crust:// experiment in this repo got them wrong: a document renders, one invoke round trip completes, an <img> loads, and crypto.subtle is defined.

Known shape, stated honestly

Deliberately absent

A string intern table, helpers that return an NSString object across the FFI, layout by setFrame: (the geometry calls window.setSize and window.setPosition still reach it inside the shim), and any dependency on Xcode at build or install time. Each was removed after it crashed the process or silently corrupted an object; the traps are in AGENTS.md.