Skip to content

Commit 9105f06

Browse files
committed
utils: enable early swift driver on Windows
This wires up the build of the swift-driver via SPM from the pinned toolchain to allow us the use of the early swift driver in the Swift build.
1 parent 6221b29 commit 9105f06

File tree

1 file changed

+97
-42
lines changed

1 file changed

+97
-42
lines changed

utils/build.ps1

Lines changed: 97 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ $ArchX64 = @{
238238
ToolchainInstallRoot = "$BinaryCache\x64\toolchains\$ProductVersion+Asserts";
239239
}
240240

241+
$WindowsX64 = $ArchX64
242+
241243
$ArchX86 = @{
242244
VSName = "x86";
243245
ShortName = "x86";
@@ -253,6 +255,8 @@ $ArchX86 = @{
253255
SwiftTestingInstallRoot = "$BinaryCache\x86\Windows.platform\Developer\Library\Testing-development";
254256
}
255257

258+
$WindowsX86 = $ArchX86
259+
256260
$ArchARM64 = @{
257261
VSName = "arm64";
258262
ShortName = "arm64";
@@ -269,6 +273,8 @@ $ArchARM64 = @{
269273
SwiftTestingInstallRoot = "$BinaryCache\arm64\Windows.platform\Developer\Library\Testing-development";
270274
}
271275

276+
$WindowsARM64 = $ArchARM64
277+
272278
$AndroidARM64 = @{
273279
AndroidArchABI = "arm64-v8a";
274280
BinaryDir = "bin64a";
@@ -433,7 +439,7 @@ function Get-TargetProjectBinaryCache($Arch, [TargetComponent]$Project) {
433439
}
434440

435441
enum HostComponent {
436-
Compilers = 5
442+
Compilers = 9
437443
FoundationMacros = 10
438444
TestingMacros
439445
System
@@ -467,6 +473,7 @@ function Get-HostProjectCMakeModules([HostComponent]$Project) {
467473

468474
enum BuildComponent {
469475
BuildTools
476+
Driver
470477
Compilers
471478
FoundationMacros
472479
TestingMacros
@@ -874,6 +881,7 @@ function Build-CMakeProject {
874881
[string[]] $UseMSVCCompilers = @(), # C,CXX
875882
[string[]] $UseBuiltCompilers = @(), # ASM,C,CXX,Swift
876883
[string[]] $UsePinnedCompilers = @(), # ASM,C,CXX,Swift
884+
[bool] $UseEarlySwiftDriver = $true,
877885
[switch] $UseSwiftSwiftDriver = $false,
878886
[switch] $AddAndroidCMakeEnv = $false,
879887
[string] $SwiftSDK = "",
@@ -1183,7 +1191,11 @@ function Build-CMakeProject {
11831191
}
11841192

11851193
if ($UseBuiltCompilers.Contains("Swift")) {
1186-
$env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMarkBinaryCache $Arch)\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path}"
1194+
$env:Path = if ($UseEarlySwiftDriver) {
1195+
"$(Get-PinnedToolchainRuntime);$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMarkBinaryCache $BuildArch)\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path}"
1196+
} else {
1197+
"$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMarkBinaryCache $BuildArch)\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path};$(Get-PinnedToolchainRuntime)"
1198+
}
11871199
} elseif ($UsePinnedCompilers.Contains("Swift")) {
11881200
$env:Path = "$(Get-PinnedToolchainRuntime);${env:Path}"
11891201
}
@@ -1493,6 +1505,7 @@ function Build-Compilers() {
14931505
Python3_ROOT_DIR = "$BinaryCache\Python$($Arch.CMakeName)-$PythonVersion\tools";
14941506
SWIFT_BUILD_SWIFT_SYNTAX = "YES";
14951507
SWIFT_CLANG_LOCATION = (Get-PinnedToolchainTool);
1508+
SWIFT_EARLY_SWIFT_DRIVER_BUILD = "$(Get-BuildProjectBinaryCache Driver)\$($BuildArch.LLVMTarget)\release";
14961509
SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY = "YES";
14971510
SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP = "YES";
14981511
SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING = "YES";
@@ -1835,6 +1848,7 @@ function Build-Dispatch([Platform]$Platform, $Arch, [switch]$Test = $false) {
18351848
-Arch $Arch `
18361849
-Platform $Platform `
18371850
-UseBuiltCompilers C,CXX,Swift `
1851+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
18381852
-Defines @{
18391853
ENABLE_SWIFT = "YES";
18401854
}
@@ -1877,28 +1891,17 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
18771891
$ShortArch = $Arch.LLVMName
18781892

18791893
Isolate-EnvVars {
1880-
$SDKRoot = if ($Platform -eq "Windows") {
1881-
""
1882-
} else {
1883-
(Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot
1884-
}
1885-
1886-
$SDKRoot = if ($Platform -eq "Windows") {
1887-
""
1888-
} else {
1889-
(Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot
1890-
}
1891-
18921894
Build-CMakeProject `
18931895
-Src $SourceCache\swift-corelibs-foundation `
18941896
-Bin $FoundationBinaryCache `
18951897
-InstallTo "$($Arch.SDKInstallRoot)\usr" `
18961898
-Arch $Arch `
18971899
-Platform $Platform `
18981900
-UseBuiltCompilers ASM,C,CXX,Swift `
1899-
-SwiftSDK:$SDKRoot `
1901+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
19001902
-Defines (@{
19011903
ENABLE_TESTING = "NO";
1904+
CMAKE_Swift_COMPILER_USE_OLD_DRIVER = "YES";
19021905
FOUNDATION_BUILD_TOOLS = if ($Platform -eq "Windows") { "YES" } else { "NO" };
19031906
CURL_DIR = "$LibraryRoot\curl-8.9.1\usr\lib\$Platform\$ShortArch\cmake\CURL";
19041907
LIBXML2_LIBRARY = if ($Platform -eq "Windows") {
@@ -1942,7 +1945,7 @@ function Build-FoundationMacros() {
19421945
Get-HostProjectBinaryCache FoundationMacros
19431946
}
19441947

1945-
$SwiftSDK = $null
1948+
$SwiftSDK = $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot)
19461949
if ($Build) {
19471950
$SwiftSDK = $BuildArch.SDKInstallRoot
19481951
}
@@ -1967,7 +1970,7 @@ function Build-FoundationMacros() {
19671970
-Arch $Arch `
19681971
-Platform $Platform `
19691972
-UseBuiltCompilers Swift `
1970-
-SwiftSDK:$SwiftSDK `
1973+
-SwiftSDK $SwiftSDK `
19711974
-BuildTargets:$Targets `
19721975
-Defines @{
19731976
SwiftSyntax_DIR = $SwiftSyntaxCMakeModules;
@@ -2004,6 +2007,7 @@ function Build-XCTest([Platform]$Platform, $Arch, [switch]$Test = $false) {
20042007
-Arch $Arch `
20052008
-Platform $Platform `
20062009
-UseBuiltCompilers Swift `
2010+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
20072011
-BuildTargets $Targets `
20082012
-Defines (@{
20092013
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
@@ -2033,6 +2037,7 @@ function Build-Testing([Platform]$Platform, $Arch, [switch]$Test = $false) {
20332037
-Arch $Arch `
20342038
-Platform $Platform `
20352039
-UseBuiltCompilers C,CXX,Swift `
2040+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
20362041
-Defines (@{
20372042
BUILD_SHARED_LIBS = "YES";
20382043
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
@@ -2258,29 +2263,79 @@ function Build-ArgumentParser($Arch) {
22582263
}
22592264
}
22602265

2261-
function Build-Driver($Arch) {
2262-
Build-CMakeProject `
2263-
-Src $SourceCache\swift-driver `
2264-
-Bin (Get-HostProjectBinaryCache Driver) `
2265-
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
2266-
-Arch $Arch `
2267-
-Platform Windows `
2268-
-UseBuiltCompilers C,CXX,Swift `
2269-
-SwiftSDK (Get-HostSwiftSDK) `
2270-
-Defines @{
2271-
BUILD_SHARED_LIBS = "YES";
2272-
SwiftSystem_DIR = (Get-HostProjectCMakeModules System);
2273-
TSC_DIR = (Get-HostProjectCMakeModules ToolsSupportCore);
2274-
LLBuild_DIR = (Get-HostProjectCMakeModules LLBuild);
2275-
Yams_DIR = (Get-HostProjectCMakeModules Yams);
2276-
ArgumentParser_DIR = (Get-HostProjectCMakeModules ArgumentParser);
2277-
SQLite3_INCLUDE_DIR = "$LibraryRoot\sqlite-3.46.0\usr\include";
2278-
SQLite3_LIBRARY = "$LibraryRoot\sqlite-3.46.0\usr\lib\SQLite3.lib";
2279-
SWIFT_DRIVER_BUILD_TOOLS = "YES";
2280-
LLVM_DIR = "$(Get-HostProjectBinaryCache Compilers)\lib\cmake\llvm";
2281-
Clang_DIR = "$(Get-HostProjectBinaryCache Compilers)\lib\cmake\clang";
2282-
Swift_DIR = "$(Get-HostProjectBinaryCache Compilers)\tools\swift\lib\cmake\swift";
2266+
function Build-Driver() {
2267+
[CmdletBinding(PositionalBinding = $false)]
2268+
param
2269+
(
2270+
[Parameter(Position = 0, Mandatory = $true)]
2271+
[hashtable]$Arch,
2272+
[switch] $Build = $false
2273+
)
2274+
2275+
if ($Build) {
2276+
$Stopwatch = [Diagnostics.Stopwatch]::StartNew()
2277+
2278+
Isolate-EnvVars {
2279+
$env:SWIFTCI_USE_LOCAL_DEPS=1
2280+
$env:SDKROOT = (Get-PinnedToolchainSDK)
2281+
$env:Path = "$(Get-PinnedToolchainRuntime);$(Get-PinnedToolchainTool);${env:Path}"
2282+
2283+
$src = "$SourceCache\swift-driver"
2284+
$dst = (Get-BuildProjectBinaryCache Driver)
2285+
2286+
if ($ToBatch) {
2287+
Write-Output ""
2288+
Write-Output "echo Building '$src' to '$dst' for arch '$($Arch.LLVMName)'..."
2289+
} else {
2290+
Write-Host -ForegroundColor Cyan "[$([DateTime]::Now.ToString("yyyy-MM-dd HH:mm:ss"))] Building '$src' to '$dst' for arch '$($Arch.LLVMName)'..."
2291+
}
2292+
2293+
Invoke-Program `
2294+
"$(Get-PinnedToolchainTool)\swift.exe" build `
2295+
-c release `
2296+
--scratch-path $dst `
2297+
--package-path $src `
2298+
-Xcc -Xclang -Xcc -fno-split-cold-code `
2299+
-Xlinker "$(Get-PinnedToolchainSDK)\usr\lib\swift\windows\$($BuildArch.LLVMName)\swiftCore.lib"
2300+
2301+
if (-not $ToBatch) {
2302+
Write-Host -ForegroundColor Cyan "[$([DateTime]::Now.ToString("yyyy-MM-dd HH:mm:ss"))] Finished building '$src' to '$dst' for arch '$($Arch.LLVMName)' in $($Stopwatch.Elapsed)"
2303+
Write-Host ""
2304+
}
2305+
2306+
if ($Summary) {
2307+
$TimingData.Add([PSCustomObject]@{
2308+
Arch = $BuildArch.LLVMName
2309+
Checkout = $src.Replace($SourceCache, '')
2310+
Platform = "Windows"
2311+
"Elapsed Time" = $Stopwatch.Elapsed.ToString()
2312+
})
2313+
}
22832314
}
2315+
} else {
2316+
Build-CMakeProject `
2317+
-Src $SourceCache\swift-driver `
2318+
-Bin (Get-HostProjectBinaryCache Driver) `
2319+
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
2320+
-Arch $Arch `
2321+
-Platform Windows `
2322+
-UseBuiltCompilers C,CXX,Swift `
2323+
-SwiftSDK (Get-HostSwiftSDK) `
2324+
-Defines @{
2325+
BUILD_SHARED_LIBS = "YES";
2326+
SwiftSystem_DIR = (Get-HostProjectCMakeModules System);
2327+
TSC_DIR = (Get-HostProjectCMakeModules ToolsSupportCore);
2328+
LLBuild_DIR = (Get-HostProjectCMakeModules LLBuild);
2329+
Yams_DIR = (Get-HostProjectCMakeModules Yams);
2330+
ArgumentParser_DIR = (Get-HostProjectCMakeModules ArgumentParser);
2331+
SQLite3_INCLUDE_DIR = "$LibraryRoot\sqlite-3.46.0\usr\include";
2332+
SQLite3_LIBRARY = "$LibraryRoot\sqlite-3.46.0\usr\lib\SQLite3.lib";
2333+
SWIFT_DRIVER_BUILD_TOOLS = "YES";
2334+
LLVM_DIR = "$(Get-HostProjectBinaryCache Compilers)\lib\cmake\llvm";
2335+
Clang_DIR = "$(Get-HostProjectBinaryCache Compilers)\lib\cmake\clang";
2336+
Swift_DIR = "$(Get-HostProjectBinaryCache Compilers)\tools\swift\lib\cmake\swift";
2337+
}
2338+
}
22842339
}
22852340

22862341
function Build-Crypto($Arch) {
@@ -2578,7 +2633,7 @@ function Build-TestingMacros() {
25782633
Get-HostProjectBinaryCache TestingMacros
25792634
}
25802635

2581-
$SwiftSDK = $null
2636+
$SwiftSDK = $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot)
25822637
if ($Build) {
25832638
$SwiftSDK = $BuildArch.SDKInstallRoot
25842639
}
@@ -2609,7 +2664,7 @@ function Build-TestingMacros() {
26092664
-Arch $Arch `
26102665
-Platform $Platform `
26112666
-UseBuiltCompilers Swift `
2612-
-SwiftSDK:$SwiftSDK `
2667+
-SwiftSDK $SwiftSDK `
26132668
-BuildTargets:$Targets `
26142669
-Defines @{
26152670
SwiftSyntax_DIR = $SwiftSyntaxCMakeModules;
@@ -2645,7 +2700,6 @@ function Build-Inspect() {
26452700
-InstallTo "$($HostArch.ToolchainInstallRoot)\usr" `
26462701
-Arch $HostArch `
26472702
-UseBuiltCompilers Swift `
2648-
-UseSwiftSwiftDriver `
26492703
-SwiftSDK $SDKRoot `
26502704
-Defines @{
26512705
CMAKE_Swift_FLAGS = @("-Xcc", "-I$SDKRoot\usr\include\swift\SwiftRemoteMirror");
@@ -2747,6 +2801,7 @@ Fetch-Dependencies
27472801
if (-not $SkipBuild) {
27482802
Invoke-BuildStep Build-CMark $BuildArch
27492803
Invoke-BuildStep Build-BuildTools $BuildArch
2804+
Invoke-BuildStep Build-Driver -Build $BuildArch
27502805
if ($IsCrossCompiling) {
27512806
Invoke-BuildStep Build-Compilers -Build $BuildArch
27522807
}

0 commit comments

Comments
 (0)