From 4539e0ab25a3b4e2a9a36b6471dcc122a3b12230 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 22 May 2025 21:26:08 -0700 Subject: [PATCH] utils: download sccache for Windows When `-EnableCaching` is specified, download a specific version of sccache to enable easy enablement. --- utils/build.ps1 | 63 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index bb39cc102b01f..6d91e0aee7906 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -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", @@ -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 @@ -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") } @@ -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") { @@ -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")) } @@ -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 } @@ -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