Skip to content

Commit 3bb70be

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 d12ab3c commit 3bb70be

File tree

1 file changed

+92
-41
lines changed

1 file changed

+92
-41
lines changed

utils/build.ps1

Lines changed: 92 additions & 41 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
@@ -466,6 +472,7 @@ function Get-HostProjectCMakeModules([HostComponent]$Project) {
466472

467473
enum BuildComponent {
468474
BuildTools
475+
Driver
469476
Compilers
470477
FoundationMacros
471478
TestingMacros
@@ -1175,7 +1182,7 @@ function Build-CMakeProject {
11751182
}
11761183

11771184
if ($UseBuiltCompilers.Contains("Swift")) {
1178-
$env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$($BuildArch.BinaryCache)\cmark-gfm-0.29.0.gfm.13\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path}"
1185+
$env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$($BuildArch.BinaryCache)\cmark-gfm-0.29.0.gfm.13\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;$(Get-PinnedToolchainRuntime);${env:Path}"
11791186
} elseif ($UsePinnedCompilers.Contains("Swift")) {
11801187
$env:Path = "$(Get-PinnedToolchainRuntime);${env:Path}"
11811188
}
@@ -1454,6 +1461,7 @@ function Build-Compilers() {
14541461
Python3_ROOT_DIR = "$BinaryCache\Python$($Arch.CMakeName)-$PythonVersion\tools";
14551462
SWIFT_BUILD_SWIFT_SYNTAX = "YES";
14561463
SWIFT_CLANG_LOCATION = (Get-PinnedToolchainTool);
1464+
SWIFT_EARLY_SWIFT_DRIVER_BUILD = "$(Get-BuildProjectBinaryCache Driver)\$($BuildArch.LLVMTarget)\release";
14571465
SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY = "YES";
14581466
SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP = "YES";
14591467
SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING = "YES";
@@ -1794,6 +1802,7 @@ function Build-Dispatch([Platform]$Platform, $Arch, [switch]$Test = $false) {
17941802
-Arch $Arch `
17951803
-Platform $Platform `
17961804
-UseBuiltCompilers C,CXX,Swift `
1805+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
17971806
-Defines @{
17981807
ENABLE_SWIFT = "YES";
17991808
}
@@ -1836,28 +1845,17 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
18361845
$ShortArch = $Arch.LLVMName
18371846

18381847
Isolate-EnvVars {
1839-
$SDKRoot = if ($Platform -eq "Windows") {
1840-
""
1841-
} else {
1842-
(Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot
1843-
}
1844-
1845-
$SDKRoot = if ($Platform -eq "Windows") {
1846-
""
1847-
} else {
1848-
(Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot
1849-
}
1850-
18511848
Build-CMakeProject `
18521849
-Src $SourceCache\swift-corelibs-foundation `
18531850
-Bin $FoundationBinaryCache `
18541851
-InstallTo "$($Arch.SDKInstallRoot)\usr" `
18551852
-Arch $Arch `
18561853
-Platform $Platform `
18571854
-UseBuiltCompilers ASM,C,CXX,Swift `
1858-
-SwiftSDK:$SDKRoot `
1855+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
18591856
-Defines (@{
18601857
ENABLE_TESTING = "NO";
1858+
CMAKE_Swift_COMPILER_USE_OLD_DRIVER = "YES";
18611859
FOUNDATION_BUILD_TOOLS = if ($Platform -eq "Windows") { "YES" } else { "NO" };
18621860
CURL_DIR = "$LibraryRoot\curl-8.9.1\usr\lib\$Platform\$ShortArch\cmake\CURL";
18631861
LIBXML2_LIBRARY = if ($Platform -eq "Windows") {
@@ -1901,7 +1899,7 @@ function Build-FoundationMacros() {
19011899
Get-HostProjectBinaryCache FoundationMacros
19021900
}
19031901

1904-
$SwiftSDK = $null
1902+
$SwiftSDK = $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot)
19051903
if ($Build) {
19061904
$SwiftSDK = $BuildArch.SDKInstallRoot
19071905
}
@@ -1926,7 +1924,7 @@ function Build-FoundationMacros() {
19261924
-Arch $Arch `
19271925
-Platform $Platform `
19281926
-UseBuiltCompilers Swift `
1929-
-SwiftSDK:$SwiftSDK `
1927+
-SwiftSDK $SwiftSDK `
19301928
-BuildTargets:$Targets `
19311929
-Defines @{
19321930
SwiftSyntax_DIR = $SwiftSyntaxCMakeModules;
@@ -1963,6 +1961,7 @@ function Build-XCTest([Platform]$Platform, $Arch, [switch]$Test = $false) {
19631961
-Arch $Arch `
19641962
-Platform $Platform `
19651963
-UseBuiltCompilers Swift `
1964+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
19661965
-BuildTargets $Targets `
19671966
-Defines (@{
19681967
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
@@ -1992,6 +1991,7 @@ function Build-Testing([Platform]$Platform, $Arch, [switch]$Test = $false) {
19921991
-Arch $Arch `
19931992
-Platform $Platform `
19941993
-UseBuiltCompilers C,CXX,Swift `
1994+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
19951995
-Defines (@{
19961996
BUILD_SHARED_LIBS = "YES";
19971997
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
@@ -2217,29 +2217,79 @@ function Build-ArgumentParser($Arch) {
22172217
}
22182218
}
22192219

2220-
function Build-Driver($Arch) {
2221-
Build-CMakeProject `
2222-
-Src $SourceCache\swift-driver `
2223-
-Bin (Get-HostProjectBinaryCache Driver) `
2224-
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
2225-
-Arch $Arch `
2226-
-Platform Windows `
2227-
-UseBuiltCompilers C,CXX,Swift `
2228-
-SwiftSDK (Get-HostSwiftSDK) `
2229-
-Defines @{
2230-
BUILD_SHARED_LIBS = "YES";
2231-
SwiftSystem_DIR = (Get-HostProjectCMakeModules System);
2232-
TSC_DIR = (Get-HostProjectCMakeModules ToolsSupportCore);
2233-
LLBuild_DIR = (Get-HostProjectCMakeModules LLBuild);
2234-
Yams_DIR = (Get-HostProjectCMakeModules Yams);
2235-
ArgumentParser_DIR = (Get-HostProjectCMakeModules ArgumentParser);
2236-
SQLite3_INCLUDE_DIR = "$LibraryRoot\sqlite-3.46.0\usr\include";
2237-
SQLite3_LIBRARY = "$LibraryRoot\sqlite-3.46.0\usr\lib\SQLite3.lib";
2238-
SWIFT_DRIVER_BUILD_TOOLS = "YES";
2239-
LLVM_DIR = "$(Get-HostProjectBinaryCache Compilers)\lib\cmake\llvm";
2240-
Clang_DIR = "$(Get-HostProjectBinaryCache Compilers)\lib\cmake\clang";
2241-
Swift_DIR = "$(Get-HostProjectBinaryCache Compilers)\tools\swift\lib\cmake\swift";
2220+
function Build-Driver() {
2221+
[CmdletBinding(PositionalBinding = $false)]
2222+
param
2223+
(
2224+
[Parameter(Position = 0, Mandatory = $true)]
2225+
[hashtable]$Arch,
2226+
[switch] $Build = $false
2227+
)
2228+
2229+
if ($Build) {
2230+
$Stopwatch = [Diagnostics.Stopwatch]::StartNew()
2231+
2232+
Isolate-EnvVars {
2233+
$env:SWIFTCI_USE_LOCAL_DEPS=1
2234+
$env:SDKROOT = (Get-PinnedToolchainSDK)
2235+
$env:Path = "$(Get-PinnedToolchainRuntime);$(Get-PinnedToolchainTool);${env:Path}"
2236+
2237+
$src = "$SourceCache\swift-driver"
2238+
$dst = (Get-BuildProjectBinaryCache Driver)
2239+
2240+
if ($ToBatch) {
2241+
Write-Output ""
2242+
Write-Output "echo Building '$src' to '$dst' for arch '$($Arch.LLVMName)'..."
2243+
} else {
2244+
Write-Host -ForegroundColor Cyan "[$([DateTime]::Now.ToString("yyyy-MM-dd HH:mm:ss"))] Building '$src' to '$dst' for arch '$($Arch.LLVMName)'..."
2245+
}
2246+
2247+
Invoke-Program `
2248+
"$(Get-PinnedToolchainTool)\swift.exe" build `
2249+
-c release `
2250+
--scratch-path $dst `
2251+
--package-path $src `
2252+
-Xcc -Xclang -Xcc -fno-split-cold-code `
2253+
-Xlinker "$(Get-PinnedToolchainSDK)\usr\lib\swift\windows\$($BuildArch.LLVMName)\swiftCore.lib"
2254+
2255+
if (-not $ToBatch) {
2256+
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)"
2257+
Write-Host ""
2258+
}
2259+
2260+
if ($Summary) {
2261+
$TimingData.Add([PSCustomObject]@{
2262+
Arch = $BuildArch.LLVMName
2263+
Checkout = $src.Replace($SourceCache, '')
2264+
Platform = "Windows"
2265+
"Elapsed Time" = $Stopwatch.Elapsed.ToString()
2266+
})
2267+
}
22422268
}
2269+
} else {
2270+
Build-CMakeProject `
2271+
-Src $SourceCache\swift-driver `
2272+
-Bin (Get-HostProjectBinaryCache Driver) `
2273+
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
2274+
-Arch $Arch `
2275+
-Platform Windows `
2276+
-UseBuiltCompilers C,CXX,Swift `
2277+
-SwiftSDK (Get-HostSwiftSDK) `
2278+
-Defines @{
2279+
BUILD_SHARED_LIBS = "YES";
2280+
SwiftSystem_DIR = (Get-HostProjectCMakeModules System);
2281+
TSC_DIR = (Get-HostProjectCMakeModules ToolsSupportCore);
2282+
LLBuild_DIR = (Get-HostProjectCMakeModules LLBuild);
2283+
Yams_DIR = (Get-HostProjectCMakeModules Yams);
2284+
ArgumentParser_DIR = (Get-HostProjectCMakeModules ArgumentParser);
2285+
SQLite3_INCLUDE_DIR = "$LibraryRoot\sqlite-3.46.0\usr\include";
2286+
SQLite3_LIBRARY = "$LibraryRoot\sqlite-3.46.0\usr\lib\SQLite3.lib";
2287+
SWIFT_DRIVER_BUILD_TOOLS = "YES";
2288+
LLVM_DIR = "$(Get-HostProjectBinaryCache Compilers)\lib\cmake\llvm";
2289+
Clang_DIR = "$(Get-HostProjectBinaryCache Compilers)\lib\cmake\clang";
2290+
Swift_DIR = "$(Get-HostProjectBinaryCache Compilers)\tools\swift\lib\cmake\swift";
2291+
}
2292+
}
22432293
}
22442294

22452295
function Build-Crypto($Arch) {
@@ -2424,7 +2474,7 @@ function Build-TestingMacros() {
24242474
Get-HostProjectBinaryCache TestingMacros
24252475
}
24262476

2427-
$SwiftSDK = $null
2477+
$SwiftSDK = $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot)
24282478
if ($Build) {
24292479
$SwiftSDK = $BuildArch.SDKInstallRoot
24302480
}
@@ -2455,7 +2505,7 @@ function Build-TestingMacros() {
24552505
-Arch $Arch `
24562506
-Platform $Platform `
24572507
-UseBuiltCompilers Swift `
2458-
-SwiftSDK:$SwiftSDK `
2508+
-SwiftSDK $SwiftSDK `
24592509
-BuildTargets:$Targets `
24602510
-Defines @{
24612511
SwiftSyntax_DIR = $SwiftSyntaxCMakeModules;
@@ -2593,6 +2643,7 @@ Fetch-Dependencies
25932643
if (-not $SkipBuild) {
25942644
Invoke-BuildStep Build-CMark $BuildArch
25952645
Invoke-BuildStep Build-BuildTools $BuildArch
2646+
Invoke-BuildStep Build-Driver -Build $BuildArch
25962647
if ($IsCrossCompiling) {
25972648
Invoke-BuildStep Build-Compilers -Build $BuildArch
25982649
}

0 commit comments

Comments
 (0)