From 845a19b6fd700813b24a59a7cf2fed172447a570 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Sat, 18 Apr 2026 19:23:49 +0200 Subject: [PATCH 1/6] CI: export CCACHE_DIR and CCACHE_CONFIGPATH2 to $GITHUB_ENV Rename the system ccache.conf path var from SYSTEM_CCACHE_CONF to CCACHE_CONFIGPATH2, the env var ccache itself reads for a secondary config, and make it absolute (rooted at github.workspace/openwrt/) so it matches the checkout layout rather than depending on working-directory: openwrt. Write both CCACHE_DIR and CCACHE_CONFIGPATH2 to $GITHUB_ENV from the configure step so every subsequent step inherits the same values. Previously each step had to redeclare CCACHE_DIR in its own env block and the "Show ccache stats" step was running without CCACHE_CONFIGPATH2 at all, so it never saw the system ccache.conf written during configuration. Link: https://github.com/openwrt/actions-shared-workflows/pull/103 Signed-off-by: Hauke Mehrtens --- .github/workflows/reusable_build.yml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/reusable_build.yml b/.github/workflows/reusable_build.yml index ffb8e6b..d14eceb 100644 --- a/.github/workflows/reusable_build.yml +++ b/.github/workflows/reusable_build.yml @@ -534,6 +534,15 @@ jobs: echo CONFIG_TARGET_PER_DEVICE_ROOTFS=y >> .config echo CONFIG_TARGET_ALL_PROFILES=y >> .config + - name: Export ccache environment + if: inputs.use_ccache_cache == true + env: + CCACHE_DIR: ${{ github.workspace }}/openwrt/.ccache + CCACHE_CONFIGPATH2: ${{ github.workspace }}/openwrt/staging_dir/host/etc/ccache.conf + run: | + echo "CCACHE_DIR=$CCACHE_DIR" >> "$GITHUB_ENV" + echo "CCACHE_CONFIGPATH2=$CCACHE_CONFIGPATH2" >> "$GITHUB_ENV" + # ccache for some reason have problem detecting compiler type # with external toolchain. This cause the complete malfunction # of ccache with the result of tons of unsupported compiler @@ -543,16 +552,14 @@ jobs: if: inputs.use_ccache_cache == true shell: su buildbot -c "sh -e {0}" working-directory: openwrt - env: - SYSTEM_CCACHE_CONF: staging_dir/host/etc/ccache.conf run: | - touch $SYSTEM_CCACHE_CONF + touch $CCACHE_CONFIGPATH2 - echo compiler_type=gcc >> $SYSTEM_CCACHE_CONF - [ ${{ inputs.ccache_type }} = 'kernel' ] && echo max_size=800M >> $SYSTEM_CCACHE_CONF + echo compiler_type=gcc >> $CCACHE_CONFIGPATH2 + [ ${{ inputs.ccache_type }} = 'kernel' ] && echo max_size=800M >> $CCACHE_CONFIGPATH2 - echo depend_mode=true >> $SYSTEM_CCACHE_CONF - echo sloppiness=file_macro,locale,time_macros >> $SYSTEM_CCACHE_CONF + echo depend_mode=true >> $CCACHE_CONFIGPATH2 + echo sloppiness=file_macro,locale,time_macros >> $CCACHE_CONFIGPATH2 echo CONFIG_CCACHE=y >> .config @@ -699,8 +706,6 @@ jobs: if: inputs.use_ccache_cache == true shell: su buildbot -c "sh -e {0}" working-directory: openwrt - env: - CCACHE_DIR: ${{ github.workspace }}/openwrt/.ccache run: staging_dir/host/bin/ccache --show-stats - name: Coverity prepare toolchain From cbb822a84ba8368e59fca061bcf76cd16fa644dd Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Sat, 18 Apr 2026 18:41:01 +0200 Subject: [PATCH 2/6] CI: add include_file_ctime,include_file_mtime to ccache sloppiness File ctime and mtime change when the ccache archive is tar'd and extracted for upload/restore, causing spurious hash mismatches. Tell ccache to ignore them. Link: https://github.com/openwrt/actions-shared-workflows/pull/103 Signed-off-by: Hauke Mehrtens --- .github/workflows/reusable_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable_build.yml b/.github/workflows/reusable_build.yml index d14eceb..803aeed 100644 --- a/.github/workflows/reusable_build.yml +++ b/.github/workflows/reusable_build.yml @@ -559,7 +559,7 @@ jobs: [ ${{ inputs.ccache_type }} = 'kernel' ] && echo max_size=800M >> $CCACHE_CONFIGPATH2 echo depend_mode=true >> $CCACHE_CONFIGPATH2 - echo sloppiness=file_macro,locale,time_macros >> $CCACHE_CONFIGPATH2 + echo sloppiness=file_macro,locale,time_macros,include_file_ctime,include_file_mtime >> $CCACHE_CONFIGPATH2 echo CONFIG_CCACHE=y >> .config From 8a8959cc69b686721e563500abf728fcfb9d461e Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Sat, 18 Apr 2026 18:42:47 +0200 Subject: [PATCH 3/6] CI: set ccache compiler_check from toolchain commit The external toolchain is rebuilt daily by the build bots, but the compiler itself usually does not change. Without an explicit compiler_check, ccache falls back to the compiler binary's mtime, so each daily rebuild produces a "new" compiler and every lookup misses. Derive a stable compiler_check string from the OpenWrt commit that last touched toolchain/gcc or toolchain/binutils. For external toolchains, read the build commit from "gcc --version" (r0- pkgversion) and resolve the last change relative to it; otherwise fall back to HEAD. Full git history is needed for "git log", so switch checkout to fetch-depth: 0. Link: https://github.com/openwrt/actions-shared-workflows/pull/103 Co-Authored-By: Claude Opus 4.7 Signed-off-by: Hauke Mehrtens --- .github/workflows/reusable_build.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/workflows/reusable_build.yml b/.github/workflows/reusable_build.yml index 803aeed..f5b7521 100644 --- a/.github/workflows/reusable_build.yml +++ b/.github/workflows/reusable_build.yml @@ -296,6 +296,7 @@ jobs: uses: actions/checkout@v6 with: path: openwrt + fetch-depth: 0 - name: Checkout packages feed if: inputs.include_feeds == true @@ -650,6 +651,27 @@ jobs: run: | echo CONFIG_USE_LLVM_PREBUILT=y >> .config + - name: Determine ccache compiler_check + if: inputs.use_ccache_cache == true + shell: su buildbot -c "sh -e {0}" + working-directory: openwrt + run: | + REV=HEAD + TOOLCHAIN_NAME=in-tree + if [ "${{ inputs.build_toolchain }}" != "true" ] && [ -d /external-toolchain ]; then + GCC=$(find /external-toolchain -name '*-openwrt-linux-*-gcc' \( -type f -o -type l \) 2>/dev/null | head -n1) + if [ -n "$GCC" ]; then + TOOLCHAIN_REV=$("$GCC" --version | head -n1 | grep -oE 'r[0-9]+-[0-9a-f]+' | sed 's/^r[0-9]*-//') + git cat-file -e "$TOOLCHAIN_REV" 2>/dev/null && REV=$TOOLCHAIN_REV + TOOLCHAIN_NAME=$(basename "$(dirname "$(dirname "$GCC")")") + fi + fi + + SHA=$(git log -1 --format=%H "$REV" -- toolchain/gcc/ toolchain/binutils/) + echo "Using toolchain rev $REV -> last toolchain change $SHA ($TOOLCHAIN_NAME)" + + echo "compiler_check=string:$SHA:$TOOLCHAIN_NAME" >> $CCACHE_CONFIGPATH2 + - name: Show configuration shell: su buildbot -c "sh -e {0}" working-directory: openwrt From 6631a4f32a6c3679d5e885ed9248fb495d84d823 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Sat, 18 Apr 2026 18:46:36 +0200 Subject: [PATCH 4/6] CI: tidy up ccache before uploading the archive Before saving/uploading the ccache archive on push, run two maintenance commands and drop the scratch directory from the tar: * ccache --evict-older-than 1d drops entries that were not accessed in the last day, so long-unused results do not sit in the cache forever across runs. * ccache --cleanup enforces max_size, which is otherwise only applied opportunistically during inserts. Running it here guarantees the archive we upload is trimmed to the configured limit instead of whatever size the cache happened to reach. * .ccache/tmp is excluded from the tar. It is ccache's scratch directory for in-flight compilations and has no value once the build step has finished; including it just inflates the archive. Both ccache invocations must run before the subsequent "Cleanup dl/build_dir/staging_dir" step, because that step removes staging_dir/host/bin/ccache. Link: https://github.com/openwrt/actions-shared-workflows/pull/103 Signed-off-by: Hauke Mehrtens --- .github/workflows/reusable_build.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/reusable_build.yml b/.github/workflows/reusable_build.yml index f5b7521..18939d8 100644 --- a/.github/workflows/reusable_build.yml +++ b/.github/workflows/reusable_build.yml @@ -788,6 +788,14 @@ jobs: name: ${{ inputs.target }}-${{ inputs.subtarget }}${{ inputs.testing == true && '-testing' || '' }}-logs path: "openwrt/logs" + - name: Cleanup ccache + if: inputs.use_ccache_cache == true && github.event_name == 'push' + shell: su buildbot -c "sh -e {0}" + working-directory: openwrt + run: | + staging_dir/host/bin/ccache --evict-older-than 1d + staging_dir/host/bin/ccache --cleanup + - name: Cleanup dl/build_dir/staging_dir to make some space working-directory: openwrt if: github.event_name == 'push' @@ -817,7 +825,7 @@ jobs: inputs.upload_ccache_cache == true shell: su buildbot -c "sh -e {0}" working-directory: openwrt - run: tar -cf ${{ needs.setup_build.outputs.ccache_name }}.tar .ccache + run: tar --exclude='.ccache/tmp' -cf ${{ needs.setup_build.outputs.ccache_name }}.tar .ccache - name: Upload ccache cache if: inputs.use_ccache_cache == true && github.event_name == 'push' && From 7cddb15ddb53393016ad23f6d5dab324d3d8a709 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Sat, 18 Apr 2026 18:56:09 +0200 Subject: [PATCH 5/6] CI: raise ccache max_size now that old entries are evicted Bump the kernel ccache max_size from 800M to 1G, and the packages ccache limit from the default 5G to 8G. Multiple package builds have been observed hitting the 5G default, and the kernel cache has been reaching the previous 800M limit. Since entries not accessed in the last day are now evicted before the archive is uploaded, a larger max_size no longer risks unbounded growth across runs. Link: https://github.com/openwrt/actions-shared-workflows/pull/103 Signed-off-by: Hauke Mehrtens --- .github/workflows/reusable_build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/reusable_build.yml b/.github/workflows/reusable_build.yml index 18939d8..4fa5bc0 100644 --- a/.github/workflows/reusable_build.yml +++ b/.github/workflows/reusable_build.yml @@ -557,7 +557,8 @@ jobs: touch $CCACHE_CONFIGPATH2 echo compiler_type=gcc >> $CCACHE_CONFIGPATH2 - [ ${{ inputs.ccache_type }} = 'kernel' ] && echo max_size=800M >> $CCACHE_CONFIGPATH2 + [ ${{ inputs.ccache_type }} = 'kernel' ] && echo max_size=1G >> $CCACHE_CONFIGPATH2 + [ ${{ inputs.ccache_type }} = 'packages' ] && echo max_size=8G >> $CCACHE_CONFIGPATH2 echo depend_mode=true >> $CCACHE_CONFIGPATH2 echo sloppiness=file_macro,locale,time_macros,include_file_ctime,include_file_mtime >> $CCACHE_CONFIGPATH2 From 2ce7d8835841562d330e14e80b25c23ded0e5d95 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Sat, 18 Apr 2026 18:46:59 +0200 Subject: [PATCH 6/6] CI: reset ccache stats and show a detailed breakdown Zero the ccache stats before the build so the stats printed afterwards reflect only the current run, not counters accumulated into the restored cache archive. Also fix the "Show ccache stats" step, which was missing CCACHE_CONFIGPATH2 and so didn't see the system ccache.conf written during configuration, and switch it to -vv for the per-reason breakdown that's useful when debugging cache misses. Link: https://github.com/openwrt/actions-shared-workflows/pull/103 Signed-off-by: Hauke Mehrtens --- .github/workflows/reusable_build.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/reusable_build.yml b/.github/workflows/reusable_build.yml index 4fa5bc0..f5c6ffb 100644 --- a/.github/workflows/reusable_build.yml +++ b/.github/workflows/reusable_build.yml @@ -565,6 +565,12 @@ jobs: echo CONFIG_CCACHE=y >> .config + - name: Reset ccache stats + if: inputs.use_ccache_cache == true + shell: su buildbot -c "sh -e {0}" + working-directory: openwrt + run: staging_dir/host/bin/ccache --zero-stats + - name: Configure external toolchain in container if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_container' shell: su buildbot -c "sh -e {0}" @@ -729,7 +735,7 @@ jobs: if: inputs.use_ccache_cache == true shell: su buildbot -c "sh -e {0}" working-directory: openwrt - run: staging_dir/host/bin/ccache --show-stats + run: staging_dir/host/bin/ccache -vv --show-stats - name: Coverity prepare toolchain if: inputs.coverity_check_packages != ''