Skip to content

Commit f629b58

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 ed42300 commit f629b58

File tree

1 file changed

+91
-40
lines changed

1 file changed

+91
-40
lines changed

utils/build.ps1

Lines changed: 91 additions & 40 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
@@ -1486,6 +1493,7 @@ function Build-Compilers() {
14861493
Python3_ROOT_DIR = "$BinaryCache\Python$($Arch.CMakeName)-$PythonVersion\tools";
14871494
SWIFT_BUILD_SWIFT_SYNTAX = "YES";
14881495
SWIFT_CLANG_LOCATION = (Get-PinnedToolchainTool);
1496+
SWIFT_EARLY_SWIFT_DRIVER_BUILD = "$(Get-BuildProjectBinaryCache Driver)\$($BuildArch.LLVMTarget)\release";
14891497
SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY = "YES";
14901498
SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP = "YES";
14911499
SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING = "YES";
@@ -1828,6 +1836,7 @@ function Build-Dispatch([Platform]$Platform, $Arch, [switch]$Test = $false) {
18281836
-Arch $Arch `
18291837
-Platform $Platform `
18301838
-UseBuiltCompilers C,CXX,Swift `
1839+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
18311840
-Defines @{
18321841
ENABLE_SWIFT = "YES";
18331842
}
@@ -1870,28 +1879,17 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
18701879
$ShortArch = $Arch.LLVMName
18711880

18721881
Isolate-EnvVars {
1873-
$SDKRoot = if ($Platform -eq "Windows") {
1874-
""
1875-
} else {
1876-
(Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot
1877-
}
1878-
1879-
$SDKRoot = if ($Platform -eq "Windows") {
1880-
""
1881-
} else {
1882-
(Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot
1883-
}
1884-
18851882
Build-CMakeProject `
18861883
-Src $SourceCache\swift-corelibs-foundation `
18871884
-Bin $FoundationBinaryCache `
18881885
-InstallTo "$($Arch.SDKInstallRoot)\usr" `
18891886
-Arch $Arch `
18901887
-Platform $Platform `
18911888
-UseBuiltCompilers ASM,C,CXX,Swift `
1892-
-SwiftSDK:$SDKRoot `
1889+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
18931890
-Defines (@{
18941891
ENABLE_TESTING = "NO";
1892+
CMAKE_Swift_COMPILER_USE_OLD_DRIVER = "YES";
18951893
FOUNDATION_BUILD_TOOLS = if ($Platform -eq "Windows") { "YES" } else { "NO" };
18961894
CURL_DIR = "$LibraryRoot\curl-8.9.1\usr\lib\$Platform\$ShortArch\cmake\CURL";
18971895
LIBXML2_LIBRARY = if ($Platform -eq "Windows") {
@@ -1935,7 +1933,7 @@ function Build-FoundationMacros() {
19351933
Get-HostProjectBinaryCache FoundationMacros
19361934
}
19371935

1938-
$SwiftSDK = $null
1936+
$SwiftSDK = $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot)
19391937
if ($Build) {
19401938
$SwiftSDK = $BuildArch.SDKInstallRoot
19411939
}
@@ -1960,7 +1958,7 @@ function Build-FoundationMacros() {
19601958
-Arch $Arch `
19611959
-Platform $Platform `
19621960
-UseBuiltCompilers Swift `
1963-
-SwiftSDK:$SwiftSDK `
1961+
-SwiftSDK $SwiftSDK `
19641962
-BuildTargets:$Targets `
19651963
-Defines @{
19661964
SwiftSyntax_DIR = $SwiftSyntaxCMakeModules;
@@ -1997,6 +1995,7 @@ function Build-XCTest([Platform]$Platform, $Arch, [switch]$Test = $false) {
19971995
-Arch $Arch `
19981996
-Platform $Platform `
19991997
-UseBuiltCompilers Swift `
1998+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
20001999
-BuildTargets $Targets `
20012000
-Defines (@{
20022001
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
@@ -2026,6 +2025,7 @@ function Build-Testing([Platform]$Platform, $Arch, [switch]$Test = $false) {
20262025
-Arch $Arch `
20272026
-Platform $Platform `
20282027
-UseBuiltCompilers C,CXX,Swift `
2028+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
20292029
-Defines (@{
20302030
BUILD_SHARED_LIBS = "YES";
20312031
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
@@ -2251,29 +2251,79 @@ function Build-ArgumentParser($Arch) {
22512251
}
22522252
}
22532253

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

22792329
function Build-Crypto($Arch) {
@@ -2571,7 +2621,7 @@ function Build-TestingMacros() {
25712621
Get-HostProjectBinaryCache TestingMacros
25722622
}
25732623

2574-
$SwiftSDK = $null
2624+
$SwiftSDK = $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot)
25752625
if ($Build) {
25762626
$SwiftSDK = $BuildArch.SDKInstallRoot
25772627
}
@@ -2602,7 +2652,7 @@ function Build-TestingMacros() {
26022652
-Arch $Arch `
26032653
-Platform $Platform `
26042654
-UseBuiltCompilers Swift `
2605-
-SwiftSDK:$SwiftSDK `
2655+
-SwiftSDK $SwiftSDK `
26062656
-BuildTargets:$Targets `
26072657
-Defines @{
26082658
SwiftSyntax_DIR = $SwiftSyntaxCMakeModules;
@@ -2742,6 +2792,7 @@ Fetch-Dependencies
27422792
if (-not $SkipBuild) {
27432793
Invoke-BuildStep Build-CMark $BuildArch
27442794
Invoke-BuildStep Build-BuildTools $BuildArch
2795+
Invoke-BuildStep Build-Driver -Build $BuildArch
27452796
if ($IsCrossCompiling) {
27462797
Invoke-BuildStep Build-Compilers -Build $BuildArch
27472798
}

0 commit comments

Comments
 (0)