This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index at /llms.txt, or add .md to any page's URL.
Rust live replacement
Rust replacement is enabled by default in development and production: native
shared libraries on macOS/Linux, the browser's Wasm executor on web, and the
wasmi interpreter on iOS devices and simulators. Native hosts start with their
linked Rust; interpreted execution applies to replaced logic. Android/Windows
have policy defaults but their hosts remain future work. LLP 1029.000
records the boundary and verification status.
Control inclusion in app.json. "rust": false disables everywhere;
"rust": {"prod": false} keeps it in development only. A platform can override
both or either environment:
json
{
"rust": {
"module": { "package": "caltrain-logic" },
"platforms": {
"ios": { "prod": false },
"macos": { "prod": "wasm" }
}
},
"dev": { "rebuild": { "rust": "manual", "typescript": "save" } }
}
Modes are auto, native, tiered, wasm, and off; true means auto and false
means off. Resolution is global → environment → platform → platform environment.
off removes the replacement path from the native bake; changing that requires
a new binary. TypeScript and delivery cadence remain separate choices. Save is
the default trigger for both languages while the development watcher runs;
manual is useful when an agent wants to finish a set of edits before rebuilding.
After the app's initial web bake, run bun scripts/rust.mjs caltrain to build
the independent Rust module variants; the running dev server consumes the
completed output. At the dev
server’s terminal, r + Enter rebuilds Rust and t + Enter rebuilds TypeScript.
For portable modules without essential private state,
"rust": {"platforms": {"macos": {"dev": "tiered"}}} runs new Wasm immediately
after publication and promotes to native when the library finishes loading.
Both variants must declare exact_logic_abi::export!(Data, constructor, stateless):
essential state lives in host inputs, Contract or host-owned storage; initialization
and destruction have no external effects. Promotion preserves the app generation
and does not restart TypeScript or replay business calls. Native loading failures
leave Wasm running. This mode adds the interpreter and both artifact variants;
explicit native avoids that interpreter. The usual dev/prod overrides apply,
but tiered is unavailable on iOS/web. Update Lab opts in for macOS development;
auto defaults are unchanged. Both variants still compile before publication.
A binary runs its own compiled data crate until an update replaces it, and only a
module that differs from that code is interpreted. The build records the digest of
the source the module compiles from (nativeSource in scripts/rust.mjs: the
module's local crates, the workspace's Cargo.toml and Cargo.lock, and the
compiler) and every Rust receipt carries it as source. A candidate whose
source is the binary's own becomes the native data source again
(Swappable::with_native). On iOS an update that changes the Rust runs
interpreted until a binary built from that source is installed; an update that
changes only the Contract or TypeScript leaves the Rust native.
The bake accepts cfg(target_*) branches and native dependencies in the data
crate: the source digest reads every arm, so an edit to any of them moves it
(LLP 1030 D3a, amended 2026-11-12). An interpreted module is built for
wasm32-unknown-unknown, though, and runs only the crate's
target_arch = "wasm32" arms, never one for the device's target_os. A crate
whose module can be replaced should branch on nothing else
(pitfall).
The digest also covers the path crates the data crate is built from, and
theirs in turn, including an optional one no default feature enables: the
build that links the crate can enable it. One case is not covered. A path
crate that [patch] puts in place of a registry or git dependency counts
only where Cargo's default-feature resolve reaches it. When only an optional
dependency that resolve leaves off reaches it, an edit to it does not move
the id; declare that dependency with path to have it counted.
The repository's app entries use contract::rust_entry to select a concrete
factory at bake time. A custom host adapter must do the same (and depend on
exact-logic), or compose Swappable::native, Swappable::tiered, Swappable::wasm or
Swappable::browser explicitly. Merely declaring a module does not retrofit
a custom, manually implemented DataSource host.
Update Lab composes one Rust probe with one
TypeScript executor. Its complete development candidate carries both modules,
so a TypeScript or Contract edit retains the last accepted Rust version.
The replacement unit is the declared portable logic-wrapper cdylib, not an individual
Rust function or file. Keep business logic in small Cargo crates and native I/O
in host adapters; Cargo reuses unchanged helpers, but their dependent loadable
module still relinks. Independent replacement of several domains requires
separate loadable artifacts and explicit host composition; a multi-module
manifest registry is not implemented.
Production capability does not grant store permission to deliver arbitrary
code updates. Apple's review guidelines
restrict downloaded feature-changing code, including interpreted code; Google
Play's policy
restricts downloaded native .so code and describes a VM/interpreter exception.
Use the production opt-out where the app's distribution requires it. Native
macOS libraries also need platform-appropriate code signing: the production
producer requires EXACT_RUST_SIGN_IDENTITY for the host's signing team, or
select wasm for macOS production.
Is this helpful
Last updated November 30, 2026