Skip to content

Commit a27b1e9

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 a27b1e9

File tree

1 file changed

+98
-54
lines changed

1 file changed

+98
-54
lines changed

utils/build.ps1

Lines changed: 98 additions & 54 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,7 +881,7 @@ function Build-CMakeProject {
874881
[string[]] $UseMSVCCompilers = @(), # C,CXX
875882
[string[]] $UseBuiltCompilers = @(), # ASM,C,CXX,Swift
876883
[string[]] $UsePinnedCompilers = @(), # ASM,C,CXX,Swift
877-
[switch] $UseSwiftSwiftDriver = $false,
884+
[bool] $UseEarlySwiftDriver = $true,
878885
[switch] $AddAndroidCMakeEnv = $false,
879886
[string] $SwiftSDK = "",
880887
[hashtable] $Defines = @{}, # Values are either single strings or arrays of flags
@@ -912,14 +919,6 @@ function Build-CMakeProject {
912919
$env:SCCACHE_DIR = $Cache
913920
}
914921
}
915-
if ($UseSwiftSwiftDriver) {
916-
$env:SWIFT_DRIVER_SWIFT_FRONTEND_EXEC = ([IO.Path]::Combine($CompilersBinaryCache, "bin", "swift-frontend.exe"))
917-
}
918-
919-
# TODO(compnerd) workaround swiftc.exe symlink not existing.
920-
if ($UseSwiftSwiftDriver) {
921-
Copy-Item -Force ([IO.Path]::Combine($DriverBinaryCache, "bin", "swift-driver.exe")) ([IO.Path]::Combine($DriverBinaryCache, "bin", "swiftc.exe"))
922-
}
923922

