Skip to content

Cache Xcode build products in CI - #16

Merged
RISCfuture merged 1 commit into
mainfrom
ci/cache-build-products
Sep 1, 2026
Merged

Cache Xcode build products in CI#16
RISCfuture merged 1 commit into
mainfrom
ci/cache-build-products

Conversation

@RISCfuture

Copy link
Copy Markdown
Contributor

Every CI run recompiled this app's SwiftPM dependencies from scratch. The existing SwiftPM cache covered only checkouts — and cloning was never the cost, compilation was.

Also fixes a cache that was silently doing nothing

The existing Cache SwiftPM dependencies step globbed ~/Library/Developer/Xcode/DerivedData/**/SourcePackages/checkouts, but these jobs build with an explicit -derivedDataPath. That glob matched nothing — the step was a no-op apart from the SwiftPM download cache.

Key design

Exact-match, no restore-keys — a partial restore of compiled objects across a changed dependency graph is how a stale-artifact bug gets in. The key records the resolved xcodebuild -version rather than the pinned label, so a toolchain bump rotates it instead of silently reusing objects built by a different compiler.

Only Build and SourcePackages are cached — not Index.noindex. This matters for Periphery: an index unit outlives the source it was built from, and an exact-match key on Package.resolved can't invalidate on a first-party source change, so a restored index could let Periphery read units for deleted or renamed files — a spurious --strict failure or a silently missed finding.

The SwiftPM download cache uses one identical path across every job. This is deliberate and was learned the hard way (see below).

A bug the canary caught

The first version gave each job its own SourcePackages/checkouts path under a shared key. GitHub derives a cache version from the path list, so identical keys with differing paths produce separate entries — five near-identical 1.2 GiB copies, duplicating content the build-product cache already held. Zephyr reached 10.57 GiB against GitHub's 10 GB per-repo limit, where eviction would have quietly undermined the caching this change exists to add. Now one shared entry per repo.

Measured on the canary

Validated on RISCfuture/Zephyr, cold then warm:

Job Cold Warm Saving
Build App 5m14s 3m04s 41%
Unit Tests 4m22s 2m56s 33%
UI Tests 8m51s 6m47s 23%

The log confirms a 1201 MB derived-data restore followed by a successful warm build — so building on restored derived data is verified, not assumed.

Note

actionlint and yamllint clean. This PR's own run is a guaranteed cache miss.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SRgQmnzeh3vsVKudXWs3RV

Every CI run recompiled the SwiftPM dependencies from scratch. Cloning
was never the cost -- compilation was. Cache the derived data Build
directory so an unchanged dependency graph and toolchain reuse the
compiled objects.

The key is exact-match with no restore-keys, and records the resolved
`xcodebuild -version` rather than the pinned label, so a toolchain bump
rotates it instead of silently serving objects built by another compiler.

Only Build and SourcePackages are cached; the index store is regenerated
each run rather than restored, since an index unit outlives the source it
was built from and the key cannot invalidate on a first-party source
change.

The SwiftPM download cache uses one identical path across every job. Its
DerivedData glob matched nothing -- these jobs build with an explicit
-derivedDataPath -- and a per-job path under one shared key would make
GitHub store a separate near-identical entry per job.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SRgQmnzeh3vsVKudXWs3RV
@RISCfuture
RISCfuture merged commit 640560d into main Sep 1, 2026
8 checks passed
@RISCfuture
RISCfuture deleted the ci/cache-build-products branch September 1, 2026 04:39
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