Skip to content

Commit c49df63

Browse files
Merge pull request #1852 from contour-terminal/ci/windows
[Github CI] Attempt to fix Windows vcpkg caching
2 parents a883102 + 5808f4a commit c49df63

3 files changed

Lines changed: 77 additions & 15 deletions

File tree

.github/workflows/build.yml

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ concurrency:
3131

3232
env:
3333
CTEST_OUTPUT_ON_FAILURE: 1
34-
SCCACHE_GHA_ENABLED: "true"
34+
# Sccache GitHub Actions cache backend - currently disabled due to service reliability
35+
# See https://github.com/mozilla/sccache/blob/main/docs/GHA.md for documentation
36+
SCCACHE_GHA_ENABLED: "false"
37+
SCCACHE_GHA_VERSION: "20260106-1"
3538

3639
jobs:
3740

@@ -615,13 +618,45 @@ jobs:
615618
windows:
616619
name: "Windows"
617620
runs-on: windows-latest
621+
permissions:
622+
contents: read
623+
packages: write
618624
env:
619625
CMAKE_PRESET: "msvc-release"
620-
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
626+
VCPKG_BINARY_SOURCES: "clear;nuget,GitHub,readwrite"
621627
steps:
622628
- uses: actions/checkout@v4
623629
- name: Run sccache-cache
630+
if: env.SCCACHE_GHA_ENABLED == 'true'
624631
uses: mozilla-actions/[email protected]
632+
continue-on-error: true
633+
id: sccache
634+
- name: "Verify sccache is operational"
635+
if: env.SCCACHE_GHA_ENABLED == 'true'
636+
id: verify_sccache
637+
shell: pwsh
638+
run: |
639+
# If GHA cache is disabled, force local disk cache
640+
# Otherwise, allow the sccache-action's default configuration
641+
if ($env:SCCACHE_GHA_ENABLED -eq "false") {
642+
Write-Host "GHA cache disabled, forcing local disk cache"
643+
echo "SCCACHE_GHA_ENABLED=" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
644+
echo "SCCACHE_DIR=$env:LOCALAPPDATA\Mozilla\sccache" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
645+
$env:SCCACHE_GHA_ENABLED = ""
646+
$env:SCCACHE_DIR = "$env:LOCALAPPDATA\Mozilla\sccache"
647+
}
648+
649+
# Quick test to ensure sccache is working
650+
sccache --show-stats
651+
if ($LASTEXITCODE -eq 0) {
652+
Write-Host "Sccache is operational"
653+
echo "sccache_enabled=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
654+
} else {
655+
Write-Host "::warning::Sccache failed, disabling compile caching"
656+
echo "sccache_enabled=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
657+
echo "CMAKE_C_COMPILER_LAUNCHER=" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
658+
echo "CMAKE_CXX_COMPILER_LAUNCHER=" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
659+
}
625660
- name: setup environment
626661
shell: powershell
627662
id: set_vars
@@ -639,12 +674,14 @@ jobs:
639674
version: "6.9.*"
640675
#version: "5.15.*"
641676
modules: qtmultimedia qt5compat qtshadertools
642-
- name: "Setup vcpkg binary caching"
643-
uses: actions/github-script@v7
644-
with:
645-
script: |
646-
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
647-
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
677+
- name: "Setup NuGet for vcpkg caching"
678+
shell: bash
679+
run: |
680+
dotnet nuget add source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" \
681+
--name GitHub \
682+
--username "${{ github.repository_owner }}" \
683+
--password "${{ secrets.GITHUB_TOKEN }}" \
684+
--store-password-in-clear-text
648685
- name: "Cache vcpkg"
649686
uses: actions/cache@v4
650687
id: vcpkg-cache
@@ -653,13 +690,24 @@ jobs:
653690
key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json', 'vcpkg-configuration.json') }}
654691
restore-keys: |
655692
vcpkg-${{ runner.os }}-
693+
- name: "Upgrade NuGet"
694+
run: |
695+
choco upgrade nuget.commandline -y
656696
- name: "vcpkg: Clone and bootstrap"
657697
if: steps.vcpkg-cache.outputs.cache-hit != 'true'
658698
run: |
659699
git clone --depth 1 https://github.com/microsoft/vcpkg.git ${{ runner.workspace }}\vcpkg
660700
${{ runner.workspace }}\vcpkg\bootstrap-vcpkg.bat
701+
${{ runner.workspace }}\vcpkg\vcpkg.exe fetch nuget
702+
env:
703+
VCPKG_BINARY_SOURCES: "clear;nuget,GitHub,readwrite"
704+
- name: "vcpkg: Install dependencies"
705+
shell: pwsh
706+
run: |
707+
${{ runner.workspace }}\vcpkg\vcpkg.exe install --triplet x64-windows
661708
env:
662-
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
709+
VCPKG_ROOT: "${{ runner.workspace }}/vcpkg"
710+
VCPKG_BINARY_SOURCES: "clear;nuget,GitHub,readwrite"
663711
- name: "Install cmake"
664712
uses: lukka/[email protected]
665713
- name: "Check cmake version"
@@ -675,6 +723,11 @@ jobs:
675723
shell: pwsh
676724
run: |
677725
cmake --build --preset ${{ env.CMAKE_PRESET }}
726+
- name: "Show sccache statistics"
727+
if: steps.verify_sccache.outputs.sccache_enabled == 'true'
728+
shell: pwsh
729+
run: |
730+
sccache --show-stats
678731
- name: "Test"
679732
shell: pwsh
680733
run: |

cmake/EnableCcache.cmake

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
# Setup ccache.
1+
# Setup ccache/sccache.
22
#
3-
# The ccache is auto-enabled if the tool is found.
4-
# To disable set -DCCACHE=OFF option.
5-
option(ENABLE_CCACHE "Enable compiler cache (ccache) [default: ON]" ON)
3+
# The compiler cache is auto-enabled if the tool is found.
4+
# To disable set -DENABLE_CCACHE=OFF option.
5+
option(ENABLE_CCACHE "Enable compiler cache (ccache/sccache) [default: ON]" ON)
66
if(ENABLE_CCACHE)
77
if(NOT DEFINED CMAKE_CXX_COMPILER_LAUNCHER)
8-
find_program(CCACHE ccache DOC "ccache tool path; set to OFF to disable")
8+
# Try sccache first (better Windows/MSVC support), then fall back to ccache
9+
find_program(CCACHE sccache DOC "sccache tool path")
10+
if(NOT CCACHE)
11+
find_program(CCACHE ccache DOC "ccache tool path")
12+
endif()
13+
914
if(CCACHE)
1015
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
16+
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
1117
if(COMMAND cotire)
1218
# Change ccache config to meet cotire requirements.
1319
set(ENV{CCACHE_SLOPPINESS} pch_defines,time_macros)
@@ -16,6 +22,9 @@ if(ENABLE_CCACHE)
1622
else()
1723
message(STATUS "[ccache] Disabled: Not found.")
1824
endif()
25+
else()
26+
# Compiler launcher already set (e.g., by CI environment)
27+
message(STATUS "[ccache] Using pre-configured launcher: ${CMAKE_CXX_COMPILER_LAUNCHER}")
1928
endif()
2029
else()
2130
message(STATUS "[ccache] Disabled.")

cmake/presets/os-windows.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"CMAKE_SYSTEM_VERSION": "10",
2222
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
2323
"LIBTERMINAL_BUILD_BENCH_HEADLESS": "OFF",
24-
"ENABLE_CCACHE": "OFF"
24+
"ENABLE_CCACHE": "ON"
2525
}
2626
},
2727
{

0 commit comments

Comments
 (0)