From dca35d9aec01fdf8437d9e206efcceaae9e7392e Mon Sep 17 00:00:00 2001 From: Michael Tautschnig Date: Tue, 17 Nov 2020 09:47:10 +0000 Subject: [PATCH 1/2] 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. For any CMake builds, ccache will be used automatically if available (as of d953327a4c). For Visual Studio, we'd need https://github.com/ccache/ccache/pull/506 to be merged to use ccache. On Ubuntu runners and OSX runners, the build time of a rebuild without source code changes is down to under one minute (from 20 minutes). --- .github/workflows/pull-request-checks.yaml | 106 ++++++++++++++++++--- .github/workflows/release-packages.yaml | 36 ++++++- 2 files changed, 127 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pull-request-checks.yaml b/.github/workflows/pull-request-checks.yaml index 9d3b09205bc..db783a2737c 100644 --- a/.github/workflows/pull-request-checks.yaml +++ b/.github/workflows/pull-request-checks.yaml @@ -16,14 +16,30 @@ jobs: # user input DEBIAN_FRONTEND: noninteractive run: | - sudo apt-get install -yq gcc gdb g++ maven jq flex bison libxml2-utils + sudo apt-get install -yq gcc gdb g++ maven jq flex bison libxml2-utils ccache make -C src minisat2-download + - name: Prepare ccache + uses: actions/cache@v2 + with: + path: .ccache + key: ${{ runner.os }}-20.04-make-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-20.04-make-${{ github.ref }} + ${{ runner.os }}-20.04-make + - name: ccache environment + run: | + echo "CCACHE_BASEDIR=$PWD" >> $GITHUB_ENV + echo "CCACHE_DIR=$PWD/.ccache" >> $GITHUB_ENV + - name: Zero ccache stats and limit in size + run: ccache -z --max-size=500M - name: Build with make run: | - make -C src CXX='/usr/bin/g++' -j2 - make -C unit CXX='/usr/bin/g++' -j2 - make -C jbmc/src CXX='/usr/bin/g++' -j2 - make -C jbmc/unit CXX='/usr/bin/g++' -j2 + make -C src CXX='ccache /usr/bin/g++' -j2 + make -C unit CXX='ccache /usr/bin/g++' -j2 + make -C jbmc/src CXX='ccache /usr/bin/g++' -j2 + make -C jbmc/unit CXX='ccache /usr/bin/g++' -j2 + - name: Print ccache stats + run: ccache -s - name: Run unit tests run: | make -C unit test @@ -50,14 +66,30 @@ jobs: # user input DEBIAN_FRONTEND: noninteractive run: | - sudo apt-get install -yq cmake ninja-build gcc g++ maven flex bison libxml2-utils dpkg-dev + sudo apt-get install -yq cmake ninja-build gcc g++ maven flex bison libxml2-utils dpkg-dev ccache + - name: Prepare ccache + uses: actions/cache@v2 + with: + path: .ccache + key: ${{ runner.os }}-20.04-Release-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-20.04-Release-${{ github.ref }} + ${{ runner.os }}-20.04-Release + - name: ccache environment + run: | + echo "CCACHE_BASEDIR=$PWD" >> $GITHUB_ENV + echo "CCACHE_DIR=$PWD/.ccache" >> $GITHUB_ENV - name: Configure using CMake run: | mkdir build cd build cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ + - name: Zero ccache stats and limit in size + run: ccache -z --max-size=500M - name: Build with Ninja run: cd build; ninja -j2 + - name: Print ccache stats + run: ccache -s - name: Check if package building works run: | cd build @@ -73,14 +105,30 @@ jobs: with: submodules: true - name: Fetch dependencies - run: brew install maven flex bison parallel + run: brew install maven flex bison parallel ccache + - name: Prepare ccache + uses: actions/cache@v2 + with: + path: .ccache + key: ${{ runner.os }}-make-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-make-${{ github.ref }} + ${{ runner.os }}-make + - name: ccache environment + run: | + echo "CCACHE_BASEDIR=$PWD" >> $GITHUB_ENV + echo "CCACHE_DIR=$PWD/.ccache" >> $GITHUB_ENV + - name: Zero ccache stats and limit in size + run: ccache -z --max-size=500M - name: Build using Make run: | make -C src minisat2-download - make -C src -j2 - make -C jbmc/src -j2 - make -C unit - make -C jbmc/unit + make -C src -j2 CXX="ccache clang++" + make -C jbmc/src -j2 CXX="ccache clang++" + make -C unit "CXX=ccache clang++" + make -C jbmc/unit "CXX=ccache clang++" + - name: Print ccache stats + run: ccache -s - name: Run unit tests run: cd unit; ./unit_tests - name: Run JBMC unit tests @@ -97,7 +145,21 @@ jobs: with: submodules: true - name: Fetch dependencies - run: brew install cmake ninja maven flex bison + run: brew install cmake ninja maven flex bison ccache + - name: Prepare ccache + uses: actions/cache@v2 + with: + path: .ccache + key: ${{ runner.os }}-Release-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-Release-${{ github.ref }} + ${{ runner.os }}-Release + - name: ccache environment + run: | + echo "CCACHE_BASEDIR=$PWD" >> $GITHUB_ENV + echo "CCACHE_DIR=$PWD/.ccache" >> $GITHUB_ENV + - name: Zero ccache stats and limit in size + run: ccache -z --max-size=500M - name: Configure using CMake run: | mkdir build @@ -105,6 +167,8 @@ jobs: cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ - name: Build with Ninja run: cd build; ninja -j2 + - name: Print ccache stats + run: ccache -s - name: Run CTest run: cd build; ctest -V -L CORE . -j2 @@ -218,7 +282,21 @@ jobs: with: submodules: recursive - name: Fetch dependencies - run: sudo apt install g++ flex bison cmake ninja-build maven jq libxml2-utils dpkg-dev + run: sudo apt install g++ flex bison cmake ninja-build maven jq libxml2-utils dpkg-dev ccache + - name: Prepare ccache + uses: actions/cache@v2 + with: + path: .ccache + key: ${{ runner.os }}-18.04-Release-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-18.04-Release-${{ github.ref }} + ${{ runner.os }}-18.04-Release + - name: ccache environment + run: | + echo "CCACHE_BASEDIR=$PWD" >> $GITHUB_ENV + echo "CCACHE_DIR=$PWD/.ccache" >> $GITHUB_ENV + - name: Zero ccache stats and limit in size + run: ccache -z --max-size=500M - name: Configure CMake run: | mkdir build @@ -228,6 +306,8 @@ jobs: run: | cd build ninja -j2 + - name: Print ccache stats + run: ccache -s - name: Run CTest run: cd build; ctest . -V -L CORE -C Release -j2 - name: Create packages diff --git a/.github/workflows/release-packages.yaml b/.github/workflows/release-packages.yaml index fd5d1320db8..741997f5d0f 100644 --- a/.github/workflows/release-packages.yaml +++ b/.github/workflows/release-packages.yaml @@ -13,16 +13,32 @@ jobs: with: submodules: recursive - name: Fetch dependencies - run: sudo apt install g++ flex bison cmake ninja-build maven jq libxml2-utils dpkg-dev + run: sudo apt install g++ flex bison cmake ninja-build maven jq libxml2-utils dpkg-dev ccache + - name: Prepare ccache + uses: actions/cache@v2 + with: + path: .ccache + key: ${{ runner.os }}-20.04-Release-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-20.04-Release-${{ github.ref }} + ${{ runner.os }}-20.04-Release + - name: ccache environment + run: | + echo "CCACHE_BASEDIR=$PWD" >> $GITHUB_ENV + echo "CCACHE_DIR=$PWD/.ccache" >> $GITHUB_ENV - name: Configure CMake run: | mkdir build cd build cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release + - name: Zero ccache stats and limit in size + run: ccache -z --max-size=500M - name: Build using Ninja run: | cd build ninja -j2 + - name: Print ccache stats + run: ccache -s - name: Run CTest run: cd build; ctest . -V -L CORE -C Release -j2 - name: Create packages @@ -53,16 +69,32 @@ jobs: with: submodules: recursive - name: Fetch dependencies - run: sudo apt install g++ flex bison cmake ninja-build maven jq libxml2-utils dpkg-dev + run: sudo apt install g++ flex bison cmake ninja-build maven jq libxml2-utils dpkg-dev ccache + - name: Prepare ccache + uses: actions/cache@v2 + with: + path: .ccache + key: ${{ runner.os }}-18.04-Release-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-18.04-Release-${{ github.ref }} + ${{ runner.os }}-18.04-Release + - name: ccache environment + run: | + echo "CCACHE_BASEDIR=$PWD" >> $GITHUB_ENV + echo "CCACHE_DIR=$PWD/.ccache" >> $GITHUB_ENV - name: Configure CMake run: | mkdir build cd build cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release + - name: Zero ccache stats and limit in size + run: ccache -z --max-size=500M - name: Build using Ninja run: | cd build ninja -j2 + - name: Print ccache stats + run: ccache -s - name: Run CTest run: cd build; ctest . -V -L CORE -C Release -j2 - name: Create packages From 1042403b72379452167d4e7427eac7901e7be101 Mon Sep 17 00:00:00 2001 From: Michael Tautschnig Date: Wed, 18 Nov 2020 17:36:04 +0000 Subject: [PATCH 2/2] Use clcache for the MSI package build ccache does not currently support msbuild, and we had successfully used clcache on CodeBuild before. Build times (of a fully cached rebuild) reduce from 34 minutes down to under 10 minutes. --- .github/workflows/pull-request-checks.yaml | 18 +++++++++++++++++- .github/workflows/release-packages.yaml | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request-checks.yaml b/.github/workflows/pull-request-checks.yaml index db783a2737c..c54b717a3c9 100644 --- a/.github/workflows/pull-request-checks.yaml +++ b/.github/workflows/pull-request-checks.yaml @@ -251,7 +251,21 @@ jobs: - name: Fetch dependencies run: | choco install winflexbison3 + nuget install clcache -OutputDirectory "c:\tools" -ExcludeVersion -Version 4.1.0 + echo "c:\tools\clcache\clcache-4.1.0" >> $env:GITHUB_PATH - uses: microsoft/setup-msbuild@v1.0.2 + - name: Prepare ccache + uses: actions/cache@v2 + with: + path: .ccache + key: ${{ runner.os }}-msbuild-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-msbuild-${{ github.ref }} + ${{ runner.os }}-msbuild + - name: ccache environment + run: | + echo "CLCACHE_BASEDIR=$((Get-Item -Path '.\').FullName)" >> $env:GITHUB_ENV + echo "CLCACHE_DIR=$pwd\.ccache" >> $env:GITHUB_ENV - name: Configure with cmake run: | New-Item -ItemType Directory -Path build @@ -260,7 +274,9 @@ jobs: - name: Build Release run: | Set-Location build - cmake --build . --config Release -- /p:CL_MPcount=2 + cmake --build . --config Release -- /p:CL_MPcount=2 /p:CLToolExe=clcache + - name: Print ccache stats + run: clcache -s - name: Create packages id: create_packages # We need to get the path to cpack because fascinatingly, diff --git a/.github/workflows/release-packages.yaml b/.github/workflows/release-packages.yaml index 741997f5d0f..eb5ef56bdcd 100644 --- a/.github/workflows/release-packages.yaml +++ b/.github/workflows/release-packages.yaml @@ -142,12 +142,26 @@ jobs: - name: Fetch dependencies run: | choco install winflexbison3 + nuget install clcache -OutputDirectory "c:\tools" -ExcludeVersion -Version 4.1.0 + echo "c:\tools\clcache\clcache-4.1.0" >> $env:GITHUB_PATH - uses: microsoft/setup-msbuild@v1.0.2 name: Setup Visual Studio environment - name: Setup code sign environment run: | 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 echo "pfxcert=$([string](Get-Location)+'\CodeSignCertificate.pfx')" >> $env:GITHUB_ENV + - name: Prepare ccache + uses: actions/cache@v2 + with: + path: .ccache + key: ${{ runner.os }}-msbuild-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-msbuild-${{ github.ref }} + ${{ runner.os }}-msbuild + - name: ccache environment + run: | + echo "CLCACHE_BASEDIR=$((Get-Item -Path '.\').FullName)" >> $env:GITHUB_ENV + echo "CLCACHE_DIR=$pwd\.ccache" >> $env:GITHUB_ENV - name: Configure with cmake run: | New-Item -ItemType Directory -Path build @@ -156,7 +170,9 @@ jobs: - name: Build Release run: | Set-Location build - cmake --build . --config Release -j2 + cmake --build . --config Release -j2 -- /p:CLToolExe=clcache + - name: Print ccache stats + run: clcache -s - name: Create packages id: create_packages run: |