Skip to content

Commit 8fd43fb

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 f7d1c59 commit 8fd43fb

File tree

1 file changed

+99
-54
lines changed

1 file changed

+99
-54
lines changed

utils/build.ps1

Lines changed: 99 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ $ArchX64 = @{
230230
ToolchainInstallRoot = "$BinaryCache\x64\toolchains\$ProductVersion+Asserts";
231231
}
232232

233+
$WindowsX64 = $ArchX64
234+
233235
$ArchX86 = @{
234236
VSName = "x86";
235237
ShortName = "x86";
@@ -245,6 +247,8 @@ $ArchX86 = @{
245247
SwiftTestingInstallRoot = "$BinaryCache\x86\Windows.platform\Developer\Library\Testing-development";
246248
}
247249

250+
$WindowsX86 = $ArchX86
251+
248252
$ArchARM64 = @{
249253
VSName = "arm64";
250254
ShortName = "arm64";
@@ -261,6 +265,8 @@ $ArchARM64 = @{
261265
SwiftTestingInstallRoot = "$BinaryCache\arm64\Windows.platform\Developer\Library\Testing-development";
262266
}
263267

268+
$WindowsARM64 = $ArchARM64
269+
264270
$AndroidARM64 = @{
265271
AndroidArchABI = "arm64-v8a";
266272
BinaryDir = "bin64a";
@@ -429,7 +435,7 @@ function Get-TargetProjectBinaryCache($Arch, [TargetComponent]$Project) {
429435
}
430436

431437
enum HostComponent {
432-
Compilers = 5
438+
Compilers = 9
433439
FoundationMacros = 10
434440
TestingMacros
435441
System
@@ -463,6 +469,7 @@ function Get-HostProjectCMakeModules([HostComponent]$Project) {
463469

464470
enum BuildComponent {
465471
BuildTools
472+
Driver
466473
Compilers
467474
FoundationMacros
468475
TestingMacros
@@ -903,7 +910,7 @@ function Build-CMakeProject {
903910
[string[]] $UseMSVCCompilers = @(), # C,CXX
904911
[string[]] $UseBuiltCompilers = @(), # ASM,C,CXX,Swift
905912
[string[]] $UsePinnedCompilers = @(), # ASM,C,CXX,Swift
906-
[switch] $UseSwiftSwiftDriver = $false,
913+
[bool] $UseEarlySwiftDriver = $true,
907914
[switch] $AddAndroidCMakeEnv = $false,
908915
[string] $SwiftSDK = "",
909916
[hashtable] $Defines = @{}, # Values are either single strings or arrays of flags
@@ -941,14 +948,6 @@ function Build-CMakeProject {
941948
$env:SCCACHE_DIR = $Cache
942949
}
943950
}
944-
if ($UseSwiftSwiftDriver) {
945-
$env:SWIFT_DRIVER_SWIFT_FRONTEND_EXEC = ([IO.Path]::Combine($CompilersBinaryCache, "bin", "swift-frontend.exe"))
946-
}
947-
948-
# TODO(compnerd) workaround swiftc.exe symlink not existing.
949-
if ($UseSwiftSwiftDriver) {
950-
Copy-Item -Force ([IO.Path]::Combine($DriverBinaryCache, "bin", "swift-driver.exe")) ([IO.Path]::Combine($DriverBinaryCache, "bin", "swiftc.exe"))
951-
}
952951

953952
# Add additional defines (unless already present)
954953
$Defines = $Defines.Clone()
@@ -1080,9 +1079,7 @@ function Build-CMakeProject {
10801079
if ($UsePinnedCompilers.Contains("Swift") -Or $UseBuiltCompilers.Contains("Swift")) {
10811080
$SwiftArgs = @()
10821081

1083-
if ($UseSwiftSwiftDriver) {
1084-
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER ([IO.Path]::Combine($DriverBinaryCache, "bin", "swiftc.exe"))
1085-
} elseif ($UseBuiltCompilers.Contains("Swift")) {
1082+
if ($UseBuiltCompilers.Contains("Swift")) {
10861083
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER ([IO.Path]::Combine($CompilersBinaryCache, "bin", "swiftc.exe"))
10871084
} else {
10881085
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER (Join-Path -Path (Get-PinnedToolchainTool) -ChildPath "swiftc.exe")
@@ -1201,7 +1198,11 @@ function Build-CMakeProject {
12011198
}
12021199

12031200
if ($UseBuiltCompilers.Contains("Swift")) {
1204-
$env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMarkBinaryCache $Arch)\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path}"
1201+
$env:Path = if ($UseEarlySwiftDriver) {
1202+
"$(Get-PinnedToolchainRuntime);$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMarkBinaryCache $BuildArch)\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path}"
1203+
} else {
1204+
"$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMarkBinaryCache $BuildArch)\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path};$(Get-PinnedToolchainRuntime)"
1205+
}
12051206
} elseif ($UsePinnedCompilers.Contains("Swift")) {
12061207
$env:Path = "$(Get-PinnedToolchainRuntime);${env:Path}"
12071208
}
@@ -1459,6 +1460,7 @@ function Build-Compilers() {
14591460
SWIFT_BUILD_DYNAMIC_STDLIB = "YES";
14601461
SWIFT_BUILD_REMOTE_MIRROR = "YES";
14611462
SWIFT_NATIVE_SWIFT_TOOLS_PATH = "";
1463+
SWIFT_EARLY_SWIFT_DRIVER_BUILD = "$(Get-HostProjectBinaryCache Driver)\bin";
14621464
}
14631465

14641466
if ($TestClang) { $Targets += @("check-clang") }
@@ -1473,6 +1475,7 @@ function Build-Compilers() {
14731475
SWIFT_BUILD_DYNAMIC_STDLIB = "NO";
14741476
SWIFT_BUILD_REMOTE_MIRROR = "NO";
14751477
SWIFT_NATIVE_SWIFT_TOOLS_PATH = $BuildTools;
1478+
SWIFT_EARLY_SWIFT_DRIVER_BUILD = "$(Get-BuildProjectBinaryCache Driver)\$($BuildArch.LLVMTarget)\release";
14761479
}
14771480
}
14781481

@@ -1497,6 +1500,7 @@ function Build-Compilers() {
14971500
-UsePinnedCompilers Swift `
14981501
-BuildTargets $Targets `
14991502
-CacheScript $SourceCache\swift\cmake\caches\Windows-$($Arch.LLVMName).cmake `
1503+
-UseEarlySwiftDriver (-not ($TestClang -or $TestLLD -or $TestLLDB -or $TestLLVM -or $TestSwift)) `
15001504
-Defines ($TestingDefines + @{
15011505
CLANG_TABLEGEN = (Join-Path -Path $BuildTools -ChildPath "clang-tblgen.exe");
15021506
CLANG_TIDY_CONFUSABLE_CHARS_GEN = (Join-Path -Path $BuildTools -ChildPath "clang-tidy-confusable-chars-gen.exe");
@@ -1865,6 +1869,7 @@ function Build-Dispatch([Platform]$Platform, $Arch, [switch]$Test = $false) {
18651869
-Arch $Arch `
18661870
-Platform $Platform `
18671871
-UseBuiltCompilers C,CXX,Swift `
1872+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
18681873
-Defines @{
18691874
ENABLE_SWIFT = "YES";
18701875
}
@@ -1907,28 +1912,17 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
19071912
$ShortArch = $Arch.LLVMName
19081913

19091914
Isolate-EnvVars {
1910-
$SDKRoot = if ($Platform -eq "Windows") {
1911-
""
1912-
} else {
1913-
(Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot
1914-
}
1915-
1916-
$SDKRoot = if ($Platform -eq "Windows") {
1917-
""
1918-
} else {
1919-
(Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot
1920-
}
1921-
19221915
Build-CMakeProject `
19231916
-Src $SourceCache\swift-corelibs-foundation `
19241917
-Bin $FoundationBinaryCache `
19251918
-InstallTo "$($Arch.SDKInstallRoot)\usr" `
19261919
-Arch $Arch `
19271920
-Platform $Platform `
19281921
-UseBuiltCompilers ASM,C,CXX,Swift `
1929-
-SwiftSDK:$SDKRoot `
1922+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
19301923
-Defines (@{
19311924
ENABLE_TESTING = "NO";
1925+
CMAKE_Swift_COMPILER_USE_OLD_DRIVER = "YES";
19321926
FOUNDATION_BUILD_TOOLS = if ($Platform -eq "Windows") { "YES" } else { "NO" };
19331927
CMAKE_FIND_PACKAGE_PREFER_CONFIG = "YES";
19341928
CURL_DIR = "$LibraryRoot\curl-8.9.1\usr\lib\$Platform\$ShortArch\cmake\CURL";
@@ -1967,7 +1961,7 @@ function Build-FoundationMacros() {
19671961
Get-HostProjectBinaryCache FoundationMacros
19681962
}
19691963

1970-
$SwiftSDK = $null
1964+
$SwiftSDK = $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot)
19711965
if ($Build) {
19721966
$SwiftSDK = $BuildArch.SDKInstallRoot
19731967
}
@@ -1992,7 +1986,7 @@ function Build-FoundationMacros() {
19921986
-Arch $Arch `
19931987
-Platform $Platform `
19941988
-UseBuiltCompilers Swift `
1995-
-SwiftSDK:$SwiftSDK `
1989+
-SwiftSDK $SwiftSDK `
19961990
-BuildTargets:$Targets `
19971991
-Defines @{
19981992
SwiftSyntax_DIR = $SwiftSyntaxCMakeModules;
@@ -2029,6 +2023,7 @@ function Build-XCTest([Platform]$Platform, $Arch, [switch]$Test = $false) {
20292023
-Arch $Arch `
20302024
-Platform $Platform `
20312025
-UseBuiltCompilers Swift `
2026+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
20322027
-BuildTargets $Targets `
20332028
-Defines (@{
20342029
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
@@ -2058,6 +2053,7 @@ function Build-Testing([Platform]$Platform, $Arch, [switch]$Test = $false) {
20582053
-Arch $Arch `
20592054
-Platform $Platform `
20602055
-UseBuiltCompilers C,CXX,Swift `
2056+
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
20612057
-Defines (@{
20622058
BUILD_SHARED_LIBS = "YES";
20632059
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
@@ -2283,29 +2279,78 @@ function Build-ArgumentParser($Arch) {
22832279
}
22842280
}
22852281

2286-
function Build-Driver($Arch) {
2287-
Build-CMakeProject `
2288-
-Src $SourceCache\swift-driver `
2289-
-Bin (Get-HostProjectBinaryCache Driver) `
2290-
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
2291-
-Arch $Arch `
2292-
-Platform Windows `
2293-
-UseBuiltCompilers C,CXX,Swift `
2294-
-SwiftSDK (Get-HostSwiftSDK) `
2295-
-Defines @{
2296-
BUILD_SHARED_LIBS = "YES";
2297-
SwiftSystem_DIR = (Get-HostProjectCMakeModules System);
2298-
TSC_DIR = (Get-HostProjectCMakeModules ToolsSupportCore);
2299-
LLBuild_DIR = (Get-HostProjectCMakeModules LLBuild);
2300-
Yams_DIR = (Get-HostProjectCMakeModules Yams);
2301-
ArgumentParser_DIR = (Get-HostProjectCMakeModules ArgumentParser);
2302-
SQLite3_INCLUDE_DIR = "$LibraryRoot\sqlite-3.46.0\usr\include";
2303-
SQLite3_LIBRARY = "$LibraryRoot\sqlite-3.46.0\usr\lib\SQLite3.lib";
2304-
SWIFT_DRIVER_BUILD_TOOLS = "YES";
2305-
LLVM_DIR = "$(Get-HostProjectBinaryCache Compilers)\lib\cmake\llvm";
2306-
Clang_DIR = "$(Get-HostProjectBinaryCache Compilers)\lib\cmake\clang";
2307-
Swift_DIR = "$(Get-HostProjectBinaryCache Compilers)\tools\swift\lib\cmake\swift";
2282+
function Build-Driver() {
2283+
[CmdletBinding(PositionalBinding = $false)]
2284+
param
2285+
(
2286+
[Parameter(Position = 0, Mandatory = $true)]
2287+
[hashtable]$Arch,
2288+
[switch] $Build = $false
2289+
)
2290+
2291+
if ($Build) {
2292+
$Stopwatch = [Diagnostics.Stopwatch]::StartNew()
2293+
2294+
Isolate-EnvVars {
2295+
$env:SWIFTCI_USE_LOCAL_DEPS=1
2296+
$env:SDKROOT = (Get-PinnedToolchainSDK)
2297+
$env:Path = "$(Get-PinnedToolchainRuntime);$(Get-PinnedToolchainTool);${env:Path}"
2298+
2299+
$src = "$SourceCache\swift-driver"
2300+
$dst = (Get-BuildProjectBinaryCache Driver)
2301+
2302+
if ($ToBatch) {
2303+
Write-Output ""
2304+
Write-Output "echo Building '$src' to '$dst' for arch '$($Arch.LLVMName)'..."
2305+
} else {
2306+
Write-Host -ForegroundColor Cyan "[$([DateTime]::Now.ToString("yyyy-MM-dd HH:mm:ss"))] Building '$src' to '$dst' for arch '$($Arch.LLVMName)'..."
2307+
}
2308+
2309+
Invoke-Program `
2310+
"$(Get-PinnedToolchainTool)\swift.exe" build `
2311+
-c release `
2312+
--scratch-path $dst `
2313+
--package-path $src `
2314+
-Xlinker "$(Get-PinnedToolchainSDK)\usr\lib\swift\windows\$($BuildArch.LLVMName)\swiftCore.lib"
2315+
2316+
if (-not $ToBatch) {
2317+
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)"
2318+
Write-Host ""
2319+
}
2320+
2321+
if ($Summary) {
2322+
$TimingData.Add([PSCustomObject]@{
2323+
Arch = $BuildArch.LLVMName
2324+
Checkout = $src.Replace($SourceCache, '')
2325+
Platform = "Windows"
2326+
"Elapsed Time" = $Stopwatch.Elapsed.ToString()
2327+
})
2328+
}
23082329
}
2330+
} else {
2331+
Build-CMakeProject `
2332+
-Src $SourceCache\swift-driver `
2333+
-Bin (Get-HostProjectBinaryCache Driver) `
2334+
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
2335+
-Arch $Arch `
2336+
-Platform Windows `
2337+
-UseBuiltCompilers C,CXX,Swift `
2338+
-SwiftSDK (Get-HostSwiftSDK) `
2339+
-Defines @{
2340+
BUILD_SHARED_LIBS = "YES";
2341+
SwiftSystem_DIR = (Get-HostProjectCMakeModules System);
2342+
TSC_DIR = (Get-HostProjectCMakeModules ToolsSupportCore);
2343+
LLBuild_DIR = (Get-HostProjectCMakeModules LLBuild);
2344+
Yams_DIR = (Get-HostProjectCMakeModules Yams);
2345+
ArgumentParser_DIR = (Get-HostProjectCMakeModules ArgumentParser);
2346+
SQLite3_INCLUDE_DIR = "$LibraryRoot\sqlite-3.46.0\usr\include";
2347+
SQLite3_LIBRARY = "$LibraryRoot\sqlite-3.46.0\usr\lib\SQLite3.lib";
2348+
SWIFT_DRIVER_BUILD_TOOLS = "YES";
2349+
LLVM_DIR = "$(Get-HostProjectBinaryCache Compilers)\lib\cmake\llvm";
2350+
Clang_DIR = "$(Get-HostProjectBinaryCache Compilers)\lib\cmake\clang";
2351+
Swift_DIR = "$(Get-HostProjectBinaryCache Compilers)\tools\swift\lib\cmake\swift";
2352+
}
2353+
}
23092354
}
23102355

23112356
function Build-Crypto($Arch) {
@@ -2603,7 +2648,7 @@ function Build-TestingMacros() {
26032648
Get-HostProjectBinaryCache TestingMacros
26042649
}
26052650

2606-
$SwiftSDK = $null
2651+
$SwiftSDK = $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot)
26072652
if ($Build) {
26082653
$SwiftSDK = $BuildArch.SDKInstallRoot
26092654
}
@@ -2634,7 +2679,7 @@ function Build-TestingMacros() {
26342679
-Arch $Arch `
26352680
-Platform $Platform `
26362681
-UseBuiltCompilers Swift `
2637-
-SwiftSDK:$SwiftSDK `
2682+
-SwiftSDK $SwiftSDK `
26382683
-BuildTargets:$Targets `
26392684
-Defines @{
26402685
SwiftSyntax_DIR = $SwiftSyntaxCMakeModules;
@@ -2670,7 +2715,6 @@ function Build-Inspect() {
26702715
-InstallTo "$($HostArch.ToolchainInstallRoot)\usr" `
26712716
-Arch $HostArch `
26722717
-UseBuiltCompilers Swift `
2673-
-UseSwiftSwiftDriver `
26742718
-SwiftSDK $SDKRoot `
26752719
-Defines @{
26762720
CMAKE_Swift_FLAGS = @("-Xcc", "-I$SDKRoot\usr\include\swift\SwiftRemoteMirror");
@@ -2774,6 +2818,7 @@ if (-not $SkipBuild) {
27742818

27752819
Invoke-BuildStep Build-CMark $BuildArch
27762820
Invoke-BuildStep Build-BuildTools $BuildArch
2821+
Invoke-BuildStep Build-Driver -Build $BuildArch
27772822
if ($IsCrossCompiling) {
27782823
Invoke-BuildStep Build-XML2 Windows $BuildArch
27792824
Invoke-BuildStep Build-Compilers -Build $BuildArch

0 commit comments

Comments
 (0)