A Github action to speedup building using ccache for C/C++ projects.
- name: ccache
uses: hendrikmuhs/ccache-action@v1
NB! This should always come after the actions/checkout
step.
In order to use ccache in your other steps, point the compiler to it, e.g. with run-cmake
:
- name: build with cmake
uses: lukka/run-cmake@v3
with:
cmakeListsOrSettingsJson: CMakeListsTxtAdvanced
cmakeAppendedArgs: '-DCMAKE_BUILD_TYPE=${{ matrix.type }} -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache'
...
or by manipulating PATH
:
- name: build
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
(works for both ubuntu
and macos
)
Ccache gets installed by this action, if its not installed yet.
If you have multiple targets(Debug
, Release
) and/or multiple OS's, it makes sense to cache them
separetely. An additional cache key can be specified.
You can also specify the maximum cache size - default 500M
(500 MB).
- name: ccache
uses: hendrikmuhs/ccache-action@v1
with:
key: ${{ matrix.os }}-${{ matrix.type }}
max-size: 100M
This action is based on https://cristianadam.eu/20200113/speeding-up-c-plus-plus-github-actions-using-ccache/
In a nutshell, the .ccache
folder is configured in the runner path and the folder is persisted and reloaded using cache
.
For more details see: https://docs.github.com/en/free-pro-team@latest/actions/guides/caching-dependencies-to-speed-up-workflows.
Stats are provided as part of the post action, check the output to see if cache is effective.