Skip to content

Commit 0083a3c

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 0083a3c

File tree

1 file changed

+86
-36
lines changed

1 file changed

+86
-36
lines changed

utils/build.ps1

Lines changed: 86 additions & 36 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
@@ -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";
@@ -1836,28 +1844,17 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
18361844
$ShortArch = $Arch.LLVMName
18371845

18381846
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-
18511847
Build-CMakeProject `
18521848
-Src $SourceCache\swift-corelibs-foundation `
18531849
-Bin $FoundationBinaryCache `
18541850
-InstallTo "$($Arch.SDKInstallRoot)\usr" `
18551851
-Arch $Arch `
18561852
-Platform $Platform `
18571853
-UseBuiltCompilers ASM,C,CXX,Swift `
1858-
-SwiftSDK:$SDKRoot `
1854+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
18591855
-Defines (@{
18601856
ENABLE_TESTING = "NO";
1857+
CMAKE_Swift_COMPILER_USE_OLD_DRIVER = "YES";
18611858
FOUNDATION_BUILD_TOOLS = if ($Platform -eq "Windows") { "YES" } else { "NO" };
18621859
CURL_DIR = "$LibraryRoot\curl-8.9.1\usr\lib\$Platform\$ShortArch\cmake\CURL";
18631860
LIBXML2_LIBRARY = if ($Platform -eq "Windows") {
@@ -1963,6 +1960,7 @@ function Build-XCTest([Platform]$Platform, $Arch, [switch]$Test = $false) {
19631960
-Arch $Arch `
19641961
-Platform $Platform `
19651962
-UseBuiltCompilers Swift `
1963+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
19661964
-BuildTargets $Targets `
19671965
-Defines (@{
19681966
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
@@ -1992,6 +1990,7 @@ function Build-Testing([Platform]$Platform, $Arch, [switch]$Test = $false) {
19921990
-Arch $Arch `
19931991
-Platform $Platform `
19941992
-UseBuiltCompilers C,CXX,Swift `
1993+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
19951994
-Defines (@{
19961995
BUILD_SHARED_LIBS = "YES";
19971996
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
@@ -2217,29 +2216,79 @@ function Build-ArgumentParser($Arch) {
22172216
}
22182217
}
22192218

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

22452294
function Build-Crypto($Arch) {
@@ -2593,6 +2642,7 @@ Fetch-Dependencies
25932642
if (-not $SkipBuild) {
25942643
Invoke-BuildStep Build-CMark $BuildArch
25952644
Invoke-BuildStep Build-BuildTools $BuildArch
2645+
Invoke-BuildStep Build-Driver -Build $BuildArch
25962646
if ($IsCrossCompiling) {
25972647
Invoke-BuildStep Build-Compilers -Build $BuildArch
25982648
}

0 commit comments

Comments
 (0)