Skip to content

Commit cff4ea8

Browse files
compnerdSteelskin
authored andcommitted
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 23e3f5f commit cff4ea8

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
@@ -1182,7 +1189,7 @@ function Build-CMakeProject {
11821189
}
11831190

11841191
if ($UseBuiltCompilers.Contains("Swift")) {
1185-
$env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMarkBinaryCache $Arch)\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path}"
1192+
$env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMarkBinaryCache $BuildArch)\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path};$(Get-PinnedToolchainRuntime)"
11861193
} elseif ($UsePinnedCompilers.Contains("Swift")) {
11871194
$env:Path = "$(Get-PinnedToolchainRuntime);${env:Path}"
11881195
}
@@ -1492,6 +1499,7 @@ function Build-Compilers() {
14921499
Python3_ROOT_DIR = "$BinaryCache\Python$($Arch.CMakeName)-$PythonVersion\tools";
14931500
SWIFT_BUILD_SWIFT_SYNTAX = "YES";
14941501
SWIFT_CLANG_LOCATION = (Get-PinnedToolchainTool);
1502+
SWIFT_EARLY_SWIFT_DRIVER_BUILD = "$(Get-BuildProjectBinaryCache Driver)\$($BuildArch.LLVMTarget)\release";
14951503
SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY = "YES";
14961504
SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP = "YES";
14971505
SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING = "YES";
@@ -1834,6 +1842,7 @@ function Build-Dispatch([Platform]$Platform, $Arch, [switch]$Test = $false) {
18341842
-Arch $Arch `
18351843
-Platform $Platform `
18361844
-UseBuiltCompilers C,CXX,Swift `
1845+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
18371846
-Defines @{
18381847
ENABLE_SWIFT = "YES";
18391848
}
@@ -1876,28 +1885,17 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
18761885
$ShortArch = $Arch.LLVMName
18771886

18781887
Isolate-EnvVars {
1879-
$SDKRoot = if ($Platform -eq "Windows") {
1880-
""
1881-
} else {
1882-
(Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot
1883-
}
1884-
1885-
$SDKRoot = if ($Platform -eq "Windows") {
1886-
""
1887-
} else {
1888-
(Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot
1889-
}
1890-
18911888
Build-CMakeProject `
18921889
-Src $SourceCache\swift-corelibs-foundation `
18931890
-Bin $FoundationBinaryCache `
18941891
-InstallTo "$($Arch.SDKInstallRoot)\usr" `
18951892
-Arch $Arch `
18961893
-Platform $Platform `
18971894
-UseBuiltCompilers ASM,C,CXX,Swift `
1898-
-SwiftSDK:$SDKRoot `
1895+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
18991896
-Defines (@{
19001897
ENABLE_TESTING = "NO";
1898+
CMAKE_Swift_COMPILER_USE_OLD_DRIVER = "YES";
19011899
FOUNDATION_BUILD_TOOLS = if ($Platform -eq "Windows") { "YES" } else { "NO" };
19021900
CURL_DIR = "$LibraryRoot\curl-8.9.1\usr\lib\$Platform\$ShortArch\cmake\CURL";
19031901
LIBXML2_LIBRARY = if ($Platform -eq "Windows") {
@@ -1941,7 +1939,7 @@ function Build-FoundationMacros() {
19411939
Get-HostProjectBinaryCache FoundationMacros
19421940
}
19431941

1944-
$SwiftSDK = $null
1942+
$SwiftSDK = $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot)
19451943
if ($Build) {
19461944
$SwiftSDK = $BuildArch.SDKInstallRoot
19471945
}
@@ -1966,7 +1964,7 @@ function Build-FoundationMacros() {
19661964
-Arch $Arch `
19671965
-Platform $Platform `
19681966
-UseBuiltCompilers Swift `
1969-
-SwiftSDK:$SwiftSDK `
1967+
-SwiftSDK $SwiftSDK `
19701968
-BuildTargets:$Targets `
19711969
-Defines @{
19721970
SwiftSyntax_DIR = $SwiftSyntaxCMakeModules;
@@ -2003,6 +2001,7 @@ function Build-XCTest([Platform]$Platform, $Arch, [switch]$Test = $false) {
20032001
-Arch $Arch `
20042002
-Platform $Platform `
20052003
-UseBuiltCompilers Swift `
2004+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
20062005
-BuildTargets $Targets `
20072006
-Defines (@{
20082007
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
@@ -2032,6 +2031,7 @@ function Build-Testing([Platform]$Platform, $Arch, [switch]$Test = $false) {
20322031
-Arch $Arch `
20332032
-Platform $Platform `
20342033
-UseBuiltCompilers C,CXX,Swift `
2034+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
20352035
-Defines (@{
20362036
BUILD_SHARED_LIBS = "YES";
20372037
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
@@ -2257,29 +2257,79 @@ function Build-ArgumentParser($Arch) {
22572257
}
22582258
}
22592259

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

22852335
function Build-Crypto($Arch) {
@@ -2577,7 +2627,7 @@ function Build-TestingMacros() {
25772627
Get-HostProjectBinaryCache TestingMacros
25782628
}
25792629

2580-
$SwiftSDK = $null
2630+
$SwiftSDK = $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot)
25812631
if ($Build) {
25822632
$SwiftSDK = $BuildArch.SDKInstallRoot
25832633
}
@@ -2608,7 +2658,7 @@ function Build-TestingMacros() {
26082658
-Arch $Arch `
26092659
-Platform $Platform `
26102660
-UseBuiltCompilers Swift `
2611-
-SwiftSDK:$SwiftSDK `
2661+
-SwiftSDK $SwiftSDK `
26122662
-BuildTargets:$Targets `
26132663
-Defines @{
26142664
SwiftSyntax_DIR = $SwiftSyntaxCMakeModules;
@@ -2747,6 +2797,7 @@ Fetch-Dependencies
27472797
if (-not $SkipBuild) {
27482798
Invoke-BuildStep Build-CMark $BuildArch
27492799
Invoke-BuildStep Build-BuildTools $BuildArch
2800+
Invoke-BuildStep Build-Driver -Build $BuildArch
27502801
if ($IsCrossCompiling) {
27512802
Invoke-BuildStep Build-Compilers -Build $BuildArch
27522803
}

0 commit comments

Comments
 (0)