Skip to content

Commit

Permalink
Fix CI ccache for library and restrict size (#2866)
Browse files Browse the repository at this point in the history
**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.
  • Loading branch information
mikee47 authored Jul 18, 2024
1 parent c3d496b commit 7c31a51
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 38 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/ci-esp32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand Down Expand Up @@ -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
Expand All @@ -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 }}
20 changes: 11 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand All @@ -79,25 +77,29 @@ 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
env:
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
Expand All @@ -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 }}
18 changes: 12 additions & 6 deletions .github/workflows/library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 }}
7 changes: 0 additions & 7 deletions Tools/ci/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 0 additions & 7 deletions Tools/ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

Expand Down

0 comments on commit 7c31a51

Please sign in to comment.