Skip to content

Commit b02a11f

Browse files
committed
utils: integrate support for caching when building
Integrate support for sccache into the build system. This allows us to get a reasonable performance increase for clean builds for the C/C++ side of the build. This is currently limited to the MSVC compiler as the extended compiler flags cause issues for sccache.
1 parent 3e816f5 commit b02a11f

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

utils/build-windows-toolchain.bat

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ echo Reeinvoking script in the default environment
1818
set TEMP=%~dp0..\..\tmp
1919
mkdir %TEMP% 2>&1 1>nul
2020
echo set PYTHON_HOME=%PYTHON_HOME%> %TEMP%\call-build.cmd
21-
echo set CMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%>> %TEMP%\call-build.cmd
2221
echo set SKIP_TESTS=%SKIP_TESTS%>> %TEMP%\call-build.cmd
2322
echo set SKIP_PACKAGING=%SKIP_PACKAGING%>> %TEMP%\call-build.cmd
2423
echo set SKIP_UPDATE_CHECKOUT=%SKIP_UPDATE_CHECKOUT%>> %TEMP%\call-build.cmd
@@ -60,8 +59,6 @@ set TMPDIR=%BuildRoot%\tmp
6059

6160
set NINJA_STATUS=[%%f/%%t][%%p][%%es]
6261

63-
if "%CMAKE_BUILD_TYPE%"=="" (set CMAKE_BUILD_TYPE=Release)
64-
6562
:: Build the -Test argument, if any, by subtracting skipped tests
6663
set TestArg=-Test swift,dispatch,foundation,xctest,
6764
for %%I in (%SKIP_TESTS%) do (call set TestArg=%%TestArg:%%I,=%%)
@@ -78,7 +75,6 @@ powershell.exe -ExecutionPolicy RemoteSigned -File %~dp0build.ps1 ^
7875
-SourceCache %SourceRoot% ^
7976
-BinaryCache %BuildRoot% ^
8077
-ImageRoot %BuildRoot% ^
81-
-BuildType %CMAKE_BUILD_TYPE% ^
8278
%SkipPackagingArg% ^
8379
%TestArg% ^
8480
-Stage %PackageRoot% || (exit /b 1)

