Skip to content

Commit d4b28a4

Browse files
authored
Merge pull request #83383 from compnerd/required-sdk
build.ps1: clean up `-SwiftSDK` handling
2 parents da55089 + eb7e7b1 commit d4b28a4

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

utils/build.ps1

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ function Build-CMakeProject {
12711271
[string[]] $UsePinnedCompilers = @(),
12721272
[switch] $AddAndroidCMakeEnv = $false,
12731273
[switch] $UseGNUDriver = $false,
1274-
[string] $SwiftSDK = "",
1274+
[string] $SwiftSDK = $null,
12751275
[hashtable] $Defines = @{}, # Values are either single strings or arrays of flags
12761276
[string[]] $BuildTargets = @()
12771277
)
@@ -1448,21 +1448,12 @@ function Build-CMakeProject {
14481448
# TODO(compnerd): remove this once we have the early swift-driver
14491449
Add-KeyValueIfNew $Defines CMAKE_Swift_COMPILER_USE_OLD_DRIVER "YES"
14501450

1451-
$SwiftFlags = if ($UsePinnedCompilers.Contains("Swift")) {
1452-
@("-sdk", (Get-PinnedToolchainSDK))
1453-
} elseif ($SwiftSDK) {
1451+
[string[]] $SwiftFlags = @();
1452+
1453+
$SwiftFlags += if ($SwiftSDK) {
14541454
@("-sdk", $SwiftSDK)
14551455
} else {
1456-
$RuntimeBinaryCache = Get-ProjectBinaryCache $Platform Runtime
1457-
$SwiftResourceDir = "${RuntimeBinaryCache}\lib\swift"
1458-
1459-
@(
1460-
"-vfsoverlay", "$RuntimeBinaryCache\stdlib\windows-vfs-overlay.yaml",
1461-
"-strict-implicit-module-context",
1462-
"-Xcc", "-Xclang", "-Xcc", "-fbuiltin-headers-in-system-modules",
1463-
"-resource-dir", $SwiftResourceDir,
1464-
"-L", "$SwiftResourceDir\$($Platform.OS.ToString().ToLowerInvariant())"
1465-
)
1456+
@()
14661457
}
14671458

14681459
$SwiftFlags += if ($DebugInfo) {
@@ -1566,22 +1557,12 @@ function Build-CMakeProject {
15661557
# TODO(compnerd) remove this once we have the early swift-driver
15671558
Add-KeyValueIfNew $Defines CMAKE_Swift_COMPILER_USE_OLD_DRIVER "YES"
15681559

1569-
$SwiftFlags = if ($USePinnedCompilers.Contains("Swift")) {
1570-
@("-sdk", (Get-PinnedToolchainSDK))
1571-
} elseif ($SwiftSDK) {
1572-
@(
1573-
"-sdk", $SwiftSDK,
1574-
"-sysroot", $AndroidSysroot
1575-
)
1560+
[string[]] $SwiftFlags = @()
1561+
1562+
$SwiftFlags += if ($SwiftSDK) {
1563+
@("-sdk", $SwiftSDK, "-sysroot", $AndroidSysroot)
15761564
} else {
1577-
$RuntimeBinaryCache = Get-ProjectBinaryCache $Platform Runtime
1578-
$SwiftResourceDir = "${RuntimeBinaryCache}\lib\swift"
1579-
1580-
@(
1581-
"-sdk", $AndroidSysroot,
1582-
"-resource-dir", $SwiftResourceDir,
1583-
"-L", "$SwiftResourceDir\$($Platform.OS.ToString().ToLowerInvariant())"
1584-
)
1565+
@()
15851566
}
15861567

15871568
$SwiftFlags += @(
@@ -1992,6 +1973,7 @@ function Build-Compilers([Hashtable] $Platform, [string] $Variant) {
19921973
-Platform $Platform `
19931974
-UseMSVCCompilers C,CXX `
19941975
-UsePinnedCompilers Swift `
1976+
-SwiftSDK (Get-PinnedToolchainSDK) `
19951977
-BuildTargets @("install-distribution") `
19961978
-CacheScript $SourceCache\swift\cmake\caches\Windows-$($Platform.Architecture.LLVMName).cmake `
19971979
-Defines (Get-CompilersDefines $Platform $Variant)
@@ -2053,6 +2035,7 @@ function Test-Compilers([Hashtable] $Platform, [string] $Variant, [switch] $Test
20532035
-Platform $Platform `
20542036
-UseMSVCCompilers C,CXX `
20552037
-UsePinnedCompilers Swift `
2038+
-SwiftSDK (Get-PinnedToolchainSDK) `
20562039
-BuildTargets $Targets `
20572040
-CacheScript $SourceCache\swift\cmake\caches\Windows-$($Platform.Architecture.LLVMName).cmake `
20582041
-Defines $TestingDefines
@@ -2388,8 +2371,9 @@ function Build-Runtime([Hashtable] $Platform) {
23882371
-Bin (Get-ProjectBinaryCache $Platform Runtime) `
23892372
-InstallTo "$(Get-SwiftSDK $Platform.OS)\usr" `
23902373
-Platform $Platform `
2391-
-CacheScript $SourceCache\swift\cmake\caches\Runtime-$($Platform.OS.ToString())-$($Platform.Architecture.LLVMName).cmake `
23922374
-UseBuiltCompilers C,CXX,Swift `
2375+
-SwiftSDK $null `
2376+
-CacheScript $SourceCache\swift\cmake\caches\Runtime-$($Platform.OS.ToString())-$($Platform.Architecture.LLVMName).cmake `
23932377
-Defines ($PlatformDefines + @{
23942378
CMAKE_Swift_COMPILER_TARGET = (Get-ModuleTriple $Platform);
23952379
CMAKE_Swift_COMPILER_WORKS = "YES";
@@ -2432,6 +2416,7 @@ function Test-Runtime([Hashtable] $Platform) {
24322416
-Bin (Get-ProjectBinaryCache $Platform Runtime) `
24332417
-Platform $Platform `
24342418
-UseBuiltCompilers C,CXX,Swift `
2419+
-SwiftSDK $null `
24352420
-BuildTargets check-swift-validation-only_non_executable `
24362421
-Defines @{
24372422
SWIFT_INCLUDE_TESTS = "YES";
@@ -2506,6 +2491,7 @@ function Build-ExperimentalRuntime([Hashtable] $Platform, [switch] $Static = $fa
25062491
-InstallTo "${SDKRoot}\usr" `
25072492
-Platform $Platform `
25082493
-UseBuiltCompilers C,CXX,Swift `
2494+
-SwiftSDK $null `
25092495
-UseGNUDriver `
25102496
-Defines @{
25112497
BUILD_SHARED_LIBS = if ($Static) { "NO" } else { "YES" };
@@ -2531,6 +2517,7 @@ function Build-ExperimentalRuntime([Hashtable] $Platform, [switch] $Static = $fa
25312517
-InstallTo "${SDKRoot}\usr" `
25322518
-Platform $Platform `
25332519
-UseBuiltCompilers C,CXX,Swift `
2520+
-SwiftSDK $null `
25342521
-UseGNUDriver `
25352522
-Defines @{
25362523
BUILD_SHARED_LIBS = if ($Static) { "NO" } else { "YES" };
@@ -2547,6 +2534,7 @@ function Build-ExperimentalRuntime([Hashtable] $Platform, [switch] $Static = $fa
25472534
-InstallTo "${SDKRoot}\usr" `
25482535
-Platform $Platform `
25492536
-UseBuiltCompilers C,Swift `
2537+
-SwiftSDK $null `
25502538
-UseGNUDriver `
25512539
-Defines @{
25522540
BUILD_SHARED_LIBS = if ($Static) { "NO" } else { "YES" };
@@ -2563,6 +2551,7 @@ function Build-ExperimentalRuntime([Hashtable] $Platform, [switch] $Static = $fa
25632551
-InstallTo "${SDKRoot}\usr" `
25642552
-Platform $Platform `
25652553
-UseBuiltCompilers C,Swift `
2554+
-SwiftSDK $null `
25662555
-UseGNUDriver `
25672556
-Defines @{
25682557
BUILD_SHARED_LIBS = if ($Static) { "NO" } else { "YES" };
@@ -2580,6 +2569,7 @@ function Build-ExperimentalRuntime([Hashtable] $Platform, [switch] $Static = $fa
25802569
-InstallTo "${SDKRoot}\usr" `
25812570
-Platform $Platform `
25822571
-UseBuiltCompilers C,CXX,Swift `
2572+
-SwiftSDK $null `
25832573
-UseGNUDriver `
25842574
-Defines @{
25852575
BUILD_SHARED_LIBS = if ($Static) { "NO" } else { "YES" };
@@ -2598,6 +2588,7 @@ function Build-ExperimentalRuntime([Hashtable] $Platform, [switch] $Static = $fa
25982588
-InstallTo "${SDKRoot}\usr" `
25992589
-Platform $Platform `
26002590
-UseBuiltCompilers CXX,Swift `
2591+
-SwiftSDK $null `
26012592
-UseGNUDriver `
26022593
-Defines @{
26032594
BUILD_SHARED_LIBS = if ($Static) { "NO" } else { "YES" };
@@ -2675,8 +2666,8 @@ function Build-Dispatch([Hashtable] $Platform) {
26752666
-Bin (Get-ProjectBinaryCache $Platform Dispatch) `
26762667
-InstallTo "$(Get-SwiftSDK $Platform.OS)\usr" `
26772668
-Platform $Platform `
2678-
-SwiftSDK (Get-SwiftSDK $Platform.OS) `
26792669
-UseBuiltCompilers C,CXX,Swift `
2670+
-SwiftSDK (Get-SwiftSDK $Platform.OS) `
26802671
-Defines @{
26812672
ENABLE_SWIFT = "YES";
26822673
}
@@ -2690,9 +2681,9 @@ function Test-Dispatch {
26902681
-Src $SourceCache\swift-corelibs-libdispatch `
26912682
-Bin (Get-ProjectBinaryCache $BuildPlatform Dispatch) `
26922683
-Platform $BuildPlatform `
2684+
-UseBuiltCompilers C,CXX,Swift `
26932685
-SwiftSDK (Get-SwiftSDK $BuildPlatform.OS) `
26942686
-BuildTargets default,ExperimentalTest `
2695-
-UseBuiltCompilers C,CXX,Swift `
26962687
-Defines @{
26972688
ENABLE_SWIFT = "YES";
26982689
}
@@ -2836,14 +2827,19 @@ function Test-XCTest {
28362827
Invoke-IsolatingEnvVars {
28372828
$env:Path = "$(Get-ProjectBinaryCache $BuildPlatform XCTest);$(Get-ProjectBinaryCache $BuildPlatform DynamicFoundation)\bin;$(Get-ProjectBinaryCache $BuildPlatform Dispatch);$(Get-ProjectBinaryCache $BuildPlatform Runtime)\bin;${env:Path};$UnixToolsBinDir"
28382829

2830+
$RuntimeBinaryCache = Get-ProjectBinaryCache $BuildPlatform Runtime
2831+
$SwiftRuntimeDirectory = "${RuntimeBinaryCache}\lib\swift"
2832+
28392833
Build-CMakeProject `
28402834
-Src $SourceCache\swift-corelibs-xctest `
28412835
-Bin (Get-ProjectBinaryCache $BuildPlatform XCTest) `
28422836
-Platform $BuildPlatform `
28432837
-UseBuiltCompilers Swift `
2838+
-SwiftSDK $null `
28442839
-BuildTargets default,check-xctest `
28452840
-Defines @{
28462841
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
2842+
CMAKE_Swift_FLAGS = @("-resource-dir", $SwiftRuntimeDirectory, "-vfsoverlay", "${RuntimeBinaryCache}\stdlib\windows-vfs-overlay.yaml");
28472843
ENABLE_TESTING = "YES";
28482844
dispatch_DIR = $(Get-ProjectCMakeModules $BuildPlatform Dispatch);
28492845
Foundation_DIR = $(Get-ProjectCMakeModules $BuildPlatform DynamicFoundation);

0 commit comments

Comments
 (0)