From 7c31a516ef7dc486323d21119f41268889d0e7f2 Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 18 Jul 2024 08:22:52 +0100 Subject: [PATCH] Fix CI ccache for library and restrict size (#2866) **Fix CI library caching** #2865 broken library CI because: - ccache initialisation commands never get executed to set ccache directory - library ccache key must have toolchain in it Fixed by removing the ccache commands from script and updating workflow `env` instead. Just requires call to clear stats before building. NB. This leads to a fair bit of duplication in all 3 workflow files. This is the simplest I can come up with for now. **Simplify workflows** Don't need the `Configure environment` step, just add values to `env`. **Use explicit ccache path** In testing was getting failures saving cache due to ccache not found. Use explicit absolute path to ccache directory. **Restrict ccache size** The cache for each job will increase over time to hit 500MB. Over 40 jobs that's 20GB and will cause cache thrashing. Easy fix: ask ccache to evict anything older than 4 hours from ccache. Do this before printing stats so we can see the resulting size. --- .github/workflows/ci-esp32.yml | 20 +++++++++++--------- .github/workflows/ci.yml | 20 +++++++++++--------- .github/workflows/library.yml | 18 ++++++++++++------ Tools/ci/build.cmd | 7 ------- Tools/ci/build.sh | 7 ------- 5 files changed, 34 insertions(+), 38 deletions(-) diff --git a/.github/workflows/ci-esp32.yml b/.github/workflows/ci-esp32.yml index 6b37b2aeff..21e3d98dab 100644 --- a/.github/workflows/ci-esp32.yml +++ b/.github/workflows/ci-esp32.yml @@ -37,11 +37,15 @@ jobs: runs-on: ${{ matrix.os }} env: + CI_BUILD_DIR: ${{ github.workspace }} + SMING_HOME: ${{ github.workspace }}/Sming SMING_ARCH: Esp32 SMING_SOC: ${{ matrix.variant }} INSTALL_IDF_VER: ${{ matrix.idf_version }} IDF_SKIP_CHECK_SUBMODULES: 1 ENABLE_CCACHE: 1 + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 500M steps: - name: Fix autocrlf setting @@ -56,12 +60,6 @@ jobs: with: python-version: ${{ matrix.idf_version == '4.3' && '3.8' || '3.12' }} - - name: Configure environment - shell: pwsh - run: | - "CI_BUILD_DIR=" + (Resolve-Path ".").path >> $env:GITHUB_ENV - "SMING_HOME=" + (Resolve-Path "Sming").path >> $env:GITHUB_ENV - - name: Fix permissions if: matrix.os != 'windows-latest' run: | @@ -90,23 +88,27 @@ jobs: id: ccache uses: actions/cache/restore@v4 with: - path: .ccache + path: ${{ env.CCACHE_DIR }} key: ${{ matrix.os }}-ccache-${{ matrix.variant }}-${{ matrix.idf_version }} - name: Build and test for ${{matrix.variant}} with IDF v${{matrix.idf_version}} on Ubuntu / MacOS if: matrix.os != 'windows-latest' run: | + ccache -z . Tools/export.sh Tools/ci/build.sh - name: Build and test for ${{matrix.variant}} with IDF v${{matrix.idf_version}} on Windows if: matrix.os == 'windows-latest' run: | + ccache -z . Tools/ci/setenv.ps1 Tools/ci/build.cmd - name: Compiler Cache stats - run: ccache -sv + run: | + ccache --evict-older-than 14400s + ccache -sv - name: Delete Previous Compiler Cache if: github.ref_name == github.event.repository.default_branch && steps.ccache.outputs.cache-hit @@ -121,5 +123,5 @@ jobs: if: github.ref_name == github.event.repository.default_branch || !steps.ccache.outputs.cache-hit uses: actions/cache/save@v4 with: - path: .ccache + path: ${{ env.CCACHE_DIR }} key: ${{ steps.ccache.outputs.cache-primary-key }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 536ab4e988..8b33ec55ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,11 +39,15 @@ jobs: runs-on: ${{ matrix.os }} env: + CI_BUILD_DIR: ${{ github.workspace }} + SMING_HOME: ${{ github.workspace }}/Sming SMING_ARCH: ${{ matrix.arch }} SMING_SOC: ${{ matrix.variant }} CLANG_BUILD: ${{ matrix.toolchain == 'clang' && '15' || '0' }} BUILD64: ${{ matrix.toolchain == 'gcc64' && 1 || 0 }} ENABLE_CCACHE: 1 + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 500M steps: - name: Fix autocrlf setting @@ -58,12 +62,6 @@ jobs: with: python-version: "3.12" - - name: Configure environment - shell: pwsh - run: | - "CI_BUILD_DIR=" + (Resolve-Path ".").path >> $env:GITHUB_ENV - "SMING_HOME=" + (Resolve-Path "Sming").path >> $env:GITHUB_ENV - - name: Install build tools for Ubuntu / MacOS if: matrix.os != 'windows-latest' run: | @@ -79,7 +77,7 @@ jobs: id: ccache uses: actions/cache/restore@v4 with: - path: .ccache + path: ${{ env.CCACHE_DIR }} key: ${{ matrix.os }}-ccache-${{ matrix.toolchain }}-${{ matrix.variant }} - name: Build and test for ${{matrix.variant}} on Ubuntu / MacOS @@ -87,17 +85,21 @@ jobs: CLANG_FORMAT: clang-format-8 if: matrix.os != 'windows-latest' run: | + ccache -z . Tools/export.sh Tools/ci/build.sh - name: Build and test for ${{matrix.variant}} on Windows if: matrix.os == 'windows-latest' run: | + ccache -z . Tools/ci/setenv.ps1 Tools/ci/build.cmd - name: Compiler Cache stats - run: ccache -sv + run: | + ccache --evict-older-than 14400s + ccache -sv - name: Delete Previous Compiler Cache if: github.ref_name == github.event.repository.default_branch && steps.ccache.outputs.cache-hit @@ -112,5 +114,5 @@ jobs: if: github.ref_name == github.event.repository.default_branch || !steps.ccache.outputs.cache-hit uses: actions/cache/save@v4 with: - path: .ccache + path: ${{ env.CCACHE_DIR }} key: ${{ steps.ccache.outputs.cache-primary-key }} diff --git a/.github/workflows/library.yml b/.github/workflows/library.yml index b01b4dbdd8..7a02c305b6 100644 --- a/.github/workflows/library.yml +++ b/.github/workflows/library.yml @@ -69,12 +69,15 @@ jobs: runs-on: ${{ matrix.os }} env: + CI_BUILD_DIR: ${{ github.workspace }} SMING_ARCH: ${{ matrix.arch }} SMING_SOC: ${{ matrix.variant }} INSTALL_IDF_VER: ${{ matrix.idf_version || '5.2' }} CLANG_BUILD: ${{ matrix.toolchain == 'clang' && '15' || '0' }} BUILD64: ${{ matrix.toolchain == 'gcc64' && 1 || 0 }} ENABLE_CCACHE: 1 + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 500M steps: - name: Fix autocrlf setting @@ -102,7 +105,6 @@ jobs: - name: Configure environment shell: pwsh run: | - "CI_BUILD_DIR=" + (Resolve-Path ".").path >> $env:GITHUB_ENV "SMING_HOME=" + (Resolve-Path "../../sming/Sming").path >> $env:GITHUB_ENV "COMPONENT_SEARCH_DIRS=" + (Resolve-Path "..").path >> $env:GITHUB_ENV "CI_MAKEFILE=" + (Resolve-Path "../../sming/Tools/ci/library/Makefile") >> $env:GITHUB_ENV @@ -137,25 +139,29 @@ jobs: id: ccache uses: actions/cache/restore@v4 with: - path: .ccache - key: ${{ matrix.os }}-ccache-${{ matrix.variant }}-${{ matrix.arch == 'Esp32' && env.INSTALL_IDF_VER || '' }} + path: ${{ env.CCACHE_DIR }} + key: ${{ matrix.os }}-ccache-${{ matrix.toolchain }}-${{ matrix.variant }}-${{ matrix.arch == 'Esp32' && env.INSTALL_IDF_VER || '' }} - name: Build and Test for ${{matrix.arch}} on Ubuntu / MacOS env: CLANG_FORMAT: clang-format-8 if: matrix.os != 'windows-latest' run: | - source $SMING_HOME/../Tools/export.sh + ccache -z + . $SMING_HOME/../Tools/export.sh make -j$(nproc) -f $CI_MAKEFILE - name: Build and Test for ${{matrix.arch}} on Windows if: matrix.os == 'windows-latest' run: | + ccache -z . "$env:SMING_HOME/../Tools/ci/setenv.ps1" make -j $env:NUMBER_OF_PROCESSORS -f $env:CI_MAKEFILE - name: Compiler Cache stats - run: ccache -sv + run: | + ccache --evict-older-than 14400s + ccache -sv - name: Delete Previous Compiler Cache if: github.ref_name == github.event.repository.default_branch && steps.ccache.outputs.cache-hit @@ -170,5 +176,5 @@ jobs: if: github.ref_name == github.event.repository.default_branch || !steps.ccache.outputs.cache-hit uses: actions/cache/save@v4 with: - path: .ccache + path: ${{ env.CCACHE_DIR }} key: ${{ steps.ccache.outputs.cache-primary-key }} diff --git a/Tools/ci/build.cmd b/Tools/ci/build.cmd index cd887728e6..3f4d7185ae 100644 --- a/Tools/ci/build.cmd +++ b/Tools/ci/build.cmd @@ -9,13 +9,6 @@ if "%BUILD_DOCS%"=="true" ( goto :EOF ) -REM Configure ccache -if "%ENABLE_CCACHE%"=="1" ( - ccache --set-config cache_dir="%CI_BUILD_DIR%\.ccache" - ccache --set-config max_size=500M - ccache -z -) - cd /d %SMING_HOME% call Arch\%SMING_ARCH%\Tools\ci\build.setup.cmd || goto :error diff --git a/Tools/ci/build.sh b/Tools/ci/build.sh index 1ec2d6833c..fed80f9876 100755 --- a/Tools/ci/build.sh +++ b/Tools/ci/build.sh @@ -9,13 +9,6 @@ if [ "$BUILD_DOCS" = "true" ]; then exit 0 fi -# Configure ccache -if [ "$ENABLE_CCACHE" == "1" ]; then - ccache --set-config cache_dir="$CI_BUILD_DIR/.ccache" - ccache --set-config max_size=500M - ccache -z -fi - # Build times benefit from parallel building export MAKE_PARALLEL="make -j$(nproc)"