This is an automated email from the ASF dual-hosted git repository. sjanc pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 2f9a460762b1d53574dd98507977f0e65db94425 Author: Szymon Janc <[email protected]> AuthorDate: Wed Oct 14 00:54:42 2026 +0200 ci: Add ccache support for build jobs Build jobs compile same sources on every run. Add composite actions that set up ccache in front of compilers used by newt and restore and save ccache directory, and use them in all build and test jobs on Linux. Ports Makefiles already use ccache, so ports job only needs ccache directory to be restored and saved. ccache directory is saved only from master branch, so pull requests use cache from latest master build. Before saving, entries not used by current job are removed so that cache does not grow over time. If job had no cache misses, restored cache already contains everything used by job and is not saved again. CodeQL job is not using ccache as compilations served from cache would not be seen by CodeQL. Assisted-by: Claude:claude-opus-5-5 --- .github/actions/ccache-restore/action.yml | 77 +++++++++++++++++++++++++++++++ .github/actions/ccache-save/action.yml | 67 +++++++++++++++++++++++++++ .github/workflows/build_all_apps.yml | 11 ++++- .github/workflows/build_cc_target.yml | 9 ++++ .github/workflows/build_ports.yml | 9 ++++ .github/workflows/build_targets.yml | 11 ++++- .github/workflows/newt_test_all.yml | 11 ++++- 7 files changed, 192 insertions(+), 3 deletions(-) diff --git a/.github/actions/ccache-restore/action.yml b/.github/actions/ccache-restore/action.yml new file mode 100644 index 000000000..13ae7ab5c --- /dev/null +++ b/.github/actions/ccache-restore/action.yml @@ -0,0 +1,77 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +name: Restore ccache +description: > + Install ccache, put it in front of compilers used by newt and restore + ccache directory from cache. Must be used after toolchain is installed + so that ccache wrappers are found in PATH before real compilers. + Supported only on Linux, does nothing on other systems. + +inputs: + key: + description: Cache key, unique for job (and matrix entry) + required: true + max-size: + description: Maximum size of ccache directory + required: false + default: 500M + +runs: + using: composite + steps: + - name: Set up ccache + if: runner.os == 'Linux' + shell: bash + run: | + if ! command -v ccache > /dev/null; then + sudo apt-get update + sudo apt-get install -y ccache + fi + # Wrappers named as compilers used by newt, ccache finds real + # compiler by skipping its own directory in PATH. + dir="$RUNNER_TEMP/ccache-bin" + mkdir -p "$dir" + for c in arm-none-eabi-gcc arm-none-eabi-g++ gcc g++; do + ln -sf "$(command -v ccache)" "$dir/$c" + done + echo "$dir" >> "$GITHUB_PATH" + { + echo "CCACHE_DIR=$RUNNER_TEMP/ccache" + echo "CCACHE_BASEDIR=$GITHUB_WORKSPACE" + echo "CCACHE_NOHASHDIR=true" + echo "CCACHE_COMPILERCHECK=content" + echo "CCACHE_MAXSIZE=${{ inputs.max-size }}" + echo "CCACHE_JOB_START=$(date +%s)" + } >> "$GITHUB_ENV" + + - name: Restore ccache directory + if: runner.os == 'Linux' + uses: actions/cache/restore@v6 + with: + path: ${{ runner.temp }}/ccache + key: ccache-${{ inputs.key }}-${{ github.sha }} + restore-keys: ccache-${{ inputs.key }}- + + - name: Reset ccache statistics + if: runner.os == 'Linux' + shell: bash + run: | + ccache --version | head -1 + ccache --zero-stats diff --git a/.github/actions/ccache-save/action.yml b/.github/actions/ccache-save/action.yml new file mode 100644 index 000000000..bcea10b67 --- /dev/null +++ b/.github/actions/ccache-save/action.yml @@ -0,0 +1,67 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +name: Save ccache +description: > + Show ccache statistics, drop cache entries not used by current job and + save ccache directory to cache. Cache is saved only from master branch + since only caches from default branch are available to pull requests, + and only if there were cache misses, since otherwise restored cache + already contains everything used by job. + Supported only on Linux, does nothing on other systems. + +inputs: + key: + description: Cache key, same as used for ccache-restore + required: true + +runs: + using: composite + steps: + - name: Show ccache statistics + id: stats + if: runner.os == 'Linux' + shell: bash + run: | + ccache --show-stats + misses=$(ccache --print-stats | awk '$1 == "cache_miss" { print $2 }') + echo "misses=${misses:-unknown}" >> "$GITHUB_OUTPUT" + + - name: Remove unused ccache entries + if: >- + runner.os == 'Linux' && github.ref == 'refs/heads/master' && + github.event_name != 'pull_request' && + steps.stats.outputs.misses != '0' + shell: bash + run: | + # Keep only entries used by this job so that cache size does not + # grow over time with stale entries. + age=$(( $(date +%s) - CCACHE_JOB_START + 60 )) + ccache --evict-older-than "${age}s" + ccache --show-stats | grep -i 'cache size' || true + + - name: Save ccache directory + if: >- + runner.os == 'Linux' && github.ref == 'refs/heads/master' && + github.event_name != 'pull_request' && + steps.stats.outputs.misses != '0' + uses: actions/cache/save@v6 + with: + path: ${{ runner.temp }}/ccache + key: ccache-${{ inputs.key }}-${{ github.run_id }}-${{ github.run_attempt }} diff --git a/.github/workflows/build_all_apps.yml b/.github/workflows/build_all_apps.yml index c619501d9..8dbc306e8 100644 --- a/.github/workflows/build_all_apps.yml +++ b/.github/workflows/build_all_apps.yml @@ -42,7 +42,7 @@ jobs: shell: bash run: | sudo apt-get update - sudo apt-get install -y gcc-multilib + sudo apt-get install -y gcc-multilib ccache - name: Install newt uses: ./.github/actions/newt-install - name: Set up project @@ -52,9 +52,18 @@ jobs: - name: Remove project targets shell: bash run: rm -rf build/targets + - name: Restore ccache + uses: ./.github/actions/ccache-restore + with: + key: apps - name: Build applications shell: bash run: | cd build bash ../.github/test_build_apps.sh cd .. + - name: Save ccache + if: always() + uses: ./.github/actions/ccache-save + with: + key: apps diff --git a/.github/workflows/build_cc_target.yml b/.github/workflows/build_cc_target.yml index 3e0c7cabd..e4d30c465 100644 --- a/.github/workflows/build_cc_target.yml +++ b/.github/workflows/build_cc_target.yml @@ -46,6 +46,10 @@ jobs: uses: ./.github/actions/newt-install - name: Set up project uses: ./.github/actions/newt-project + - name: Restore ccache + uses: ./.github/actions/ccache-restore + with: + key: gcc-target-${{ matrix.gcc }} - name: Build test target shell: bash run: | @@ -55,3 +59,8 @@ jobs: newt target set cc_test app="@apache-mynewt-nimble/apps/btshell" cp -f ../.github/test_build_apps_syscfg.yml targets/cc_test/syscfg.yml newt build cc_test + - name: Save ccache + if: always() + uses: ./.github/actions/ccache-save + with: + key: gcc-target-${{ matrix.gcc }} diff --git a/.github/workflows/build_ports.yml b/.github/workflows/build_ports.yml index 7297cc801..f8b48d4b1 100644 --- a/.github/workflows/build_ports.yml +++ b/.github/workflows/build_ports.yml @@ -68,6 +68,10 @@ jobs: echo "LIBRARY_PATH=${{ github.workspace }}/mbedtls_install/lib" >> $GITHUB_ENV echo "LD_LIBRARY_PATH=${{ github.workspace }}/mbedtls_install/lib" >> $GITHUB_ENV echo "MBEDTLS_DIR=${{ github.workspace }}/mbedtls_install" >> $GITHUB_ENV + - name: Restore ccache + uses: ./.github/actions/ccache-restore + with: + key: ports - name: Build example ports shell: bash run: | @@ -101,3 +105,8 @@ jobs: >> nuttx-build/apps/wireless/bluetooth/nimble/include/syscfg/syscfg.h make -C nuttx-build/nuttx olddefconfig make -C nuttx-build/nuttx + - name: Save ccache + if: always() + uses: ./.github/actions/ccache-save + with: + key: ports diff --git a/.github/workflows/build_targets.yml b/.github/workflows/build_targets.yml index 97de444c4..c9a808587 100644 --- a/.github/workflows/build_targets.yml +++ b/.github/workflows/build_targets.yml @@ -47,7 +47,7 @@ jobs: if: matrix.os == 'ubuntu-latest' run: | sudo apt-get update - sudo apt-get install -y gcc-multilib + sudo apt-get install -y gcc-multilib ccache - name: Install newt uses: ./.github/actions/newt-install - name: Set up project @@ -55,6 +55,10 @@ jobs: - name: Remove project targets shell: bash run: rm -rf build/targets + - name: Restore ccache + uses: ./.github/actions/ccache-restore + with: + key: targets - name: Build targets shell: bash run: | @@ -72,3 +76,8 @@ jobs: ls targets | xargs -n1 sh -c 'echo "Testing $0"; newt build -q $0' rm -rf targets cd .. + - name: Save ccache + if: always() + uses: ./.github/actions/ccache-save + with: + key: targets diff --git a/.github/workflows/newt_test_all.yml b/.github/workflows/newt_test_all.yml index 20d14114a..959918e79 100644 --- a/.github/workflows/newt_test_all.yml +++ b/.github/workflows/newt_test_all.yml @@ -39,13 +39,17 @@ jobs: shell: bash run: | sudo apt-get update - sudo apt-get install -y gcc-multilib + sudo apt-get install -y gcc-multilib ccache - name: Install newt uses: ./.github/actions/newt-install - name: Set up project uses: ./.github/actions/newt-project with: project: .github/project_newt_test_all.yml + - name: Restore ccache + uses: ./.github/actions/ccache-restore + with: + key: unit-tests - name: Switch to main mcuboot # This is temporary until next mcuboot release is available shell: bash @@ -58,3 +62,8 @@ jobs: run: | cd build newt test all + - name: Save ccache + if: always() + uses: ./.github/actions/ccache-save + with: + key: unit-tests
