Skip to content

ci: add ccache/sccache compilation caching to speed up CI builds#360

Open
Cuiyus wants to merge 7 commits intoalibaba:mainfrom
Cuiyus:ci/ccache-sccache-optimization
Open

ci: add ccache/sccache compilation caching to speed up CI builds#360
Cuiyus wants to merge 7 commits intoalibaba:mainfrom
Cuiyus:ci/ccache-sccache-optimization

Conversation

@Cuiyus
Copy link
Copy Markdown
Collaborator

@Cuiyus Cuiyus commented Apr 20, 2026

  • add ccachecompilation caching to speed up CI builds (Windows is unable to enable cache acceleration because sccache cannot recognize /FS)
  • switch MacOS & Linux build from Unix Makefiles to Ninja generator

- Use hendrikmuhs/ccache-action@v1.2 for Linux/macOS/iOS/Android/clang-tidy
  (auto-installs ccache, manages cache, sets env vars, shows stats)
- Use mozilla-actions/sccache-action@v0.0.9 for Windows (MSVC compatible)
- Add CMAKE_C/CXX_COMPILER_LAUNCHER to all CMake build steps
- Exclude wheel build and nightly coverage workflows per decision
Cuiyus added 5 commits April 21, 2026 15:45
- Replace CMAKE_GENERATOR='Unix Makefiles' with 'Ninja' in pip build
- Replace 'make unittest -j' with 'cmake --build --target unittest --parallel'
- Add '-G Ninja' to C++ and C example cmake configure steps
- Replace 'make -j' with 'cmake --build --parallel' for examples
- Aligns with Windows and Android workflows which already use Ninja
- Use CMake ProcessorCount module to detect available CPU cores
- Add -j ${NPROC} to ctest command for parallel test execution
- Add --timeout 300 to prevent individual tests from hanging CI
- Fallback to NPROC=1 when ProcessorCount returns 0
- iOS target unchanged (build-only, no test execution)
Windows (05-windows-build.yml):
- Remove mozilla-actions/sccache-action: sccache incompatible with MSVC /FS flag
- Remove SCCACHE_GHA_ENABLED env var
- Remove CMAKE_C/CXX_COMPILER_LAUNCHER=sccache from build steps
- Remove 'Show sccache statistics' step
- MSVC /FS (global PDB concurrency flag) causes fatal C1041 when used with sccache

MacOS & Linux (03-macos-linux-build.yml):
- Fix cmake.define values: remove extra quotes around 'ccache' and 'ON'
- Bare values required: cmake.define.FOO=bar not cmake.define.FOO="bar"
@Cuiyus Cuiyus requested a review from feihongxu0824 April 21, 2026 08:00
uses: actions/cache@v5
with:
path: build_host
key: ${{ runner.os }}-host-protoc-${{ hashFiles('thirdparty/protobuf/**', 'CMakeLists.txt') }}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是不是也可以优化下?包括下面的if [ ! -f "build_host/bin/protoc" ]

Copy link
Copy Markdown
Collaborator Author

@Cuiyus Cuiyus Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里暂不需要优化。因为protoc 的编译有两层cache用来加速。第一层的是action@cache(目录级cache),而protoc 这种thirdparty 修改频率很低,一般不会cache miss,若出现miss 会采用编译器出现的ccache. (如果缓存紧张的话,可以去掉 protoc的ccache)

key: ios-${{ matrix.platform }}

- name: Cache host protoc build
uses: actions/cache@v5
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是不是可以去掉?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要。目前多平台(除windows)的ci都是加了两层cache加速。整个cache用量目前在2G左右。

image

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macOS和linux的是一层cache吧?两层指的是?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

两层cache加速的效果应该不大吧?另外这里的cache size也会随着action的运行累加,比如此时此刻

Image

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

主要是ios的cache比较大(~890MB+350MB),这里用两层感觉有点浪费

- name: Setup ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ inputs.platform }}-${{ inputs.os }}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把compiler也加到key上吧,不然也容易cache miss吧?

key: ios-${{ matrix.platform }}

- name: Cache host protoc build
uses: actions/cache@v5
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macOS和linux的是一层cache吧?两层指的是?

key: ios-${{ matrix.platform }}

- name: Cache host protoc build
uses: actions/cache@v5
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

两层cache加速的效果应该不大吧?另外这里的cache size也会随着action的运行累加,比如此时此刻

Image

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.

2 participants