Skip to content

Commit

Permalink
CI: Use ccache for Linux, MacOS, and mingw64 builds (#845)
Browse files Browse the repository at this point in the history
Co-authored-by: Mike Taves <[email protected]>
  • Loading branch information
dbaston and mwtoews authored Mar 16, 2023
1 parent 878d434 commit 7bb353c
Showing 1 changed file with 107 additions and 57 deletions.
164 changes: 107 additions & 57 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ on:
paths-ignore:
- '**/.md'

env:
CCACHE_BASEDIR: ${{ github.workspace }}
CCACHE_DIR: ${{ github.workspace }}/.ccache
CCACHE_COMPRESS: "true"
CCACHE_COMPRESSLEVEL: "6"
CCACHE_MAXSIZE: "300M"

jobs:
linux:
name: 'Linux'
Expand Down Expand Up @@ -184,13 +191,21 @@ jobs:
set -e
uname -a
sudo -E apt-get update
sudo -E apt-get -yq --no-install-suggests --no-install-recommends install make doxygen python3-pip valgrind ${{ matrix.ci.packages }}
sudo -E apt-get -yq --no-install-suggests --no-install-recommends install make doxygen python3-pip ccache valgrind ${{ matrix.ci.packages }}
python3 -m pip install --disable-pip-version-check --user cmake==${{ matrix.ci.cmake }}
echo "$(python3 -m site --user-base)/bin" >> $GITHUB_PATH
- name: 'Check Out'
uses: actions/checkout@v3

- name: Retrieve build cache
uses: actions/cache/restore@v3
id: restore-cache
with:
path: .ccache
key: ${{ matrix.ci.os }}-${{ matrix.ci.cxx_compiler }}-${{ matrix.ci.build_type}}-${{ matrix.ci.cxxstd }}-${{ matrix.ci.arch }}-${{ github.ref_name }}-${{ github.run_id }}
restore-keys: ${{ matrix.ci.os }}-${{ matrix.ci.cxx_compiler }}-${{ matrix.ci.build_type}}-${{ matrix.ci.cxxstd }}-${{ matrix.ci.arch }}

- name: 'Build'
env:
CFLAGS: "-m${{ matrix.ci.arch }}"
Expand All @@ -200,9 +215,22 @@ jobs:
mkdir build.cmake
cd build.cmake
cmake --version
cmake ${{ matrix.ci.cmake_extra }} -DCMAKE_C_COMPILER=${{ matrix.ci.c_compiler }} -DCMAKE_CXX_COMPILER=${{ matrix.ci.cxx_compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.ci.cxxstd }} -DBUILD_DOCUMENTATION=YES -DCMAKE_BUILD_TYPE=${{ matrix.ci.build_type }} ..
cmake ${{ matrix.ci.cmake_extra }} \
-DCMAKE_C_COMPILER=${{ matrix.ci.c_compiler }} \
-DCMAKE_CXX_COMPILER=${{ matrix.ci.cxx_compiler }} \
-DCMAKE_CXX_STANDARD=${{ matrix.ci.cxxstd }} \
-DUSE_CCACHE=ON \
-DBUILD_DOCUMENTATION=YES \
-DCMAKE_BUILD_TYPE=${{ matrix.ci.build_type }} ..
make -j 2
cmake --build . --target docs
ccache -s
- name: Save build cache
uses: actions/cache/save@v3
with:
path: .ccache
key: ${{ steps.restore-cache.outputs.cache-primary-key }}

- name: Test
run: |
Expand Down Expand Up @@ -238,102 +266,103 @@ jobs:
shell: bash

windows-mingw:
name: 'Windows (mingw-w64, Debug, 11, x86_64, windows-2019)'
name: 'Windows (mingw-w64, x86_64, windows-2019)'
runs-on: windows-2019
defaults:
run:
shell: msys2 {0}
strategy:
matrix:
build_type: ['Debug', 'Release']

steps:
- name: 'Check Out'
uses: actions/checkout@v3

- name: 'Setup'
uses: msys2/setup-msys2@v2
with:
install: mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake make
install: mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake make mingw-w64-x86_64-ccache
update: true

- name: 'Build'
run: |
mkdir build
cd build
cmake --version
cmake -DCMAKE_BUILD_TYPE=Debug -G"MSYS Makefiles" ..
cmake --build . -j 2
- name: 'Test'
run: |
cd build
ctest --output-on-failure .
windows-mingw-release:
name: 'Windows (mingw-w64, Release, 11, x86_64, windows-2019)'
runs-on: windows-2019
defaults:
run:
shell: msys2 {0}
steps:
- name: 'Check Out'
uses: actions/checkout@v3

- name: 'Setup'
uses: msys2/setup-msys2@v2
- name: Retrieve build cache
id: restore-cache
uses: actions/cache/restore@v3
with:
install: mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake make
update: true
path: .ccache
key: windows-mingw-${{ matrix.build_type}}-${{ github.ref_name }}-${{ github.run_id }}
restore-keys: windows-mingw-${{ matrix.build_type}}

- name: 'Build'
run: |
export CCACHE_BASE_DIR=$(pwd)
mkdir build
cd build
cmake --version
cmake -DCMAKE_BUILD_TYPE=Release -G"MSYS Makefiles" ..
cmake \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DUSE_CCACHE=ON \
-G"MSYS Makefiles" ..
cmake --build . -j 2
- name: Save build cache
uses: actions/cache/save@v3
with:
path: .ccache
key: ${{ steps.restore-cache.outputs.cache-primary-key }}

- name: 'Test'
run: |
cd build
ctest --output-on-failure .
windows-msvc-22:
name: 'Windows (Visual Studio 2022, Debug, windows-2022)'
runs-on: windows-2022
steps:
- name: 'Check Out'
uses: actions/checkout@v3

- name: 'Build'
run: |
mkdir build
cd build
cmake --version
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_STANDARD=14 -DBUILD_SHARED_LIBS=ON ..
cmake --build . --config Debug -j 2
windows-msvc:
name: 'Windows (Visual Studio)'
strategy:
matrix:
ci:
- build_type: Debug
cxxstd: 14
os: windows-2022

- name: 'Test'
run: |
cd build
ctest --output-on-failure -C Debug
- build_type: Release
cxxstd: 14
os: windows-2019

windows-msvc-19:
name: 'Windows (Visual Studio 2019, Release, windows-2019)'
runs-on: windows-2019
runs-on: ${{ matrix.ci.os }}
steps:
- name: 'Check Out'
uses: actions/checkout@v3

- name: 'Setup'
run: choco install ccache

- name: Retrieve build cache
id: restore-cache
uses: actions/cache/restore@v3
with:
path: .ccache
key: windows-msvc-${{ matrix.build_type}}-${{ github.ref_name }}-${{ github.run_id }}
restore-keys: windows-msvc-${{ matrix.build_type}}

- name: 'Build'
run: |
mkdir build
cd build
cmake --version
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=14 -DBUILD_SHARED_LIBS=ON ..
cmake --build . --config Release -j 2
cmake -DCMAKE_BUILD_TYPE=${{ matrix.ci.build_type }} -DCMAKE_CXX_STANDARD=${{ matrix.ci.cxxstd }} -DBUILD_SHARED_LIBS=ON -DUSE_CCACHE=ON ..
cmake --build . --config ${{ matrix.ci.build_type }} -j 2
- name: Save build cache
uses: actions/cache/save@v3
with:
path: .ccache
key: ${{ steps.restore-cache.outputs.cache-primary-key }}

- name: 'Test'
run: |
cd build
ctest --output-on-failure -C Release
ctest --output-on-failure -C ${{ matrix.ci.build_type }}
macos:
name: 'macOS clang'
Expand All @@ -353,6 +382,10 @@ jobs:
runs-on: macos-11
steps:

- name: 'Setup'
run: |
brew install ccache
- name: 'Install'
env:
XCODE_APP: /Applications/XCode_${{ matrix.xcode }}.app
Expand All @@ -366,6 +399,14 @@ jobs:
- name: 'Check Out'
uses: actions/checkout@v3

- name: Retrieve build cache
id: restore-cache
uses: actions/cache/restore@v3
with:
path: .ccache
key: ${{ runner.os }}-${{ matrix.xcode }}-${{ matrix.build_type}}-${{ matrix.cxxstd }}-${{ github.ref_name }}-${{ github.run_id }}
restore-keys: ${{ runner.os }}-${{ matrix.xcode }}-${{ matrix.build_type}}-${{ matrix.cxxstd }}

- name: 'Build'
env:
BUILD_TYPE: ${{ matrix.build_type }}
Expand All @@ -375,9 +416,18 @@ jobs:
mkdir build
cd build
cmake --version
cmake -DCMAKE_CXX_STANDARD=${CXX_STANDARD} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ..
cmake \
-DCMAKE_CXX_STANDARD=${CXX_STANDARD} \
-DUSE_CCACHE=ON \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} ..
cmake --build . --config ${BUILD_TYPE} -j 3
- name: Save build cache
uses: actions/cache/save@v3
with:
path: .ccache
key: ${{ steps.restore-cache.outputs.cache-primary-key }}

- name: 'Test'
run: |
cd build
Expand Down

0 comments on commit 7bb353c

Please sign in to comment.