Skip to content

Commit 4539e0a

Browse files
committed
utils: download sccache for Windows
When `-EnableCaching` is specified, download a specific version of sccache to enable easy enablement.
1 parent 789f657 commit 4539e0a

File tree

1 file changed

+43
-20
lines changed

1 file changed

+43
-20
lines changed

utils/build.ps1

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ param
152152
[string] $Variant = "Asserts",
153153
[switch] $Clean,
154154
[switch] $DebugInfo,
155+
[ValidatePattern('^\d+(\.\d+)*$')]
156+
[string] $SCCacheVersion = "0.10.0",
155157
[switch] $EnableCaching,
156158
[ValidateSet("debug", "release")]
157159
[string] $FoundationTestConfiguration = "debug",
@@ -374,6 +376,34 @@ $KnownNDKs = @{
374376
}
375377
}
376378

379+
$KnownSCCache = @{
380+
"0.9.1" = @{
381+
AMD64 = @{
382+
URL = "https://github.com/mozilla/sccache/releases/download/v0.9.1/sccache-v0.9.1-x86_64-pc-windows-msvc.zip"
383+
SHA256 = "9C862BCAEF62804F2124DFC2605A0204F4FE0C5FA337BA4264E9BCAE9D2BA487"
384+
Path = [IO.Path]::Combine("$BinaryCache\sccache-0.9.1\sccache-v0.9.1-x86_64-pc-windows-msvc", "sccache.exe");
385+
}
386+
ARM64 = @{
387+
URL = "https://github.com/mozilla/sccache/releases/download/v0.9.1/sccache-v0.9.1-aarch64-pc-windows-msvc.tar.gz"
388+
SHA256 = "99BD024919430DE3C741658ADC60334305A61C0A109F7A334C030F0BB56007A6"
389+
Path = [IO.Path]::Combine("$BinaryCache\sccache-0.9.1\sccache-v0.9.1-aarch64-pc-windows-msvc", "sccache.exe")
390+
}
391+
}
392+
393+
"0.10.0" = @{
394+
AMD64 = @{
395+
URL = "https://github.com/mozilla/sccache/releases/download/v0.10.0/sccache-v0.10.0-x86_64-pc-windows-msvc.zip"
396+
SHA256 = "6D8823B5C13E0DBA776D88C537229256ECB2F01A1D775B507FD141CB55D30578"
397+
Path = [IO.Path]::Combine("$BinaryCache\sccache-0.10.0\sccache-v0.10.0-x86_64-pc-windows-msvc", "sccache.exe")
398+
}
399+
ARM64 = @{
400+
URL = "https://github.com/mozilla/sccache/releases/download/v0.10.0/sccache-v0.10.0-aarch64-pc-windows-msvc.tar.gz"
401+
SHA256 = "5FD6CD6DD474E91C37510719BF27CFE1826F929E40DD383C22A7B96DA9A5458D"
402+
Path = [IO.Path]::Combine("$BinaryCache\sccache-0.10.0\sccache-v0.10.0-aarch64-pc-windows-msvc", "sccache.exe")
403+
}
404+
}
405+
}
406+
377407
$BuildArchName = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE }
378408
# TODO: Support other cross-compilation scenarios.
379409
$BuildOS = [OS]::Windows
@@ -539,6 +569,10 @@ function Get-BisonExecutable {
539569
return Join-Path -Path $BinaryCache -ChildPath "win_flex_bison\win_bison.exe"
540570
}
541571

572+
function Get-SCCache {
573+
return $KnownSCCache[$SCCacheVersion][$BuildArchName]
574+
}
575+
542576
function Get-PythonPath([Hashtable] $Platform) {
543577
return [IO.Path]::Combine("$BinaryCache\", "Python$($Platform.Architecture.CMakeName)-$PythonVersion")
544578
}
@@ -967,6 +1001,12 @@ function Get-Dependencies {
9671001

9681002
if ($SkipBuild) { return }
9691003

1004+
if ($EnableCaching) {
1005+
$SCCache = Get-SCCache
1006+
DownloadAndVerify $SCCache.URL "$BinaryCache\sccache-$SCCacheVersion.zip" $SCCache.SHA256
1007+
Expand-ZipFile sccache-$SCCacheVersion.zip $BinaryCache sccache-$SCCacheVersion
1008+
}
1009+
9701010
DownloadAndVerify $PinnedBuild "$BinaryCache\$PinnedToolchain.exe" $PinnedSHA256
9711011

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

1150-
function Test-SCCacheAtLeast([int]$Major, [int]$Minor, [int]$Patch = 0) {
1151-
if ($ToBatch) { return $false }
1152-
1153-
$SCCacheVersionString = @(& sccache.exe --version)[0]
1154-
if (-not ($SCCacheVersionString -match "sccache (\d+)\.(\d+)(?:\.(\d+))?")) {
1155-
throw "Unexpected SCCache version string format"
1156-
}
1157-
1158-
if ([int]$Matches.1 -ne $Major) { return [int]$Matches.1 -gt $Major }
1159-
if ([int]$Matches.2 -ne $Minor) { return [int]$Matches.2 -gt $Minor }
1160-
if ($null -eq $Matches.3) { return 0 -gt $Patch }
1161-
return [int]$Matches.3 -ge $Patch
1162-
}
1163-
11641190
function Get-PlatformRoot([OS] $OS) {
11651191
return ([IO.Path]::Combine((Get-InstallDir $HostPlatform), "Platforms", "$($OS.ToString()).platform"))
11661192
}
@@ -1289,14 +1315,14 @@ function Build-CMakeProject {
12891315
if ($UseMSVCCompilers.Contains("C")) {
12901316
Add-KeyValueIfNew $Defines CMAKE_C_COMPILER cl
12911317
if ($EnableCaching) {
1292-
Add-KeyValueIfNew $Defines CMAKE_C_COMPILER_LAUNCHER sccache
1318+
Add-KeyValueIfNew $Defines CMAKE_C_COMPILER_LAUNCHER $(Get-SCCache).Path
12931319
}
12941320
Add-FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
12951321
}
12961322
if ($UseMSVCCompilers.Contains("CXX")) {
12971323
Add-KeyValueIfNew $Defines CMAKE_CXX_COMPILER cl
12981324
if ($EnableCaching) {
1299-
Add-KeyValueIfNew $Defines CMAKE_CXX_COMPILER_LAUNCHER sccache
1325+
Add-KeyValueIfNew $Defines CMAKE_CXX_COMPILER_LAUNCHER $(Get-SCCache).Path
13001326
}
13011327
Add-FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFlags
13021328
}
@@ -3192,10 +3218,7 @@ if ($Clean) {
31923218

31933219
if (-not $SkipBuild) {
31943220
if ($EnableCaching) {
3195-
if (-Not (Test-SCCacheAtLeast -Major 0 -Minor 7 -Patch 4)) {
3196-
throw "Minimum required sccache version is 0.7.4"
3197-
}
3198-
& sccache.exe --zero-stats
3221+
Invoke-Program (Get-SCCache).Path --zero-stats
31993222
}
32003223

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

0 commit comments

Comments
 (0)