924923
# Add additional defines (unless already present)
925924
$Defines = $Defines.Clone()
@@ -1062,9 +1061,7 @@ function Build-CMakeProject {
10621061
if ($UsePinnedCompilers.Contains("Swift") -Or $UseBuiltCompilers.Contains("Swift")) {
10631062
$SwiftArgs = @()
10641063

1065-
if ($UseSwiftSwiftDriver) {
1066-
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER ([IO.Path]::Combine($DriverBinaryCache, "bin", "swiftc.exe"))
1067-
} elseif ($UseBuiltCompilers.Contains("Swift")) {
1064+
if ($UseBuiltCompilers.Contains("Swift")) {
10681065
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER ([IO.Path]::Combine($CompilersBinaryCache, "bin", "swiftc.exe"))
10691066
} else {
10701067
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER (Join-Path -Path (Get-PinnedToolchainTool) -ChildPath "swiftc.exe")
@@ -1183,7 +1180,11 @@ function Build-CMakeProject {
11831180
}
11841181

11851182
if ($UseBuiltCompilers.Contains("Swift")) {
1186-
$env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMarkBinaryCache $Arch)\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path}"
1183+
$env:Path = if ($UseEarlySwiftDriver) {
1184+
"$(Get-PinnedToolchainRuntime);$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMarkBinaryCache $BuildArch)\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path}"
1185+
} else {
1186+
"$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMarkBinaryCache $BuildArch)\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path};$(Get-PinnedToolchainRuntime)"
1187+
}
11871188
} elseif ($UsePinnedCompilers.Contains("Swift")) {
11881189
$env:Path = "$(Get-PinnedToolchainRuntime);${env:Path}"
11891190
}
@@ -1493,6 +1494,7 @@ function Build-Compilers() {
14931494
Python3_ROOT_DIR = "$BinaryCache\Python$($Arch.CMakeName)-$PythonVersion\tools";
14941495
SWIFT_BUILD_SWIFT_SYNTAX = "YES";
14951496
SWIFT_CLANG_LOCATION = (Get-PinnedToolchainTool);
1497+
SWIFT_EARLY_SWIFT_DRIVER_BUILD = "$(Get-BuildProjectBinaryCache Driver)\$($BuildArch.LLVMTarget)\release";
14961498
SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY = "YES";
14971499
SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP = "YES";
14981500
SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING = "YES";
@@ -1835,6 +1837,7 @@ function Build-Dispatch([Platform]$Platform, $Arch, [switch]$Test = $false) {
18351837
-Arch $Arch `
18361838
-Platform $Platform `
18371839
-UseBuiltCompilers C,CXX,Swift `
1840+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
18381841
-Defines @{
18391842
ENABLE_SWIFT = "YES";
18401843
}
@@ -1877,28 +1880,17 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
18771880
$ShortArch = $Arch.LLVMName
18781881

18791882
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-
18921883
Build-CMakeProject `
18931884
-Src $SourceCache\swift-corelibs-foundation `
18941885
-Bin $FoundationBinaryCache `
18951886
-InstallTo "$($Arch.SDKInstallRoot)\usr" `
18961887
-Arch $Arch `
18971888
-Platform $Platform `
18981889
-UseBuiltCompilers ASM,C,CXX,Swift `
1899-
-SwiftSDK:$SDKRoot `
1890+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
19001891
-Defines (@{
19011892
ENABLE_TESTING = "NO";
1893+
CMAKE_Swift_COMPILER_USE_OLD_DRIVER = "YES";
19021894
FOUNDATION_BUILD_TOOLS = if ($Platform -eq "Windows") { "YES" } else { "NO" };
19031895
CURL_DIR = "$LibraryRoot\curl-8.9.1\usr\lib\$Platform\$ShortArch\cmake\CURL";
19041896
LIBXML2_LIBRARY = if ($Platform -eq "Windows") {
@@ -1942,7 +1934,7 @@ function Build-FoundationMacros() {
19421934
Get-HostProjectBinaryCache FoundationMacros
19431935
}
19441936

1945-
$SwiftSDK = $null
1937+
$SwiftSDK = $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot)
19461938
if ($Build) {
19471939
$SwiftSDK = $BuildArch.SDKInstallRoot
19481940
}
@@ -1967,7 +1959,7 @@ function Build-FoundationMacros() {
19671959
-Arch $Arch `
19681960
-Platform $Platform `
19691961
-UseBuiltCompilers Swift `
1970-
-SwiftSDK:$SwiftSDK `
1962+
-SwiftSDK $SwiftSDK `
19711963
-BuildTargets:$Targets `
19721964
-Defines @{
19731965
SwiftSyntax_DIR = $SwiftSyntaxCMakeModules;
@@ -2004,6 +1996,7 @@ function Build-XCTest([Platform]$Platform, $Arch, [switch]$Test = $false) {
20041996
-Arch $Arch `
20051997
-Platform $Platform `
20061998
-UseBuiltCompilers Swift `
1999+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
20072000
-BuildTargets $Targets `
20082001
-Defines (@{
20092002
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
@@ -2033,6 +2026,7 @@ function Build-Testing([Platform]$Platform, $Arch, [switch]$Test = $false) {
20332026
-Arch $Arch `
20342027
-Platform $Platform `
20352028
-UseBuiltCompilers C,CXX,Swift `
2029+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
20362030
-Defines (@{
20372031
BUILD_SHARED_LIBS = "YES";
20382032
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
@@ -2258,29 +2252,79 @@ function Build-ArgumentParser($Arch) {
22582252
}
22592253
}
22602254

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

22862330
function Build-Crypto($Arch) {
@@ -2578,7 +2622,7 @@ function Build-TestingMacros() {
25782622
Get-HostProjectBinaryCache TestingMacros
25792623
}
25802624

2581-
$SwiftSDK = $null
2625+
$SwiftSDK = $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot)
25822626
if ($Build) {
25832627
$SwiftSDK = $BuildArch.SDKInstallRoot
25842628
}
@@ -2609,7 +2653,7 @@ function Build-TestingMacros() {
26092653
-Arch $Arch `
26102654
-Platform $Platform `
26112655
-UseBuiltCompilers Swift `
2612-
-SwiftSDK:$SwiftSDK `
2656+
-SwiftSDK $SwiftSDK `
26132657
-BuildTargets:$Targets `
26142658
-Defines @{
26152659
SwiftSyntax_DIR = $SwiftSyntaxCMakeModules;
@@ -2645,7 +2689,6 @@ function Build-Inspect() {
26452689
-InstallTo "$($HostArch.ToolchainInstallRoot)\usr" `
26462690
-Arch $HostArch `
26472691
-UseBuiltCompilers Swift `
2648-
-UseSwiftSwiftDriver `
26492692
-SwiftSDK $SDKRoot `
26502693
-Defines @{
26512694
CMAKE_Swift_FLAGS = @("-Xcc", "-I$SDKRoot\usr\include\swift\SwiftRemoteMirror");
@@ -2747,6 +2790,7 @@ Fetch-Dependencies
27472790
if (-not $SkipBuild) {
27482791
Invoke-BuildStep Build-CMark $BuildArch
27492792
Invoke-BuildStep Build-BuildTools $BuildArch
2793+
Invoke-BuildStep Build-Driver -Build $BuildArch
27502794
if ($IsCrossCompiling) {
27512795
Invoke-BuildStep Build-Compilers -Build $BuildArch
27522796
}

0 commit comments

Comments
 (0)