This uses ccache + github caching to substantially decrease the time it takes to run CMake builds. Due to Bazel caching, these are some of our slowest tests, causing one of the biggest presubmit bottlenecks PiperOrigin-RevId: 507667813pull/11825/head
parent
e5bbcd20d3
commit
c399aeccc4
6 changed files with 234 additions and 40 deletions
@ -0,0 +1,65 @@ |
||||
name: 'CCache Setup' |
||||
description: 'Run a Bazel-based docker image for Protobuf CI testing' |
||||
inputs: |
||||
cache-prefix: |
||||
required: true |
||||
description: A unique prefix to prevent cache pollution |
||||
type: string |
||||
support-modules: |
||||
required: false |
||||
description: Whether or not we need to support modules. This can result in extra cache misses. |
||||
|
||||
runs: |
||||
using: 'composite' |
||||
steps: |
||||
- name: Setup ccache on Windows |
||||
if: ${{ runner.os == 'Windows' }} |
||||
uses: ./.github/actions/internal/ccache-setup-windows |
||||
- name: Setup ccache on Mac |
||||
if: ${{ runner.os == 'macOS' }} |
||||
shell: bash |
||||
run: brew install ccache |
||||
|
||||
- name: Setup fixed path ccache caching |
||||
uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 # v3.2.4 |
||||
with: |
||||
path: .ccache |
||||
# Always push to a cache key unique to this commit. |
||||
key: ${{ format('ccache-{0}-{1}-{2}', inputs.cache-prefix, github.ref, github.sha) }} |
||||
# Select a cache to restore from with the follow order of preference: |
||||
# 1) The exact same commit we're running over |
||||
# 2) The latest cache from the current ref branch |
||||
# 3) The latest push to the base ref of a pull request |
||||
restore-keys: | |
||||
${{ format('ccache-{0}-{1}-{2}', inputs.cache-prefix, github.ref, github.sha) }} |
||||
${{ format('ccache-{0}-{1}', inputs.cache-prefix, github.ref) }} |
||||
${{ format('ccache-{0}-{1}', inputs.cache-prefix, github.base_ref) }} |
||||
|
||||
- name: Configure ccache environment variables |
||||
shell: bash |
||||
run: | |
||||
echo "CCACHE_BASEDIR=${{ github.workspace }}" >> $GITHUB_ENV |
||||
echo "CCACHE_DIR=${{ github.workspace }}/.ccache" >> $GITHUB_ENV |
||||
echo "CCACHE_COMPRESS=true" >> $GITHUB_ENV |
||||
echo "CCACHE_COMPRESSLEVEL=6" >> $GITHUB_ENV |
||||
echo "CCACHE_MAXSIZE=600M" >> $GITHUB_ENV |
||||
echo "CCACHE_SLOPPINESS=clang_index_store,include_file_ctime,include_file_mtime,file_macro,time_macros" >> $GITHUB_ENV |
||||
echo "CCACHE_DIRECT=true" >> $GITHUB_ENV |
||||
echo "CCACHE_CMAKE_FLAGS=-Dprotobuf_ALLOW_CCACHE=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache $CCACHE_CMAKE_FLAGS" >> $GITHUB_ENV |
||||
|
||||
- name: Enable module support |
||||
if: ${{ inputs.support-modules }} |
||||
shell: bash |
||||
run: | |
||||
echo "CCACHE_SLOPPINESS=$CCACHE_SLOPPINESS,modules" >> $GITHUB_ENV |
||||
echo "CCACHE_DEPEND=true" >> $GITHUB_ENV |
||||
|
||||
- name: Zero out ccache |
||||
if: ${{ runner.os == 'macOS' }} |
||||
shell: bash |
||||
run: ccache -z |
||||
|
||||
- name: Zero out ccache |
||||
if: ${{ runner.os == 'Windows' }} |
||||
shell: pwsh |
||||
run: ${{ github.workspace }}\ccache.exe -z |
@ -0,0 +1,36 @@ |
||||
name: 'CCache Setup' |
||||
description: 'Setup ccache for us in Windows CI' |
||||
inputs: |
||||
ccache-version: |
||||
required: false |
||||
default: '4.7.4' |
||||
description: A pinned version of ccache |
||||
type: string |
||||
|
||||
runs: |
||||
using: 'composite' |
||||
steps: |
||||
- name: Configure ccache environment variables |
||||
shell: pwsh |
||||
run: | |
||||
Write-Host $Env:GITHUB_REF |
||||
$cllocation = (Get-Command cl.exe).Path |
||||
echo "CCACHE_COMPILER=$cllocation" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append |
||||
echo "CCACHE_COMPILERTYPE=msvc" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append |
||||
|
||||
- name: Download ccache |
||||
shell: bash |
||||
run: | |
||||
curl -kLSs "https://github.com/ccache/ccache/releases/download/v${{ inputs.ccache-version }}/ccache-${{ inputs.ccache-version }}-windows-x86_64.zip" -o ccache.zip |
||||
unzip ccache.zip |
||||
cp ccache-${{ inputs.ccache-version }}-windows-x86_64/ccache.exe ccache.exe |
||||
cp ccache.exe cl.exe |
||||
rm ccache.zip |
||||
|
||||
- name: Configure msbuild flags |
||||
shell: bash |
||||
run: echo "CCACHE_MSBUILD_FLAGS=/p:CLToolExe=cl.exe /p:CLToolPath=${{ github.workspace}}" >> $GITHUB_ENV |
||||
|
||||
- name: Configure cmake flags |
||||
shell: bash |
||||
run: echo "CCACHE_CMAKE_FLAGS=-Dprotobuf_ALLOW_CCACHE=ON" >> $GITHUB_ENV |
Loading…
Reference in new issue