Cache Xcode build products in CI - #16
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 dependenciesstep 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 resolvedxcodebuild -versionrather than the pinned label, so a toolchain bump rotates it instead of silently reusing objects built by a different compiler.Only
BuildandSourcePackagesare cached — notIndex.noindex. This matters for Periphery: an index unit outlives the source it was built from, and an exact-match key onPackage.resolvedcan't invalidate on a first-party source change, so a restored index could let Periphery read units for deleted or renamed files — a spurious--strictfailure 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/checkoutspath 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.Zephyrreached 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: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
actionlintandyamllintclean. This PR's own run is a guaranteed cache miss.🤖 Generated with Claude Code
https://claude.ai/code/session_01SRgQmnzeh3vsVKudXWs3RV