Skip to content

Commit 2994f76

Browse files
authored
305 add ccache to linux build (#994)
1 parent 369edec commit 2994f76

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

.github/actions/linux-build/action.yml

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: "Linux Build"
22
description: "Build the C++ library on Linux. Produces artifact build-cpp-linux-$compiler-$version-$config."
33
inputs:
4+
#take care to adapt the unique cache keys and artifact names below when adding new inputs that affect compilation
5+
#keys also need to be adapted in the other jobs of the pipeline that use the artifacts
46
config:
57
description: "Configuration to build (Release or Debug, see CMAKE_BUILD_TYPE)"
68
required: true
@@ -21,38 +23,22 @@ inputs:
2123
description: "Turn coverage on (ON or OFF, default OFF)"
2224
required: false
2325
default: "OFF"
24-
sanitize-ub:
25-
description: "Turn on UB sanitzer (ON or OFF, default OFF)"
26-
required: false
27-
default: "OFF"
28-
sanitize-addr:
29-
description: "Turn on address sanitzer (ON or OFF, default OFF)"
30-
required: false
31-
default: "OFF"
32-
build-tests:
33-
description: "Build tests"
34-
required: false
35-
default: "ON"
36-
build-benchmarks:
37-
description: "Build benchmarks"
26+
sanitizers:
27+
description: "Turn on sanitzers (ON or OFF, default OFF)"
3828
required: false
3929
default: "OFF"
4030
openmp:
4131
description: "Enable Multithreading with OpenMP (ON or OFF, default OFF). If ON, adds `-omp` to the name of the artifact."
4232
required: false
4333
default: "OFF"
44-
enable-optimization:
45-
description: "Enable optimization with Ipopt (ON or OFF, default ON)"
46-
required: false
47-
default: "ON"
4834
runs:
4935
using: "composite"
5036
steps:
5137
- name: Install dependencies
5238
shell: bash
5339
run: |
5440
sudo apt-get -qq update
55-
sudo apt-get -qq -y install lcov
41+
sudo apt-get -qq -y install lcov ccache
5642
if [[ "${{ inputs.optional-dependencies }}" == "ON" ]]; then
5743
sudo apt-get -qq -y install libhdf5-dev
5844
fi
@@ -71,6 +57,21 @@ runs:
7157
sudo apt-get -qq -y install clang-14
7258
fi
7359
fi
60+
- name: ccache
61+
id: ccache
62+
uses: hendrikmuhs/ccache-action@v1.2
63+
with:
64+
# free total space for cache available on github is limited to 10GB, so only save on main branch;
65+
# other branches will try to use cache from main, but branches that are too old won't benefit;
66+
save: ${{ github.ref_name == 'main' }}
67+
# set enough space per build cache to keep a few previous versions to be used by older branches
68+
# debug builds require more space
69+
max-size: ${{ inputs.config == 'Release' && '200M' || '1G' }}
70+
# saves cache as `ccache-<key>-<timestamp>` (timestamp added automatically, key must be unique, github caches are never overwritten)
71+
# key should be a composite of all options that affect the compilation
72+
key: linux-${{ inputs.compiler }}-${{ inputs.version }}-${{ inputs.config }}-cov${{ inputs.coverage }}-dep${{ inputs.optional-dependencies }}-omp${{ inputs.openmp }}-san${{ inputs.sanitizers }}
73+
# load most recent cache where a prefix of the key matches a restore-key, e.g. from the most recent nightly run of the same build
74+
restore-keys: linux-${{ inputs.compiler }}-${{ inputs.version }}-${{ inputs.config }}-cov${{ inputs.coverage }}-dep${{ inputs.optional-dependencies }}-omp${{ inputs.openmp }}-san${{ inputs.sanitizers }}
7475
- name: Build
7576
shell: bash
7677
run: |
@@ -96,7 +97,7 @@ runs:
9697
exit 1
9798
fi
9899
mkdir -p build && cd build
99-
cmake -DCMAKE_BUILD_TYPE=${{ inputs.config }} -DMEMILIO_BUILD_TESTS=${{ inputs.build-tests }} -DMEMILIO_BUILD_BENCHMARKS=${{ inputs.build-benchmarks }} -DMEMILIO_ENABLE_IPOPT=${{ inputs.enable-optimization }} -DMEMILIO_TEST_COVERAGE=${{ inputs.coverage }} -DMEMILIO_SANITIZE_ADDRESS=${{ inputs.sanitize-addr }} -DMEMILIO_SANITIZE_UNDEFINED=${{ inputs.sanitize-ub }} -DMEMILIO_USE_BUNDLED_JSONCPP=${{ inputs.optional-dependencies }} -DMEMILIO_ENABLE_OPENMP=${{ inputs.openmp }} ..
100+
cmake -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_BUILD_TYPE=${{ inputs.config }} -DMEMILIO_ENABLE_IPOPT=ON -DMEMILIO_TEST_COVERAGE=${{ inputs.coverage }} -DMEMILIO_SANITIZE_ADDRESS=${{ inputs.sanitizers }} -DMEMILIO_SANITIZE_UNDEFINED=${{ inputs.sanitizers }} -DMEMILIO_USE_BUNDLED_JSONCPP=${{ inputs.optional-dependencies }} -DMEMILIO_ENABLE_OPENMP=${{ inputs.openmp }} ..
100101
make -j4
101102
- name: create build dir archive
102103
shell: bash

.github/workflows/main.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ jobs:
4747
config: ${{ matrix.config }}
4848
version: ${{ matrix.version }}
4949
coverage: ${{ (matrix.compiler == 'gcc' && matrix.config == 'Debug' && matrix.version == 'latest') && 'ON' || 'OFF' }} # `c && t || f` is (usually) equivalent to `c ? t : f`
50-
sanitize-addr: ${{ (matrix.compiler == 'gcc' && matrix.config == 'Debug' && matrix.version == 'latest') && 'ON' || 'OFF' }}
51-
sanitize-ub: ${{ (matrix.compiler == 'gcc' && matrix.config == 'Debug' && matrix.version == 'latest') && 'ON' || 'OFF' }}
50+
sanitizers: ${{ (matrix.compiler == 'gcc' && matrix.config == 'Debug' && matrix.version == 'latest') && 'ON' || 'OFF' }}
5251

5352
build-cpp-gcc-no-optional-deps:
5453
if: github.event.pull_request.draft == false

0 commit comments

Comments
 (0)