Skip to content

Commit baa0125

Browse files
committed
CI: sccache for Visual Studio msbuild and CMake VS jobs
MSVC jobs were the wall clock (10–14 min) and skipped ccache. Use hendrikmuhs/ccache-action variant sccache, wrap cl.exe for msbuild, and pass the same properties through cmake --build. emptyExample and allAddonsExample share OF sources, so the second project in a job should hit the cache even on a cold runner. Subsequent runs restore the GitHub Actions cache per vsYear/platform/toolset.
1 parent d4a549b commit baa0125

3 files changed

Lines changed: 61 additions & 6 deletions

File tree

‎.github/workflows/of.yml‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,12 @@ jobs:
245245
steps:
246246
- uses: actions/checkout@v7.0.1
247247
- name: ccache
248-
if: matrix.name != 'vs-x64' && matrix.name != 'emscripten'
248+
if: matrix.name != 'emscripten'
249249
uses: hendrikmuhs/ccache-action@v1.2.24
250250
with:
251251
key: cmake-${{ matrix.name }}
252+
variant: ${{ matrix.name == 'vs-x64' && 'sccache' || 'ccache' }}
253+
max-size: 1G
252254

253255
- name: Libs, dependencies and projectGenerator (linux64)
254256
if: matrix.name == 'linux64'
@@ -326,6 +328,15 @@ jobs:
326328
if: matrix.name == 'vs-x64'
327329
shell: msys2 {0}
328330
run: ./scripts/ci/vs/install.sh -a x64
331+
- uses: ilammy/msvc-dev-cmd@v1.13.0
332+
if: matrix.name == 'vs-x64'
333+
with:
334+
arch: x64
335+
vsversion: "2022"
336+
- name: sccache cl wrapper (vs-x64)
337+
if: matrix.name == 'vs-x64'
338+
shell: pwsh
339+
run: ./scripts/ci/vs/setup_sccache_cl.ps1
329340
- name: Build (vs-x64)
330341
if: matrix.name == 'vs-x64'
331342
shell: bash
@@ -352,6 +363,12 @@ jobs:
352363
steps:
353364
- name: Clone repository
354365
uses: actions/checkout@v7.0.1
366+
- name: sccache
367+
uses: hendrikmuhs/ccache-action@v1.2.24
368+
with:
369+
variant: sccache
370+
key: vs-${{ matrix.vsYear }}-${{ matrix.platform }}-${{ matrix.toolset }}
371+
max-size: 1G
355372
- uses: msys2/setup-msys2@v2.33.0
356373
with:
357374
update: true
@@ -376,17 +393,28 @@ jobs:
376393
run: ./scripts/ci/vs/install.sh ${{ matrix.installFlag }} -a ${{ matrix.platform }}
377394
- name: Setup MSBuild
378395
uses: microsoft/setup-msbuild@v3
396+
- uses: ilammy/msvc-dev-cmd@v1.13.0
397+
with:
398+
arch: ${{ matrix.platform == 'x64' && 'x64' || matrix.platform == 'ARM64' && 'amd64_arm64' || 'amd64_arm64ec' }}
399+
vsversion: "${{ matrix.vsYear }}"
400+
- name: sccache cl wrapper
401+
shell: pwsh
402+
run: ./scripts/ci/vs/setup_sccache_cl.ps1
379403