utils/build.ps1

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ The path to a directory that mimics a file system image root,
2626
under which "Library" and "Program Files" subdirectories will be created
2727
with the files installed by CMake.
2828
29-
.PARAMETER BuildType
30-
The CMake build type to use, one of: Release, RelWithDebInfo, Debug.
31-
3229
.PARAMETER CDebugFormat
3330
The debug information format for C/C++ code: dwarf or codeview.
3431
@@ -62,6 +59,12 @@ If set, skips building the msi's and installer
6259
.PARAMETER DefaultsLLD
6360
If false, use `link.exe` as the default linker with the SDK (with SPM)
6461
62+
.PARAMETER DebugInfo
63+
If set, debug information will be generated for the builds.
64+
65+
.PARAMETER EnableCaching
66+
If true, use `sccache` to cache the build rules.
67+
6568
.PARAMETER Test
6669
An array of names of projects to run tests for.
6770
'*' runs all tests
@@ -88,7 +91,6 @@ param(
8891
[string] $SourceCache = "S:\SourceCache",
8992
[string] $BinaryCache = "S:\b",
9093
[string] $ImageRoot = "S:",
91-
[string] $BuildType = "Release",
9294
[string] $CDebugFormat = "dwarf",
9395
[string] $SwiftDebugFormat = "dwarf",
9496
[string[]] $SDKs = @("X64","X86","Arm64"),
@@ -103,6 +105,8 @@ param(
103105
[string[]] $Test = @(),
104106
[string] $Stage = "",
105107
[string] $BuildTo = "",
108+
[switch] $DebugInfo,
109+
[switch] $EnableCaching,
106110
[switch] $ToBatch
107111
)
108112

@@ -528,21 +532,30 @@ function Build-CMakeProject {
528532
# Add additional defines (unless already present)
529533
$Defines = $Defines.Clone()
530534

531-
TryAdd-KeyValue $Defines CMAKE_BUILD_TYPE $BuildType
535+
TryAdd-KeyValue $Defines CMAKE_BUILD_TYPE Release
532536
TryAdd-KeyValue $Defines CMAKE_MT "mt"
533537

534-
$GenerateDebugInfo = $Defines["CMAKE_BUILD_TYPE"] -ne "Release"
535-
536538
$CFlags = @("/GS-", "/Gw", "/Gy", "/Oi", "/Oy", "/Zc:inline")
537-
if ($GenerateDebugInfo) { $CFlags += "/Zi" }
539+
if ($DebugInfo) { $CFlags += if ($EnableCaching) { "/Z7" } else { "/Zi" } }
538540
$CXXFlags = $CFlags.Clone() + "/Zc:__cplusplus"
539541

542+
if ($EnableCaching) {
543+
$env:SCCACHE_DIRECT = "true"
544+
$env:SCCACHE_DIR = "$BinaryCache\sccache"
545+
}
546+
540547
if ($UseMSVCCompilers.Contains("C")) {
541548
TryAdd-KeyValue $Defines CMAKE_C_COMPILER cl
549+
if ($EnableCaching) {
550+
TryAdd-KeyValue $Defines CMAKE_C_COMPILER_LAUNCHER sccache
551+
}
542552
Append-FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
543553
}
544554
if ($UseMSVCCompilers.Contains("CXX")) {
545555
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER cl
556+
if ($EnableCaching) {
557+
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER_LAUNCHER sccache
558+
}
546559
Append-FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFlags
547560
}
548561
if ($UsePinnedCompilers.Contains("ASM") -Or $UseBuiltCompilers.Contains("ASM")) {
@@ -567,7 +580,7 @@ function Build-CMakeProject {
567580
TryAdd-KeyValue $Defines CMAKE_CL_SHOWINCLUDES_PREFIX "Note: including file: "
568581
}
569582

570-
if ($GenerateDebugInfo -and $CDebugFormat -eq "dwarf") {
583+
if ($DebugInfo -and $CDebugFormat -eq "dwarf") {
571584
Append-FlagsDefine $Defines CMAKE_C_FLAGS "-gdwarf"
572585
}
573586
Append-FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
@@ -585,7 +598,7 @@ function Build-CMakeProject {
585598
TryAdd-KeyValue $Defines CMAKE_CL_SHOWINCLUDES_PREFIX "Note: including file: "
586599
}
587600

588-
if ($GenerateDebugInfo -and $CDebugFormat -eq "dwarf") {
601+
if ($DebugInfo -and $CDebugFormat -eq "dwarf") {
589602
Append-FlagsDefine $Defines CMAKE_CXX_FLAGS "-gdwarf"
590603
}
591604
Append-FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFlags
@@ -615,7 +628,7 @@ function Build-CMakeProject {
615628
}
616629

617630
# Debug Information
618-
if ($GenerateDebugInfo) {
631+
if ($DebugInfo) {
619632
if ($SwiftDebugFormat -eq "dwarf") {
620633
$SwiftArgs += @("-g", "-Xlinker", "/DEBUG:DWARF", "-use-ld=lld-link")
621634
} else {
@@ -730,14 +743,14 @@ function Build-SPMProject {
730743
"-Xcc", "-I$SDKInstallRoot\usr\lib\swift",
731744
"-Xlinker", "-L$SDKInstallRoot\usr\lib\swift\windows"
732745
)
733-
if ($BuildType -eq "Release") {
734-
$Arguments += @("-debug-info-format", "none")
735-
} else {
746+
if ($DebugInfo) {
736747
if ($SwiftDebugFormat -eq "dwarf") {
737748
$Arguments += @("-debug-info-format", "dwarf")
738749
} else {
739750
$Arguments += @("-debug-info-format", "codeview")
740751
}
752+
} else {
753+
$Arguments += @("-debug-info-format", "none")
741754
}
742755

743756
Invoke-Program "$ToolchainInstallRoot\usr\bin\swift.exe" "build" @Arguments @AdditionalArguments
@@ -798,6 +811,7 @@ function Build-BuildTools($Arch) {
798811
-Src $SourceCache\llvm-project\llvm `
799812
-Bin $BinaryCache\0 `
800813
-Arch $Arch `
814+
-UseMSVCCompilers C,CXX `
801815
-BuildTargets llvm-tblgen,clang-tblgen,clang-pseudo-gen,clang-tidy-confusable-chars-gen,lldb-tblgen,llvm-config,swift-def-to-strings-converter,swift-serialize-diagnostics,swift-compatibility-symbols `
802816
-Defines @{
803817
LLDB_ENABLE_PYTHON = "NO";
@@ -845,11 +859,6 @@ function Build-Compilers($Arch, [switch]$Test = $false) {
845859

846860
$env:Path = "$BinaryCache\toolchains\$PinnedToolchain\PFiles64\Swift\runtime-development\usr\bin;${env:Path}"
847861

848-
$LLVM_ENABLE_PDB = switch ($BuildType) {
849-
"Release" { "NO" }
850-
default { "YES" }
851-
}
852-
853862
Build-CMakeProject `
854863
-Src $SourceCache\llvm-project\llvm `
855864
-Bin $BinaryCache\1 `
@@ -860,10 +869,6 @@ function Build-Compilers($Arch, [switch]$Test = $false) {
860869
-Defines ($TestingDefines + @{
861870
CLANG_TABLEGEN = "$BinaryCache\0\bin\clang-tblgen.exe";
862871
CLANG_TIDY_CONFUSABLE_CHARS_GEN = "$BinaryCache\0\bin\clang-tidy-confusable-chars-gen.exe";
863-
# LLVM plays tricks with flags and prefers to use `LLVM_ENABLE_PDB` for
864-
# debug information on Windows rather than the CMake handling. This
865-
# give us a sligtly faster build.
866-
CMAKE_BUILD_TYPE = "Release";
867872
CMAKE_INSTALL_PREFIX = "$($Arch.ToolchainInstallRoot)\usr";
868873
CMAKE_Swift_COMPILER = "$BinaryCache\toolchains\$PinnedToolchain\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe";
869874
CMAKE_Swift_FLAGS = @("-sdk", "$BinaryCache\toolchains\$PinnedToolchain\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk");
@@ -872,7 +877,6 @@ function Build-Compilers($Arch, [switch]$Test = $false) {
872877
LLDB_PYTHON_RELATIVE_PATH = "lib/site-packages";
873878
LLDB_TABLEGEN = "$BinaryCache\0\bin\lldb-tblgen.exe";
874879
LLVM_CONFIG_PATH = "$BinaryCache\0\bin\llvm-config.exe";
875-
LLVM_ENABLE_PDB = $LLVM_ENABLE_PDB;
876880
LLVM_EXTERNAL_CMARK_SOURCE_DIR = "$SourceCache\cmark";
877881
LLVM_EXTERNAL_SWIFT_SOURCE_DIR = "$SourceCache\swift";
878882
LLVM_NATIVE_TOOL_DIR = "$BinaryCache\0\bin";

0 commit comments

Comments
 (0)