# Build pipeline

One monorepo, three languages, one entry point. Every workspace has a `package.json` whose scripts turbo runs. The root `package.json` delegates to `turbo run <task>`, except `plugin`, which runs `scripts/plugin.ts` once to start a plugin, and `index`, which runs `scripts/index.ts` to write `plugins/index.json` and `plugins/README.md`, or with `bun run index -- --check` to check both against the plugins and write nothing; neither is a task of the graph.

## Workspaces

Bun workspaces are declared in the root `package.json`. A Rust crate or the Swift app is a workspace too: its `package.json` wraps `cargo` or `xcodebuild`. Workspace dependencies in those files mirror the real dependencies between crates, so turbo orders tasks and invalidates caches correctly. When a crate gains a dependency on another crate, add it in both `Cargo.toml` and `package.json`.

`scripts/` is a workspace as well. It owns `bootstrap` and the checks that span the whole repository.

## Tasks

| Task | What it does |
|---|---|
| `bootstrap` | Installs the pinned Rust toolchain, xcodegen, periphery, cargo-machete and the git hooks. |
| `generate` | Writes everything that is derived: Swift bindings, the protocol JSON Schema, the types of the AssemblyScript SDK from it, the Xcode project. |
| `build` | Compiles every workspace, the packages of the adapters, the xcframework and the app. |
| `lint` | Linters, format checks, unused-code checks, type checks and the naming check. |
| `format` | Rewrites files with rustfmt, oxfmt and swift-format. |
| `test` | Rust, Swift and adapter tests. |
| `dev` | Runs the app with the mock adapter, from `bun run dev`, or the landing page, from `bun run landing`. Each root script names its workspace, so neither starts the other. |
| `release` | Only `@blossom/macos`: builds the app in Release, arm64 alone, into `apps/macos/build/Build/Products/Release/Blossom.app`, after everything `build` needs. The release workflow runs it; see [../roadmap/distribution.md](../roadmap/distribution.md#release-builds). |

The task graph is in `turbo.json`. Read it before changing a script.

## From Rust to the app

```
crates/bridge ──generate──▶ generated/swift, generated/headers
              ──build─────▶ generated/core.xcframework
adapters/*    ──build─────▶ build/manifest.json, build/main.js, build/hooks
apps/macos    ──generate──▶ blossom.xcodeproj, generated/Info.plist
              ──build─────▶ generated/adapters, generated/runtime/bun
                            build/Build/Products/Debug/Blossom.app
```

1. `@blossom/bridge#generate` builds the bridge crate and runs the UniFFI bindgen binary that lives in the same crate. It writes the Swift bindings and the C header with its module map.
2. `@blossom/bridge#build` compiles the static library in release mode for arm64 and x86_64, merges both with `lipo` and wraps the result and the headers in an xcframework.
3. The `build` of each adapter the app depends on runs `blossom-adapter`, the binary of `sdks/adapter`, which writes its package into `build/` of the adapter; see [adapters.md](adapters.md).
4. `@blossom/macos#generate` runs XcodeGen on `project.yml`.
5. `@blossom/macos#build` runs `scripts/bundle.ts` and then `xcodebuild`. It depends on every step above. The script copies the package of each adapter in the `dependencies` of `apps/macos/package.json` into `generated/adapters`, and the Bun that runs it into `generated/runtime/bun`, after checking that it is the version `package.json` pins; it copies the runtime only when its bytes changed, so Xcode does not copy and sign it again. In `xcodebuild` a folder reference puts the packages in `Contents/Resources/adapters`, and the build phase `Runtime` copies the runtime into `Contents/Helpers` and signs it with the identity of the app before the app itself is signed. The mock is a development dependency of the app and never ships.

After any change to the FFI surface of the bridge, run `bun run generate` before building the app.

Packaging is cheap, so it runs with every build of the app rather than only on `main`. Measured on an Apple M3 Pro shared with other builds: the six packages in 0.24 s with `--force`, `scripts/bundle.ts` in 0.06 s, and copying and signing the runtime in 0.34 s, which the `Runtime` phase repeats only when the runtime changed; an incremental build of the app took 3 to 8 s with or without it. The app grows by the runtime, 85 MB, and the packages, 228 KB on disk: a debug build went from 63 MB to 148 MB.

### Checking a built app

The app checks itself without opening a window:

```sh
apps/macos/build/Build/Products/Debug/Blossom.app/Contents/MacOS/Blossom --selftest
```

It starts the core through the bridge with a configuration and a home of its own in a temporary folder, which it removes after, so it never reads or writes the configuration of the user. Then it checks that the JavaScript engine compiles and is the one `ENGINE_DIGEST` pins, that every key of the catalog in `keys.rs` is 32 bytes in hexadecimal and not a point of small order, which is what Blossom asks of a key before it trusts one and less than a full check of the curve, the marker of a catalog not set up being allowed, that the runtime in `Contents/Helpers/bun` is executable and answers `--version` within ten seconds with the version `packageManager` pins in the root `package.json`, that the package of each adapter Blossom includes is in `Contents/Resources/adapters` and matches its manifest, and that the catalog of logos reads. It prints one line per failure and exits with 1, or prints that it passed and exits with 0. The checks are in `crates/infrastructure/src/selftest.rs` and `crates/bridge/src/selftest.rs`; the app adds only the catalog of logos, which Swift reads. CI runs it on every app it builds, and the release workflow runs it on the app inside the archive it publishes, after unpacking it; see [../roadmap/distribution.md](../roadmap/distribution.md#the-release-workflow).

The test below goes further: it starts every adapter.

`a_built_app_starts_every_adapter_it_includes_with_its_own_runtime`, in `crates/bridge/src/adapter/tests.rs`, starts the core as the app does with a configuration that names every included package and expects each to introduce itself. It is ignored by `cargo test`, because it needs a built app and a home of its own: copy the app out of the repository and run the test binary with nothing else in its environment.

```sh
copy=$(mktemp -d) home=$(mktemp -d /tmp/home.XXXX)
cp -Rp apps/macos/build/Build/Products/Debug/Blossom.app "$copy/"
binary=$(cargo test --package blossom-bridge --no-run --message-format=json | grep -o '"executable":"[^"]*blossom_bridge-[^"]*"' | cut -d'"' -f4)
env -i HOME="$home" PATH=/usr/bin:/bin BLOSSOM_APPLICATION="$copy/Blossom.app" "$binary" --ignored a_built_app
codesign --verify --deep --strict "$copy/Blossom.app"
```

The home goes under `/tmp` because the path of a socket holds 103 bytes at most. The last line shows that nothing in the app was written while its adapters ran.

## Generated files

`generated/`, `build/`, `declarations/`, `target/` and `*.xcodeproj` are ignored by git and never edited. The Xcode project and the `Info.plist` come from `project.yml`: change that file, never Xcode's project settings.

## Checks behind lint

| Language | Check | Catches |
|---|---|---|
| Rust | `#![deny(unused, dead_code)]` in every crate | unused items |
| Rust | clippy with `-D warnings` | lints as errors |
| Rust | cargo-machete | unused dependencies |
| TypeScript | oxlint | lints, unused variables and imports |
| TypeScript | oxfmt `--check` | formatting |
| TypeScript | knip | unused files, exports and dependencies |
| TypeScript | tsc, strict | types |
| Swift | warnings as errors | compiler warnings |
| Swift | swift-format `--strict` | formatting and style |
| Swift | periphery | unused declarations |
| All | `scripts/naming.ts` | names that are not one lowercase word |
| Plugins | `cargo run --package blossom-harness --bin index -- <package>` in the lint of each plugin | an entry of `plugins/index.json` that no longer says what the plugin asks for and contributes |
| All | `scripts/table.ts --check` | a table of `plugins/README.md`, or a list of folders, that `plugins/index.json` does not match |

periphery does not build. It reads the index that `@blossom/macos#test` writes while it builds for testing, in `apps/macos/build/Index.noindex/DataStore`, which is why `@blossom/macos#lint` depends on that task. Every checkout has its own `build/`, so worktrees that lint at the same time never see each other's declarations.

## Caching

Turbo caches a task by hashing the files of its workspace, its workspace dependencies and the global files listed in `turbo.json`.

- Cargo tasks declare no outputs: cargo keeps its own incremental cache in `target/`.
- The build of an adapter caches its package, `build/`. The runtime is never in the cache of turbo: the app build copies it from the Bun that runs it.
- The bridge caches its bindings and its xcframework.
- The build of the landing caches `.next/`, without the cache and the development files Next.js keeps there. Its `lint` runs after its `build`, because both write the route types in `.next/`.
- The Xcode build and tests are never cached. Xcode's incremental build is faster than restoring derived data.
- The repository-wide lint is never cached, because its inputs are the whole repository.

## Hooks

Lefthook installs two git hooks.

- `pre-commit` runs on staged files only: the naming check, oxfmt, oxlint, rustfmt and swift-format. It is fast on purpose; clippy and periphery run in `lint` and in CI.
- `commit-msg` runs commitlint.

Claude Code has its own hook in `.claude/settings.json`: after every file edit it formats that file and checks its name, and reports a bad name back to the agent at once.

## Continuous integration

`.github/workflows/ci.yml` runs for every push to `main` and every pull request. It runs the same turbo tasks as a laptop, split into jobs so that each runs only where it must and only when the change can break it.

| Job | Runner | Runs when | What it runs |
|---|---|---|---|
| `changes` | Linux | always | Decides which jobs below start and how much they run, and fails when an affected workspace belongs to none of them. |
| `repository` | Linux | always | `@blossom/scripts#lint`: naming, oxlint, oxfmt, knip and `tsc` of the scripts, over the whole repository; and `@blossom/scripts#test`, the tests of `scripts/release.ts`. |
| `typescript` | macOS | an adapter or `sdks/adapter` is affected | `lint`, `build` and `test` of `adapters/*` and `sdks/adapter`; the `build` of an adapter is its package. |
| `rust` | Linux | a crate in `crates/` or an app in `apps/` other than `apps/macos` and `apps/landing` is affected | `lint`, `build` and `test` of every crate and of those apps, such as `apps/catalog`; of the bridge only `lint` and `test`, because its `build` is the xcframework. |
| `landing` | Linux | `apps/landing` is affected, or a file it publishes changed: `documentation/`, `README.md`, the `README.md` or `package.json` of an adapter, or the logos of `apps/macos/resources/logos/catalog.json` | `lint` and `build` of `@blossom/landing`, with Bun only: no Rust toolchain. The cache of Next.js is kept between runs. |
| `plugins` | Linux | a plugin or a plugin SDK in `sdks/` is affected, or `plugins/index.json` changed | `lint`, `build` and `test` of `plugins/*` and of every workspace under `sdks/`, nested ones such as those of `sdks/assemblyscript` included, but `sdks/adapter`, then the index of the plugins checked against every manifest with `bun run index -- --check`. Three legs of one matrix, each on its own runner: `plugins` for `plugins/*`, `harness` for `sdks/harness` and the check of the index, `sdks` for the rest. |
| `macos` | macOS 26, Xcode 26.5 | a file under `apps/macos/` or `crates/`, a Cargo or Bun manifest or lockfile, `rust-toolchain.toml`, `turbo.json`, `scripts/bootstrap.sh` or `scripts/bundle.ts` changed | Every task of `@blossom/macos` and what it depends on: the bindings, the xcframework, the packages of the adapters, the app with them and the runtime, its tests, swift-format and periphery; then `--selftest` on the app it built. |
| `compatibility` | macOS 15, Xcode 16.0 | a push to `main`, and a pull request that changes `.github/` or `apps/macos/project.yml` | The same app built and tested with the oldest Xcode Blossom supports, then `--selftest` on it. No lint: swift-format and periphery follow the Xcode of `macos`. When it fails it keeps the crash reports of the runner, `~/Library/Logs/DiagnosticReports`, as the artifact `crashes-<commit>` for seven days, since a test bundle that traps leaves only `Trace/BPT trap: 5` in the log. |
| `verify` | Linux | always | Fails if any job above failed or was cancelled. A job skipped because the change cannot break it counts as passed. This is the one check a pull request needs. |

What "affected" means is turbo's: a workspace with a changed file, every workspace that depends on it, and every workspace when a file in `globalDependencies`, `turbo.json` or `bun.lock` changed. `globalDependencies` names the root `package.json`, whose `packageManager` pins the Bun that the app brings inside it, so a new version of Bun builds everything again instead of reusing a cached app with the older one. In a pull request the comparison is with the first parent of the merge commit GitHub tests, which is the tip of `main`, so a pull request is checked against what it would merge into. No build, lint or test reads a Markdown file, so a change made only of Markdown files, the `README.md` of a workspace included, starts only `repository`.

Two cases run everything, every task executed again with `turbo --force`: a push to `main`, and a pull request that changes anything under `.github/`. `main` runs complete on every push because it is what every pull request is compared with and what seeds the caches they read; a push to `main` never cancels the run of the previous one. A pull request cancels its own run when a newer commit arrives.

Three jobs need a Mac. `macos` builds the app, on `macos-26` with `DEVELOPER_DIR` set to `/Applications/Xcode_26.5.app`, the runner and Xcode the release builds with, both pinned so neither moves when GitHub changes `macos-latest` or the default Xcode of an image; see [../roadmap/distribution.md](../roadmap/distribution.md#the-release-workflow). Moving them is one change to `ci.yml`, `release.yml` and this page. `compatibility` builds it again with the oldest Xcode Blossom supports, 16.0, the first with Swift 6, which `project.yml` asks for, so code that only a newer Xcode accepts fails on `main` and not on a contributor's machine. It runs on the oldest macOS image GitHub still offers: in December 2026 that is `macos-15`, Apple silicon, with Xcode 16.0 to 26.3 installed side by side, and `DEVELOPER_DIR` picks `/Applications/Xcode_16.app`. `turbo.json` names that variable in `globalEnv`: turbo hands a task only the variables it is told about, and without it every `xcodebuild` of the job fell back to the default Xcode of the image, 16.4, while the job said 16.0. GitHub no longer offers macOS 14, so the deployment target of `project.yml` is checked by the compiler, which refuses an API newer than macOS 14 without a check of availability, but the app never runs on macOS 14 in CI; that stays a check by hand, step 4 of "Full screen and displays" in [../roadmap/checks.md](../roadmap/checks.md). It does not start for an ordinary pull request, so the path of one is as long as before: it runs beside the complete run of every push to `main`, and in a pull request that changes the workflows or `project.yml`, where the Xcode or the deployment target is set. When GitHub retires `macos-15`, the job moves to the oldest image left and this paragraph says which Xcode it keeps. `typescript` tests adapters that only run on macOS, and two tests of the Claude Code adapter fail on Linux because the socket code of `sdks/adapter` relies on what macOS does: connecting to a file that is not a socket fails there with another error than a socket nobody listens on, and a removed file never hands its inode number to the next one. The job needs only Bun, so it takes a Mac for a minute or two. It runs one task at a time: the hook tests of several adapters start many shells, and run together they once used up the processes a macOS runner allows. The Linux jobs do not run `bun run bootstrap`, which needs Homebrew and Xcode: they install the pinned toolchain with `rustup toolchain install` and cargo-machete with `cargo install`, through `.github/actions/rust`.

`plugins` is split because every test of a plugin asks it through the real host, one test at a time, and the battery of the harness runs about twenty scenarios for each plugin: in one job on one Linux runner it took from 18 to 28 minutes in December 2026, 17 of them for the tests of `sdks/harness` alone, and grew with every plugin. Each leg compiles the core again, but the three run side by side, and a leg with nothing affected stops after its setup. Split, with their cargo cache restored, `plugins` took 14 minutes, `harness` 12 to 15 and `sdks` 6; a leg without it took 6 to 18 minutes more, `harness` up to 30 in all.

The cargo cache of `compatibility` is its own, since it builds with another Xcode, and `main` seeds it like the others. Without it the job takes 40 to 50 minutes, most of them compiling the core three times, once for the bindings and once for each architecture of the xcframework.

Two caches keep repeated work out:

- **Cargo.** `Swatinem/rust-cache` keeps the compiled dependencies and `~/.cargo`, one cache per job, the three legs of `plugins` sharing one, keyed by the toolchain, the lockfiles and the Rust toolchains of the runner image. Only a push to `main` saves it, and only when the job passed and no cache with that key exists; pull requests and runs started by hand only read it, and one that changes `Cargo.lock` restores the closest cache of `main` and compiles the rest. GitHub keeps 10 GB of caches for a repository and evicts the least recently used beyond that: while every pull request saved its own, 1 to 2 GB for each job, a night of merges took the repository to 11.2 GB, the caches of `main` were evicted, and the next runs compiled everything again. The key also names every Rust toolchain installed on the runner: while GitHub rolls out an image that brings another, as in December 2026 with 1.100.1 beside the pinned 1.100.0, runs on the old and the new image miss each other's cache until `main` has saved both. A cancelled or failed job saves nothing, because a cache with an exact key is never saved again and a half-built one would stay until the lockfile changes. The crates of the workspace are always compiled.
- **Turbo.** `.turbo/cache` is kept with `actions/cache` in the Rust, plugin and macOS jobs, one per leg of `plugins`, so a task whose inputs did not change replays its log instead of running. That is what spares a pull request that does not touch the bridge the release build of the xcframework. Entries older than seven days are evicted. The app's own build, tests and lint are never cached, as on a laptop; Xcode's derived data is not cached either, since building the app takes well under a minute.


### Actions and permissions

Every action from outside the repository is pinned to the full SHA of a commit, never to a tag, so a tag moved upstream changes nothing here. The workflows carry no comments, so the version each SHA stands for is kept in this table:

| Action | Version | Commit |
|---|---|---|
| `actions/checkout` | v4.4.0 | `11d5960a326750d5838078e36cf38b85af677262` |
| `actions/cache` | v4.3.0 | `0057852bfaa89a56745cba8c7296529d2fc39830` |
| `actions/upload-artifact` | v4.6.2 | `ea165f8d65b6e75b540449e92b4886f43607fa02` |
| `actions/download-artifact` | v8.0.2 | `9000827ccba6bdab643e8b6fd33ac0654aef8333` |
| `actions/upload-pages-artifact` | v5.0.0 | `fc324d3547104276b827a68afc52ff2a11cc49c9` |
| `actions/deploy-pages` | v5.0.1 | `368f82528645a54fb793d4d04e342629a3f51346` |
| `oven-sh/setup-bun` | v2.2.0 | `0c5077e51419868618aeaa5fe8019c62421857d6` |
| `Swatinem/rust-cache` | v2.9.3 | `d1527c8f67ef9af357290475d4af4b0fab8f12e0` |

A change that moves an action, one from Dependabot included, updates its row in the same pull request. To check a row, `gh api repos/<owner>/<action>/tags` lists the tags of an action with the commit of each.

Every workflow gives its token `contents: read` and nothing more, and `verify`, which checks nothing out, gets no permission at all. Every checkout sets `persist-credentials: false`, so the token is not left in the git configuration of the runner for later steps to read. No job pushes or comments. Two jobs of `.github/workflows/catalog.yml`, which runs only on `main`, are the exceptions: `sign` gets no permission and the secret of the environment `catalog`, and `deploy`, the one job that publishes, gets `pages: write` and `id-token: write` and checks nothing out; see [../roadmap/catalog.md](../roadmap/catalog.md#continuous-integration). One job of the release workflow publishes too: `publish`, the only one with `contents: write`, which holds no secret, checks out nothing and leaves a draft for the maintainer; its job with a secret, `sign`, checks out nothing either. The release workflow downloads one tool from outside the package managers, `sign_update` from the archive of the Sparkle release `project.yml` pins, checked against a SHA-256 written in the workflow.

### The release workflow

`.github/workflows/release.yml` runs `check`, `build`, `sign` and `publish` when the maintainer pushes a tag `v*`; [../roadmap/distribution.md](../roadmap/distribution.md#the-release-workflow) says what each checks and holds. A pull request that changes `release.yml`, `scripts/release.ts`, `apps/macos/project.yml` or `apps/macos/package.json` runs `check` and `build` as a rehearsal: everything a tag runs up to the archive, its checks and its feed, without the tag, the history, the dated section of the changelog, the keys, the signature or a release. It caches nothing between runs, so a release builds from its sources alone; `check` runs the lint, the build and the tests of every workspace, which takes longer than CI.

### Dependency updates

`.github/dependabot.yml` asks Dependabot once a week for new versions of the actions, the crates of the Cargo workspace and the packages of the Bun workspaces. Minor and patch versions of one ecosystem come together in one pull request; a new major version comes alone. Each pull request runs CI like any other and merges only when `verify` is green.

- A pull request that moves an action also updates the table above, by hand.
- A new version of `quickjs-wasi` fails the tests until `ENGINE_DIGEST` changes with it, as [../decisions/javascript.md](../decisions/javascript.md) says. That is the point: the engine changes only on purpose.
- Dependabot writes its own commit messages, which can break the commit rules, with an uppercase owner or a long header. Give the merge commit a subject that follows them.
- Not covered: the Rust toolchain of `rust-toolchain.toml`, Sparkle, which `apps/macos/project.yml` pins with `exactVersion` and `release.yml` names with the SHA-256 of its archive, so a new version changes both and the table of the release, and the tools `bun run bootstrap` installs.
