Skip to content

Commit 76dc705

Browse files
committed
Use CCache to speed up build times in GitHub actions
We used to do this on Travis and CodeBuild, let's also port this to GitHub actions.
1 parent 762f7df commit 76dc705

File tree

3 files changed

+106
-25
lines changed

3 files changed

+106
-25
lines changed

.github/workflows/pull-request-checks.yaml

Lines changed: 72 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,24 @@ jobs:
1717
DEBIAN_FRONTEND: noninteractive
1818
TESTPL_JOBS: 4
1919
run: |
20-
sudo apt-get install -yq gcc gdb g++ maven jq flex bison libxml2-utils cpanminus
20+
sudo apt-get install -yq gcc gdb g++ maven jq flex bison libxml2-utils cpanminus ccache
2121
make -C src minisat2-download
2222
cpanm Thread::Pool::Simple
23+
- name: Prepare ccache
24+
uses: actions/cache@v2
25+
with:
26+
path: .ccache
27+
key: ${{ matrix.os }}-make
28+
- name: Zero ccache stats and limit in size
29+
run: ccache -z --max-size=500M
2330
- name: Build with make
2431
run: |
25-
make -C src CXX='/usr/bin/g++' -j2
26-
make -C unit CXX='/usr/bin/g++' -j2
27-
make -C jbmc/src CXX='/usr/bin/g++' -j2
28-
make -C jbmc/unit CXX='/usr/bin/g++' -j2
32+
make -C src CXX='ccache /usr/bin/g++' -j2
33+
make -C unit CXX='ccache /usr/bin/g++' -j2
34+
make -C jbmc/src CXX='ccache /usr/bin/g++' -j2
35+
make -C jbmc/unit CXX='ccache /usr/bin/g++' -j2
36+
- name: Print ccache stats
37+
run: ccache -s
2938
- name: Run unit tests
3039
run: |
3140
make -C unit test
@@ -52,15 +61,24 @@ jobs:
5261
# user input
5362
DEBIAN_FRONTEND: noninteractive
5463
run: |
55-
sudo apt-get install -yq cmake ninja-build gcc g++ maven flex bison libxml2-utils cpanminus dpkg-dev
64+
sudo apt-get install -yq cmake ninja-build gcc g++ maven flex bison libxml2-utils cpanminus dpkg-dev ccache
5665
cpanm Thread::Pool::Simple
66+
- name: Prepare ccache
67+
uses: actions/cache@v2
68+
with:
69+
path: .ccache
70+
key: ${{ matrix.os }}-Release
5771
- name: Configure using CMake
5872
run: |
5973
mkdir build
6074
cd build
61-
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++
75+
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="/usr/bin/gcc" -DCMAKE_CXX_COMPILER="/usr/bin/g++" -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
76+
- name: Zero ccache stats and limit in size
77+
run: ccache -z --max-size=500M
6278
- name: Build with Ninja
6379
run: cd build; ninja
80+
- name: Print ccache stats
81+
run: ccache -s
6482
- name: Check if package building works
6583
run: |
6684
cd build
@@ -78,14 +96,23 @@ jobs:
7896
with:
7997
submodules: true
8098
- name: Fetch dependencies
81-
run: brew install maven flex bison
99+
run: brew install maven flex bison ccache
100+
- name: Prepare ccache
101+
uses: actions/cache@v2
102+
with:
103+
path: .ccache
104+
key: ${{ matrix.os }}-Make
105+
- name: Zero ccache stats and limit in size
106+
run: ccache -z --max-size=500M
82107
- name: Build using Make
83108
run: |
84109
make -C src minisat2-download
85-
make -C src
86-
make -C jbmc/src
87-
make -C unit
88-
make -C jbmc/unit
110+
make -C src CXX="ccache clang++"
111+
make -C jbmc/src CXX="ccache clang++"
112+
make -C unit "CXX=ccache clang++"
113+
make -C jbmc/unit "CXX=ccache clang++"
114+
- name: Print ccache stats
115+
run: ccache -s
89116
- name: Run unit tests
90117
run: cd unit; ./unit_tests
91118
- name: Run JBMC unit tests
@@ -102,14 +129,23 @@ jobs:
102129
with:
103130
submodules: true
104131
- name: Fetch dependencies
105-
run: brew install cmake ninja maven flex bison
132+
run: brew install cmake ninja maven flex bison ccache
133+
- name: Prepare ccache
134+
uses: actions/cache@v2
135+
with:
136+
path: .ccache
137+
key: ${{ matrix.os }}-Release
138+
- name: Zero ccache stats and limit in size
139+
run: ccache -z --max-size=500M
106140
- name: Configure using CMake
107141
run: |
108142
mkdir build
109143
cd build
110-
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++
144+
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="/usr/bin/clang" -DCMAKE_CXX_COMPILER="/usr/bin/clang++" -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
111145
- name: Build with Ninja
112146
run: cd build; ninja
147+
- name: Print ccache stats
148+
run: ccache -s
113149
- name: Run CTest
114150
run: cd build; ctest -V -L CORE .
115151

