Skip to content

utils: download sccache for Windows #81733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 43 additions & 20 deletions utils/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ param
[string] $Variant = "Asserts",
[switch] $Clean,
[switch] $DebugInfo,
[ValidatePattern('^\d+(\.\d+)*$')]
[string] $SCCacheVersion = "0.10.0",
[switch] $EnableCaching,
[ValidateSet("debug", "release")]
[string] $FoundationTestConfiguration = "debug",
Expand Down Expand Up @@ -374,6 +376,34 @@ $KnownNDKs = @{
}
}

$KnownSCCache = @{
"0.9.1" = @{
AMD64 = @{
URL = "https://github.com/mozilla/sccache/releases/download/v0.9.1/sccache-v0.9.1-x86_64-pc-windows-msvc.zip"
SHA256 = "9C862BCAEF62804F2124DFC2605A0204F4FE0C5FA337BA4264E9BCAE9D2BA487"
Path = [IO.Path]::Combine("$BinaryCache\sccache-0.9.1\sccache-v0.9.1-x86_64-pc-windows-msvc", "sccache.exe");
}
ARM64 = @{
URL = "https://github.com/mozilla/sccache/releases/download/v0.9.1/sccache-v0.9.1-aarch64-pc-windows-msvc.tar.gz"
SHA256 = "99BD024919430DE3C741658ADC60334305A61C0A109F7A334C030F0BB56007A6"
Path = [IO.Path]::Combine("$BinaryCache\sccache-0.9.1\sccache-v0.9.1-aarch64-pc-windows-msvc", "sccache.exe")
}
}

"0.10.0" = @{
AMD64 = @{
URL = "https://github.com/mozilla/sccache/releases/download/v0.10.0/sccache-v0.10.0-x86_64-pc-windows-msvc.zip"
SHA256 = "6D8823B5C13E0DBA776D88C537229256ECB2F01A1D775B507FD141CB55D30578"
Path = [IO.Path]::Combine("$BinaryCache\sccache-0.10.0\sccache-v0.10.0-x86_64-pc-windows-msvc", "sccache.exe")
}
ARM64 = @{
URL = "https://github.com/mozilla/sccache/releases/download/v0.10.0/sccache-v0.10.0-aarch64-pc-windows-msvc.tar.gz"
SHA256 = "5FD6CD6DD474E91C37510719BF27CFE1826F929E40DD383C22A7B96DA9A5458D"
Path = [IO.Path]::Combine("$BinaryCache\sccache-0.10.0\sccache-v0.10.0-aarch64-pc-windows-msvc", "sccache.exe")
}
}
}

$BuildArchName = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE }
# TODO: Support other cross-compilation scenarios.
$BuildOS = [OS]::Windows
Expand Down Expand Up @@ -539,6 +569,10 @@ function Get-BisonExecutable {
return Join-Path -Path $BinaryCache -ChildPath "win_flex_bison\win_bison.exe"
}

function Get-SCCache {
return $KnownSCCache[$SCCacheVersion][$BuildArchName]
}

function Get-PythonPath([Hashtable] $Platform) {
return [IO.Path]::Combine("$BinaryCache\", "Python$($Platform.Architecture.CMakeName)-$PythonVersion")
}
Expand Down Expand Up @@ -967,6 +1001,12 @@ function Get-Dependencies {

if ($SkipBuild) { return }

if ($EnableCaching) {
$SCCache = Get-SCCache
DownloadAndVerify $SCCache.URL "$BinaryCache\sccache-$SCCacheVersion.zip" $SCCache.SHA256
Expand-ZipFile sccache-$SCCacheVersion.zip $BinaryCache sccache-$SCCacheVersion
}

DownloadAndVerify $PinnedBuild "$BinaryCache\$PinnedToolchain.exe" $PinnedSHA256

if ($Test -contains "lldb") {
Expand Down Expand Up @@ -1147,20 +1187,6 @@ function Add-FlagsDefine([hashtable]$Defines, [string]$Name, [string[]]$Value) {
}
}

function Test-SCCacheAtLeast([int]$Major, [int]$Minor, [int]$Patch = 0) {
if ($ToBatch) { return $false }

$SCCacheVersionString = @(& sccache.exe --version)[0]
if (-not ($SCCacheVersionString -match "sccache (\d+)\.(\d+)(?:\.(\d+))?")) {
throw "Unexpected SCCache version string format"
}

if ([int]$Matches.1 -ne $Major) { return [int]$Matches.1 -gt $Major }
if ([int]$Matches.2 -ne $Minor) { return [int]$Matches.2 -gt $Minor }
if ($null -eq $Matches.3) { return 0 -gt $Patch }
return [int]$Matches.3 -ge $Patch
}

function Get-PlatformRoot([OS] $OS) {
return ([IO.Path]::Combine((Get-InstallDir $HostPlatform), "Platforms", "$($OS.ToString()).platform"))
}
Expand Down Expand Up @@ -1289,14 +1315,14 @@ function Build-CMakeProject {
if ($UseMSVCCompilers.Contains("C")) {
Add-KeyValueIfNew $Defines CMAKE_C_COMPILER cl
if ($EnableCaching) {
Add-KeyValueIfNew $Defines CMAKE_C_COMPILER_LAUNCHER sccache
Add-KeyValueIfNew $Defines CMAKE_C_COMPILER_LAUNCHER $(Get-SCCache).Path
}
Add-FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
}
if ($UseMSVCCompilers.Contains("CXX")) {
Add-KeyValueIfNew $Defines CMAKE_CXX_COMPILER cl
if ($EnableCaching) {
Add-KeyValueIfNew $Defines CMAKE_CXX_COMPILER_LAUNCHER sccache
Add-KeyValueIfNew $Defines CMAKE_CXX_COMPILER_LAUNCHER $(Get-SCCache).Path
}
Add-FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFlags
}
Expand Down Expand Up @@ -3192,10 +3218,7 @@ if ($Clean) {

if (-not $SkipBuild) {
if ($EnableCaching) {
if (-Not (Test-SCCacheAtLeast -Major 0 -Minor 7 -Patch 4)) {
throw "Minimum required sccache version is 0.7.4"
}
& sccache.exe --zero-stats
Invoke-Program (Get-SCCache).Path --zero-stats
}

Remove-Item -Force -Recurse ([IO.Path]::Combine((Get-InstallDir $HostPlatform), "Platforms")) -ErrorAction Ignore
Expand Down