Skip to content

Commit 9b5e7ec

Browse files
ci: persist ccache across hosted runners
Use the platform-aware ccache action and content-based compiler checks so reinstalled toolchains and changing checkout paths do not invalidate every object. Normalize base/hash directory behavior and report hit statistics.
1 parent 05c78ea commit 9b5e7ec

1 file changed

Lines changed: 28 additions & 20 deletions

File tree

‎.github/workflows/cmake-single-platform.yml‎

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ on:
99

1010
env:
1111
BUILD_TYPE: Release
12+
# GitHub runners reinstall toolchains under changing file mtimes. Hashing
13+
# compiler contents and normalizing the checkout directory makes ccache
14+
# reusable across runs while still invalidating on a real compiler change.
15+
CCACHE_BASEDIR: ${{ github.workspace }}
16+
CCACHE_COMPILERCHECK: content
17+
CCACHE_COMPRESS: "true"
18+
CCACHE_MAXSIZE: 2G
19+
CCACHE_NOHASHDIR: "true"
1220

1321
jobs:
1422
build:
@@ -30,26 +38,6 @@ jobs:
3038
steps:
3139
- uses: actions/checkout@v4
3240

33-
# ========== 缓存:ccache(Linux) ==========
34-
- name: Cache ccache (Linux)
35-
if: runner.os == 'Linux'
36-
uses: actions/cache@v4
37-
with:
38-
path: ~/.cache/ccache
39-
key: ${{ runner.os }}-ccache-${{ github.sha }}
40-
restore-keys: |
41-
${{ runner.os }}-ccache-
42-
43-
# ========== 缓存:ccache(Windows) ==========
44-
- name: Cache ccache (Windows)
45-
if: runner.os == 'Windows'
46-
uses: actions/cache@v4
47-
with:
48-
path: C:\Users\runneradmin\AppData\Local\ccache
49-
key: ${{ runner.os }}-ccache-${{ github.sha }}
50-
restore-keys: |
51-
${{ runner.os }}-ccache-
52-
5341
# 注意:不缓存整个 build 目录——旧 CMakeCache.txt 会跨运行携带已移除的
5442
# -D 设置(如历史上的 CMAKE_CXX_FLAGS=-stdlib=libc++),导致编译/链接
5543
# 标准库 ABI 不匹配(std::__cxx11::* 未定义)。编译产物由 ccache 缓存。
@@ -132,6 +120,23 @@ jobs:
132120
$llvmPath = "C:\Program Files\LLVM\bin"
133121
echo "$llvmPath" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
134122
123+
# 两边工具链安装完成后统一挂载 ccache。由 action 自己管理平台的默认
124+
# CCACHE_DIR、restore/save 与统计,避免手写 runner 路径漂移。
125+
- name: Mount ccache
126+
uses: hendrikmuhs/ccache-action@v1.2
127+
with:
128+
key: ${{ runner.os }}-ccache-v2-release-clang
129+
restore-keys: |
130+
${{ runner.os }}-ccache-v2-
131+
${{ runner.os }}-ccache-
132+
max-size: 2G
133+
verbose: 1
134+
135+
- name: Inspect ccache mount
136+
run: |
137+
ccache --show-stats --verbose
138+
ccache --zero-stats
139+
135140
# ========== Windows: 缓存 Vulkan SDK(避免重复下载安装) ==========
136141
- name: Cache Vulkan SDK (Windows)
137142
id: cache-vulkan-windows
@@ -210,6 +215,9 @@ jobs:
210215
- name: Build
211216
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
212217

218+
- name: Report ccache usage
219+
run: ccache --show-stats --verbose
220+
213221
# ========== 真跑测试(roadmap P0-1)==========
214222
# 需 Vulkan 的用例在无 GPU 的 runner 上按退出码 77 记 skip(非失败)。
215223
- name: Test ctest (Linux)

0 commit comments

Comments
 (0)