Skip to content

Commit 350e92f

Browse files
action: cache the compiler cache between invocations
Set up the compiler cache (ccache) and cache it between invocations, speeding up incremental builds. Caching of the compiler cache between invocations can be disabled by setting "enable-ccache: false" when using the action. The ccache is limited to 512MB by default. Currently, ccache is only supported on Linux and macOS platforms. Co-authored-by: Fabio Baltieri <[email protected]> Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent dfda61e commit 350e92f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

action.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ inputs:
1919
required: false
2020
default: .
2121

22+
ccache-max-size:
23+
description: |
24+
Maximum size of the files stored in the compiler cache (ccache). Defaults to 512MB.
25+
required: false
26+
default: 512MB
27+
28+
enable-ccache:
29+
description: |
30+
Enable caching/restoring of compiler cache (ccache) files between invocations.
31+
Defaults to 'true'.
32+
required: false
33+
default: true
34+
2235
manifest-file-name:
2336
description: Name of the west workspace manifest file name in "app-path"
2437
required: false
@@ -121,16 +134,19 @@ runs:
121134
122135
if [ "${{ runner.os }}" = "Linux" ]; then
123136
pip_cache_path="~/.cache/pip"
137+
ccache_path="$HOME/.cache/ccache"
124138
sdk_ext="tar.xz"
125139
setup_file="./setup.sh"
126140
setup_opt="-"
127141
elif [ "${{ runner.os }}" = "macOS" ]; then
128142
pip_cache_path="~/Library/Caches/pip"
143+
ccache_path="$HOME/Library/Caches/ccache"
129144
sdk_ext="tar.xz"
130145
setup_file="./setup.sh"
131146
setup_opt="-"
132147
elif [ "${{ runner.os }}" = "Windows" ]; then
133148
pip_cache_path="~/AppData/Local/pip/Cache"
149+
ccache_path="$HOME/AppData/Local/ccache/Cache"
134150
sdk_ext="7z"
135151
setup_file="./setup.cmd"
136152
setup_opt="//"
@@ -156,6 +172,9 @@ runs:
156172
echo "SDK_VERSION=${sdk_version}" >> $GITHUB_ENV
157173
echo "SDK_FILE=zephyr-sdk-${sdk_version}_${sdk_variant}_minimal.${sdk_ext}" >> $GITHUB_ENV
158174
echo "PIP_CACHE_PATH=${pip_cache_path}" >> $GITHUB_ENV
175+
echo "CCACHE_TIMESTAMP=$(date +%s)" >> $GITHUB_ENV
176+
echo "CCACHE_DIR=${ccache_path}" >> $GITHUB_ENV
177+
echo "CCACHE_IGNOREOPTIONS=-specs=* --specs=*" >> $GITHUB_ENV
159178
echo "SETUP_FILE=${setup_file}" >> $GITHUB_ENV
160179
echo "SETUP_OPT=${setup_opt}" >> $GITHUB_ENV
161180
@@ -207,3 +226,20 @@ runs:
207226
${SETUP_FILE} ${SETUP_OPT}h
208227
fi
209228
${SETUP_FILE} ${SETUP_OPT}c
229+
230+
- name: Cache ccache data
231+
if: inputs.enable-ccache == 'true' && runner.os != 'Windows'
232+
uses: actions/cache@v4
233+
with:
234+
path: ${{ env.CCACHE_DIR }}
235+
key: ccache-${{ matrix.os }}-${{ matrix.release }}-${{ env.CCACHE_TIMESTAMP }}
236+
restore-keys: ccache-${{ matrix.os }}-${{ matrix.release }}-
237+
238+
- name: Set up ccache
239+
if: inputs.enable-ccache == 'true' && runner.os != 'Windows'
240+
shell: bash
241+
run: |
242+
mkdir -p ${{ env.CCACHE_DIR }}
243+
ccache -M ${{ inputs.ccache-max-size }}
244+
ccache -p
245+
ccache -z -s -vv

0 commit comments

Comments
 (0)