Skip to content

Cache SwiftPM build products in CI - #1

Open
RISCfuture wants to merge 1 commit into
mainfrom
ci/cache-build-products
Open

Cache SwiftPM build products in CI#1
RISCfuture wants to merge 1 commit into
mainfrom
ci/cache-build-products

Conversation

@RISCfuture

Copy link
Copy Markdown
Contributor

Every CI run recompiled this package's dependencies from scratch. This caches .build alongside the SwiftPM download caches, so a run whose dependency graph and toolchain are unchanged reuses the compiled objects.

Not cached: lint (SwiftLint) and swift-format — both parse source without compiling, so there are no build products to reuse.

Key design

Exact-match, no restore-keys. Objects built against a different dependency graph or toolchain must never be reused, and a partial prefix restore is precisely how a stale-artifact bug gets in. Matrix jobs carry both the OS and the Swift version, so macOS objects can never restore onto a Linux leg, nor 6.1 objects onto a 6.3 toolchain. Each compiling job has its own key prefix so jobs building different products don't clobber one another.

Measured on the canary

This exact pattern was validated on RISCfuture/hearts before rollout, with a cold run followed by a warm one:

Job Cold Warm Saving
Build 3m55s 1m29s 62%
Build Documentation 2m58s 52s 71%
Periphery 2m06s 1m13s 42%

Each key hit independently, confirming the per-job prefixes work as intended.

Note

actionlint and yamllint are clean. This PR's own run is a guaranteed cache miss — the entries don't exist yet. It proves the workflows still pass; a second run is what demonstrates the hit.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SRgQmnzeh3vsVKudXWs3RV

Every CI run recompiled the package's dependencies from scratch. Cache
`.build` alongside the SwiftPM download caches so a run whose dependency
graph and toolchain are unchanged reuses the compiled objects.

The key is exact-match with no restore-keys: objects built against a
different dependency graph or toolchain must never be reused, and a
partial restore is how a stale-artifact bug gets in. Matrix jobs put both
the OS and the Swift version in the key, so macOS objects can never land
on a Linux leg. Each compiling job gets its own key prefix. The lint and
swift-format jobs parse source without compiling it and are left alone.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SRgQmnzeh3vsVKudXWs3RV
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