380404
- name: Build DEBUG and RELEASE emptyExample
381405
working-directory: ${{env.GITHUB_WORKSPACE}}
406+
shell: pwsh
382407
run: |
383-
msbuild examples/templates/emptyExample/emptyExample.vcxproj /p:Configuration=Debug /p:Platform=${{ matrix.platform }} /p:PlatformToolset=${{ matrix.toolset }}
384-
msbuild examples/templates/emptyExample/emptyExample.vcxproj /p:Configuration=Release /p:Platform=${{ matrix.platform }} /p:PlatformToolset=${{ matrix.toolset }}
408+
$extra = $env:MSBUILD_SCCACHE_PROPS.Split(' ', [System.StringSplitOptions]::RemoveEmptyEntries)
409+
msbuild examples/templates/emptyExample/emptyExample.vcxproj /p:Configuration=Debug /p:Platform=${{ matrix.platform }} /p:PlatformToolset=${{ matrix.toolset }} @extra
410+
msbuild examples/templates/emptyExample/emptyExample.vcxproj /p:Configuration=Release /p:Platform=${{ matrix.platform }} /p:PlatformToolset=${{ matrix.toolset }} @extra
385411
- name: Build DEBUG and RELEASE allAddonsExample
386412
working-directory: ${{env.GITHUB_WORKSPACE}}
413+
shell: pwsh
387414
run: |
388-
msbuild examples/templates/allAddonsExample/allAddonsExample.vcxproj /p:Configuration=Debug /p:Platform=${{ matrix.platform }} /p:PlatformToolset=${{ matrix.toolset }}
389-
msbuild examples/templates/allAddonsExample/allAddonsExample.vcxproj /p:Configuration=Release /p:Platform=${{ matrix.platform }} /p:PlatformToolset=${{ matrix.toolset }}
415+
$extra = $env:MSBUILD_SCCACHE_PROPS.Split(' ', [System.StringSplitOptions]::RemoveEmptyEntries)
416+
msbuild examples/templates/allAddonsExample/allAddonsExample.vcxproj /p:Configuration=Debug /p:Platform=${{ matrix.platform }} /p:PlatformToolset=${{ matrix.toolset }} @extra
417+
msbuild examples/templates/allAddonsExample/allAddonsExample.vcxproj /p:Configuration=Release /p:Platform=${{ matrix.platform }} /p:PlatformToolset=${{ matrix.toolset }} @extra
390418
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
391419
rpi-build:
392420
needs: changes

‎scripts/ci/cmake/build.sh‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ fail(){
4646
configure_and_build(){
4747
local src="$1" dir="$2" config="$3"
4848
$CMAKE_WRAPPER cmake -S "$src" -B "$dir" "${CONFIGURE_ARGS[@]}" -DCMAKE_BUILD_TYPE="$config" || return 1
49-
cmake --build "$dir" --config "$config" --parallel || return 1
49+
if [[ -n "${CMAKE_VS_MSBUILD_ARGS:-}" ]]; then
50+
# shellcheck disable=SC2086
51+
cmake --build "$dir" --config "$config" --parallel -- $CMAKE_VS_MSBUILD_ARGS || return 1
52+
else
53+
cmake --build "$dir" --config "$config" --parallel || return 1
54+
fi
5055
}
5156

5257
# Exercise MSVC addon layouts on every host; no Windows binaries are linked here.

‎scripts/ci/vs/setup_sccache_cl.ps1‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Wrap MSVC cl.exe with sccache for msbuild / Visual Studio CMake generators.
2+
# hendrikmuhs/ccache-action (variant: sccache) must run first so sccache is on PATH.
3+
$ErrorActionPreference = "Stop"
4+
5+
$sccache = (Get-Command sccache).Source
6+
$wrapDir = Join-Path $env:RUNNER_TEMP "sccache-cl"
7+
New-Item -ItemType Directory -Force -Path $wrapDir | Out-Null
8+
$cmdPath = Join-Path $wrapDir "sccache-cl.cmd"
9+
@"
10+
@echo off
11+
"$sccache" cl.exe %*
12+
"@ | Set-Content -Encoding ascii -Path $cmdPath
13+
14+
$props = "/p:CLToolExe=sccache-cl.cmd /p:CLToolPath=$wrapDir /p:TrackFileAccess=false /p:UseMultiToolTask=true /p:DebugInformationFormat=OldStyle"
15+
if ($env:GITHUB_ENV) {
16+
Add-Content -Path $env:GITHUB_ENV -Value "MSBUILD_SCCACHE_PROPS=$props"
17+
Add-Content -Path $env:GITHUB_ENV -Value "CMAKE_VS_MSBUILD_ARGS=$props"
18+
}
19+
Write-Host "sccache: $sccache"
20+
Write-Host "wrapper: $cmdPath"
21+
Write-Host "msbuild props: $props"
22+
& sccache --version

0 commit comments

Comments
 (0)