Skip to content

Commit 5e46e52

Browse files
hjmjohnsonclaude
andcommitted
ENH: Optimize GitHub Actions ccache strategy for faster C++ builds
Key changes from upstream: 1. Remove CCACHE_NODIRECT=1: Enables direct mode so ccache skips the preprocessor for cache lookups, significantly faster on hits. 2. Add CCACHE_SLOPPINESS=pch_defines,time_macros: Avoids cache misses caused by __DATE__/__TIME__ macros that change every build. Standard CI-safe setting. 3. CCACHE_MAXSIZE 2.4G -> 5G: ITK has ~4000 translation units; a larger cache retains more objects across incremental builds. 4. SHA-based cache key with restore-keys fallback: - key: ccache-v4-<os>-<config>-<sha> (unique per commit) - restore-keys: ccache-v4-<os>-<config>- (most recent match) Each build creates a new cache entry; restore-keys always finds the most recent cache for the same OS and configuration. Replaces the old static key that could never be updated once written. 5. Save on !cancelled() instead of main-only: PR builds now persist their cache for subsequent pushes, but cancelled runs do not save potentially incomplete caches. 6. Use runner.os (Linux/macOS/Windows) instead of matrix.os (ubuntu-24.04-arm/macos-15) for cache key consistency across runner image updates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1e27859 commit 5e46e52

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

.github/workflows/arm.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ jobs:
9494
echo "CCACHE_BASEDIR=${GITHUB_WORKSPACE}" >> "$GITHUB_ENV"
9595
echo "CCACHE_COMPILERCHECK=content" >> "$GITHUB_ENV"
9696
echo "CCACHE_NOHASHDIR=true" >> "$GITHUB_ENV"
97-
echo "CCACHE_NODIRECT=1" >> "$GITHUB_ENV"
97+
echo "CCACHE_SLOPPINESS=pch_defines,time_macros" >> "$GITHUB_ENV"
9898
echo "CCACHE_DIR=${{ runner.temp }}/ccache" >> "$GITHUB_ENV"
99-
echo "CCACHE_MAXSIZE=2.4G" >> "$GITHUB_ENV"
99+
echo "CCACHE_MAXSIZE=5G" >> "$GITHUB_ENV"
100100
if [ "$RUNNER_OS" == "Linux" ]; then
101101
sudo apt-get update -qq && sudo apt-get install -y ccache locales
102102
sudo locale-gen de_DE.UTF-8
@@ -109,7 +109,9 @@ jobs:
109109
uses: actions/cache/restore@v5
110110
with:
111111
path: ${{ runner.temp }}/ccache
112-
key: ccache-v1-${{ matrix.os }}-${{ matrix.name }}
112+
key: ccache-v4-${{ runner.os }}-${{ matrix.name }}-${{ github.sha }}
113+
restore-keys: |
114+
ccache-v4-${{ runner.os }}-${{ matrix.name }}-
113115
114116
- name: Show ccache configuration, stats and maintenance
115117
shell: bash
@@ -170,11 +172,11 @@ jobs:
170172
env:
171173
CTEST_OUTPUT_ON_FAILURE: 1
172174
- name: Save compiler cache
173-
if: github.ref == 'refs/heads/main'
175+
if: ${{ !cancelled() }}
174176
uses: actions/cache/save@v5
175177
with:
176178
path: ${{ runner.temp }}/ccache
177-
key: ccache-v1-${{ matrix.os }}-${{ matrix.name }}
179+
key: ccache-v4-${{ runner.os }}-${{ matrix.name }}-${{ github.sha }}
178180

179181
- name: ccache stats
180182
if: always()

.github/workflows/pixi.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ jobs:
5353
echo "CCACHE_BASEDIR=${GITHUB_WORKSPACE}" >> "$GITHUB_ENV"
5454
echo "CCACHE_COMPILERCHECK=content" >> "$GITHUB_ENV"
5555
echo "CCACHE_NOHASHDIR=true" >> "$GITHUB_ENV"
56-
echo "CCACHE_NODIRECT=1" >> "$GITHUB_ENV"
56+
echo "CCACHE_SLOPPINESS=pch_defines,time_macros" >> "$GITHUB_ENV"
5757
echo "CCACHE_DIR=${{ runner.temp }}/ccache" >> "$GITHUB_ENV"
58-
echo "CCACHE_MAXSIZE=2.4G" >> "$GITHUB_ENV"
58+
echo "CCACHE_MAXSIZE=5G" >> "$GITHUB_ENV"
5959
if [ "$RUNNER_OS" == "Linux" ]; then
6060
sudo apt-get update -qq && sudo apt-get install -y ccache locales
6161
sudo locale-gen de_DE.UTF-8
@@ -70,7 +70,9 @@ jobs:
7070
uses: actions/cache/restore@v5
7171
with:
7272
path: ${{ runner.temp }}/ccache
73-
key: ccache-v1-${{ matrix.os }}-pixi-cxx
73+
key: ccache-v4-${{ runner.os }}-pixi-cxx-${{ github.sha }}
74+
restore-keys: |
75+
ccache-v4-${{ runner.os }}-pixi-cxx-
7476
7577
- name: Show ccache configuration, stats and maintenance
7678
shell: bash
@@ -150,11 +152,11 @@ jobs:
150152
echo "****** df -h /"
151153
df -h /
152154
- name: Save compiler cache
153-
if: github.ref == 'refs/heads/main'
155+
if: ${{ !cancelled() }}
154156
uses: actions/cache/save@v5
155157
with:
156158
path: ${{ runner.temp }}/ccache
157-
key: ccache-v1-${{ matrix.os }}-pixi-cxx
159+
key: ccache-v4-${{ runner.os }}-pixi-cxx-${{ github.sha }}
158160

159161
- name: ccache stats
160162
if: always()

0 commit comments

Comments
 (0)