@@ -191,17 +227,26 @@ jobs:
191227
submodules: recursive
192228
- name: Fetch dependencies
193229
run: |
194-
choco install winflexbison3
230+
choco install winflexbison3 ccache
231+
- name: Prepare ccache
232+
uses: actions/cache@v2
233+
with:
234+
path: .ccache
235+
key: ${{ matrix.os }}-Release
236+
- name: Zero ccache stats and limit in size
237+
run: ccache -z --max-size=500M
195238
- uses: microsoft/[email protected]
196239
- name: Configure with cmake
197240
run: |
198241
New-Item -ItemType Directory -Path build
199242
Set-Location build
200-
cmake ..
243+
cmake .. -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
201244
- name: Build Release
202245
run: |
203246
Set-Location build
204247
cmake --build . --config Release
248+
- name: Print ccache stats
249+
run: ccache -s
205250
- name: Create packages
206251
id: create_packages
207252
# We need to get the path to cpack because fascinatingly,
@@ -223,16 +268,25 @@ jobs:
223268
with:
224269
submodules: recursive
225270
- name: Fetch dependencies
226-
run: sudo apt install g++ flex bison cmake ninja-build maven jq libxml2-utils dpkg-dev
271+
run: sudo apt install g++ flex bison cmake ninja-build maven jq libxml2-utils dpkg-dev ccache
272+
- name: Prepare ccache
273+
uses: actions/cache@v2
274+
with:
275+
path: .ccache
276+
key: ${{ matrix.os }}-Release
277+
- name: Zero ccache stats and limit in size
278+
run: ccache -z --max-size=500M
227279
- name: Configure CMake
228280
run: |
229281
mkdir build
230282
cd build
231-
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release
283+
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
232284
- name: Build using Ninja
233285
run: |
234286
cd build
235287
ninja
288+
- name: Print ccache stats
289+
run: ccache -s
236290
- name: Run CTest
237291
run: cd build; ctest . -V -L CORE -C Release
238292
- name: Create packages

.github/workflows/release-packages.yaml

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,25 @@ jobs:
1313
with:
1414
submodules: recursive
1515
- name: Fetch dependencies
16-
run: sudo apt install g++ flex bison cmake ninja-build maven jq libxml2-utils dpkg-dev
16+
run: sudo apt install g++ flex bison cmake ninja-build maven jq libxml2-utils dpkg-dev ccache
17+
- name: Prepare ccache
18+
uses: actions/cache@v2
19+
with:
20+
path: .ccache
21+
key: ${{ matrix.os }}-Release
1722
- name: Configure CMake
1823
run: |
1924
mkdir build
2025
cd build
21-
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release
26+
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
27+
- name: Zero ccache stats and limit in size
28+
run: ccache -z --max-size=500M
2229
- name: Build using Ninja
2330
run: |
2431
cd build
2532
ninja
33+
- name: Print ccache stats
34+
run: ccache -s
2635
- name: Run CTest
2736
run: cd build; ctest . -V -L CORE -C Release
2837
- name: Create packages
@@ -53,16 +62,25 @@ jobs:
5362
with:
5463
submodules: recursive
5564
- name: Fetch dependencies
56-
run: sudo apt install g++ flex bison cmake ninja-build maven jq libxml2-utils dpkg-dev
65+
run: sudo apt install g++ flex bison cmake ninja-build maven jq libxml2-utils dpkg-dev ccache
66+
- name: Prepare ccache
67+
uses: actions/cache@v2
68+
with:
69+
path: .ccache
70+
key: ${{ matrix.os }}-Release
5771
- name: Configure CMake
5872
run: |
5973
mkdir build
6074
cd build
61-
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release
75+
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
76+
- name: Zero ccache stats and limit in size
77+
run: ccache -z --max-size=500M
6278
- name: Build using Ninja
6379
run: |
6480
cd build
6581
ninja
82+
- name: Print ccache stats
83+
run: ccache -s
6684
- name: Run CTest
6785
run: cd build; ctest . -V -L CORE -C Release
6886
- name: Create packages
@@ -109,22 +127,31 @@ jobs:
109127
submodules: recursive
110128
- name: Fetch dependencies
111129
run: |
112-
choco install winflexbison3
130+
choco install winflexbison3 ccache
113131
- uses: microsoft/[email protected]
114132
name: Setup Visual Studio environment
115133
- name: Setup code sign environment
116134
run: |
117135
echo "$(Split-Path -Path $(Get-ChildItem -Path ${env:ProgramFiles(x86)} -Recurse -Filter 'signtool.exe' | Where-Object FullName -like '*10.0.19041.0\x64\signtool.exe').FullName)" >> $env:GITHUB_PATH
118136
echo "pfxcert=$([string](Get-Location)+'\CodeSignCertificate.pfx')" >> $env:GITHUB_ENV
137+
- name: Prepare ccache
138+
uses: actions/cache@v2
139+
with:
140+
path: .ccache
141+
key: ${{ matrix.os }}-Release
142+
- name: Zero ccache stats and limit in size
143+
run: ccache -z --max-size=500M
119144
- name: Configure with cmake
120145
run: |
121146
New-Item -ItemType Directory -Path build
122147
Set-Location build
123-
cmake ..
148+
cmake .. -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
124149
- name: Build Release
125150
run: |
126151
Set-Location build
127152
cmake --build . --config Release
153+
- name: Print ccache stats
154+
run: ccache -s
128155
- name: Create packages
129156
id: create_packages
130157
run: |

.github/workflows/vs2019/build-cbmc.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ echo "Remove strawberry"
1616
del /s /q "c:/Strawberry/c/bin"
1717

1818
echo "Configure CBMC with cmake"
19-
cmake -S. -Bbuild
19+
cmake -S. -Bbuild -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
2020

2121
echo "Build CBMC with cmake"
2222
cmake --build build --config Release

0 commit comments

Comments
 (0)