Skip to content

Commit a20b568

Browse files
authored
Merge pull request #80157 from compnerd/helper
utils: extract `Build-SDK` helper
2 parents e7aa152 + 78a2057 commit a20b568

File tree

1 file changed

+88
-63
lines changed

1 file changed

+88
-63
lines changed

utils/build.ps1

+88-63
Original file line numberDiff line numberDiff line change
@@ -2290,31 +2290,49 @@ function Build-ExperimentalRuntime {
22902290
}
22912291
}
22922292

2293-
function Write-SDKSettingsPlist([Hashtable] $Platform) {
2293+
function Write-SDKSettingsPlist([OS] $OS) {
22942294
$SDKSettings = @{
22952295
DefaultProperties = @{
22962296
}
22972297
}
2298-
if ($Platform.OS -eq [OS]::Windows) {
2298+
if ($OS -eq [OS]::Windows) {
22992299
$SDKSettings.DefaultProperties.DEFAULT_USE_RUNTIME = "MD"
23002300
}
2301-
Write-PList -Settings $SDKSettings -Path "$(Get-SwiftSDK $Platform.OS)\SDKSettings.plist"
2301+
Write-PList -Settings $SDKSettings -Path "$(Get-SwiftSDK $OS)\SDKSettings.plist"
23022302

23032303
$SDKSettings = @{
2304-
CanonicalName = "$($Platform.Triple)"
2305-
DisplayName = "$($Platform.OS.ToString())"
2304+
CanonicalName = $OS.ToString()
2305+
DisplayName = $OS.ToString()
23062306
IsBaseSDK = "NO"
23072307
Version = "${ProductVersion}"
23082308
VersionMap = @{}
23092309
DefaultProperties = @{
2310-
PLATFORM_NAME = "$($Platform.OS.ToString())"
2310+
PLATFORM_NAME = $OS.ToString()
23112311
DEFAULT_COMPILER = "${ToolchainIdentifier}"
23122312
}
2313+
SupportedTargets = @{
2314+
$OS.ToString() = @{
2315+
PlatformFamilyDisplayName = $OS.ToString()
2316+
PlatformFamilyName = $OS.ToString()
2317+
}
2318+
}
23132319
}
2314-
if ($Platform.OS -eq [OS]::Windows) {
2315-
$SDKSettings.DefaultProperties.DEFAULT_USE_RUNTIME = "MD"
2320+
switch ($OS) {
2321+
Windows {
2322+
$SDKSettings.DefaultProperties.DEFAULT_USE_RUNTIME = "MD"
2323+
$SDKSettings.SupportedTargets.Windows.LLVMTargetVendor = "unknown"
2324+
$SDKSettings.SupportedTargets.Windows.LLVMTargetSys = "windows"
2325+
$SDKSettings.SupportedTargets.Windows.LLVMTargetTripleEnvironment = "msvc"
2326+
$SDKSettings.SupportedTargets.Windows.Archs = $WindowsSDKPlatforms | ForEach-Object { $_.Architecture.LLVMName } | Sort-Object
2327+
}
2328+
Android {
2329+
$SDKSettings.SupportedTargets.Android.LLVMTargetVendor = "unknown"
2330+
$SDKSettings.SupportedTargets.Android.LLVMTargetSys = "linux"
2331+
$SDKSettings.SupportedTargets.Android.LLVMTargetTripleEnvironment = "android${AndroidAPILevel}"
2332+
$SDKSettings.SupportedTargets.Android.Archs = $AndroidSDKPlatforms | ForEach-Object { $_.Architecture.LLVMName } | Sort-Object
2333+
}
23162334
}
2317-
$SDKSettings | ConvertTo-JSON | Out-FIle -FilePath "$(Get-SwiftSDK $Platform.OS)\SDKSettings.json"
2335+
$SDKSettings | ConvertTo-JSON -Depth 4 | Out-FIle -FilePath "$(Get-SwiftSDK $OS)\SDKSettings.json"
23182336
}
23192337

23202338
function Build-Dispatch([Hashtable] $Platform) {
@@ -2501,18 +2519,18 @@ function Test-Testing {
25012519
throw "testing Testing is not supported"
25022520
}
25032521

2504-
function Write-PlatformInfoPlist([Hashtable] $Platform) {
2522+
function Write-PlatformInfoPlist([OS] $OS) {
25052523
$Settings = @{
25062524
DefaultProperties = @{
25072525
SWIFT_TESTING_VERSION = "$ProductVersion"
25082526
XCTEST_VERSION = "$ProductVersion"
25092527
}
25102528
}
2511-
if ($Platform.OS -eq [OS]::Windows) {
2529+
if ($OS -eq [OS]::Windows) {
25122530
$Settings.DefaultProperties.SWIFTC_FLAGS = @( "-use-ld=lld" )
25132531
}
25142532

2515-
Write-PList -Settings $Settings -Path "$(Get-PlatformRoot $Platform.OS)\Info.plist"
2533+
Write-PList -Settings $Settings -Path "$(Get-PlatformRoot $OS)\Info.plist"
25162534
}
25172535

25182536
# Copies files installed by CMake from the arch-specific platform root,
@@ -2532,12 +2550,44 @@ function Install-Platform([Hashtable[]] $Platforms, [OS] $OS) {
25322550
$PlatformResources = "$(Get-SwiftSDK $Platform.OS)\usr\lib\swift\$($Platform.OS.ToString().ToLowerInvariant())"
25332551
Get-ChildItem -Recurse "$PlatformResources\$($Platform.Architecture.LLVMName)" | ForEach-Object {
25342552
if (".swiftmodule", ".swiftdoc", ".swiftinterface" -contains $_.Extension) {
2553+
Write-Host -BackgroundColor DarkRed -ForegroundColor White "$($_.FullName) is not in a thick module layout"
25352554
Copy-File $_.FullName "$PlatformResources\$($_.BaseName).swiftmodule\$(Get-ModuleTriple $Platform)$($_.Extension)"
25362555
}
25372556
}
25382557
}
25392558
}
25402559

2560+
function Build-SDK([Hashtable] $Platform, [switch] $IncludeMacros = $false) {
2561+
if ($IncludeDS2) {
2562+
Invoke-BuildStep Build-DS2 $Platform
2563+
}
2564+
2565+
# Third Party Dependencies
2566+
Invoke-BuildStep Build-ZLib $Platform
2567+
Invoke-BuildStep Build-XML2 $Platform
2568+
Invoke-BuildStep Build-CURL $Platform
2569+
Invoke-BuildStep Build-LLVM $Platform
2570+
2571+
# Libraries
2572+
Invoke-BuildStep Build-Runtime $Platform
2573+
Invoke-BuildStep Build-Dispatch $Platform
2574+
if ($IncludeMacros) {
2575+
Invoke-BuildStep Build-FoundationMacros $Platform
2576+
Invoke-BuildStep Build-TestingMacros $Platform
2577+
}
2578+
Invoke-BuildStep Build-Foundation $Platform
2579+
Invoke-BuildStep Build-Sanitizers $Platform
2580+
Invoke-BuildStep Build-XCTest $Platform
2581+
Invoke-BuildStep Build-Testing $Platform
2582+
}
2583+
2584+
function Build-ExperimentalSDK([Hashtable] $Platform) {
2585+
# TODO(compnerd) we currently build the experimental SDK with just the static
2586+
# variant. We should aim to build both dynamic and static variants.
2587+
Invoke-BuildStep Build-ExperimentalRuntime $Platform -Static
2588+
Invoke-BuildStep Build-Foundation $Platform -Static
2589+
}
2590+
25412591
function Build-SQLite([Hashtable] $Platform) {
25422592
Build-CMakeProject `
25432593
-Src $SourceCache\swift-toolchain-sqlite `
@@ -3167,69 +3217,44 @@ if (-not $SkipBuild) {
31673217
Invoke-BuildStep Build-XML2 $HostPlatform
31683218
Invoke-BuildStep Build-Compilers $HostPlatform
31693219

3220+
Invoke-BuildStep Build-SDK $BuildPlatform -IncludeMacros
3221+
31703222
foreach ($Platform in $WindowsSDKPlatforms) {
3171-
Invoke-BuildStep Build-ZLib $Platform
3172-
Invoke-BuildStep Build-XML2 $Platform
3173-
Invoke-BuildStep Build-CURL $Platform
3174-
Invoke-BuildStep Build-LLVM $Platform
3175-
3176-
# Build platform: SDK, Redist and XCTest
3177-
Invoke-BuildStep Build-Runtime $Platform
3178-
Invoke-BuildStep Build-Dispatch $Platform
3179-
# FIXME(compnerd) ensure that the _build_ is the first arch and don't rebuild on each arch
3180-
if ($Platform -eq $BuildPlatform) {
3181-
Invoke-BuildStep Build-FoundationMacros $BuildPlatform
3182-
Invoke-BuildStep Build-TestingMacros $BuildPlatform
3183-
}
3184-
Invoke-BuildStep Build-Foundation $Platform
3185-
Invoke-BuildStep Build-Sanitizers $Platform
3186-
Invoke-BuildStep Build-XCTest $Platform
3187-
Invoke-BuildStep Build-Testing $Platform
3188-
Invoke-BuildStep Write-SDKSettingsPlist $Platform
3189-
3190-
Invoke-BuildStep Build-ExperimentalRuntime $Platform -Static
3191-
Invoke-BuildStep Build-Foundation $Platform -Static
3192-
3193-
Copy-File "$(Get-SwiftSDK Windows)\usr\lib\swift\windows\*.lib" "$(Get-SwiftSDK Windows)\usr\lib\swift\windows\$($Platform.Architecture.LLVMName)\"
3223+
Invoke-BuildStep Build-SDK $Platform
3224+
Invoke-BuildStep Build-ExperimentalSDK $Platform
3225+
3226+
Get-ChildItem "$(Get-SwiftSDK Windows)\usr\lib\swift\windows" -Filter "*.lib" -File -ErrorAction Ignore | ForEach-Object {
3227+
Write-Host -BackgroundColor DarkRed -ForegroundColor White "$($_.FullName) is not nested in an architecture directory"
3228+
Move-Item $_.FullName "$(Get-SwiftSDK Windows)\usr\lib\swift\windows\$($Platform.Architecture.LLVMName)\" | Out-Null
3229+
}
3230+
31943231
if ($Platform -eq $HostPlatform) {
3195-
Copy-Directory "$(Get-SwiftSDK Windows)\usr\bin" "$([IO.Path]::Combine((Get-InstallDir $HostPlatform), "Runtimes", $ProductVersion))\usr"
3232+
Copy-Directory "$(Get-SwiftSDK Windows)\usr\bin" "$([IO.Path]::Combine((Get-InstallDir $Platform), "Runtimes", $ProductVersion))\usr"
31963233
}
31973234
}
31983235
Install-Platform $WindowsSDKPlatforms Windows
3199-
Invoke-BuildStep Write-PlatformInfoPlist $HostPlatform
3236+
Write-PlatformInfoPlist Windows
3237+
Write-SDKSettingsPlist Windows
32003238

32013239
if ($Android) {
32023240
foreach ($Platform in $AndroidSDKPlatforms) {
3203-
if ($IncludeDS2) {
3204-
Invoke-BuildStep Build-DS2 $Platform
3205-
}
3206-
Invoke-BuildStep Build-ZLib $Platform
3207-
Invoke-BuildStep Build-XML2 $Platform
3208-
Invoke-BuildStep Build-CURL $Platform
3209-
Invoke-BuildStep Build-LLVM $Platform
3210-
3211-
# Build platform: SDK, Redist and XCTest
3212-
Invoke-BuildStep Build-Runtime $Platform
3213-
Invoke-BuildStep Build-Dispatch $Platform
3214-
Invoke-BuildStep Build-Foundation $Platform
3215-
Invoke-BuildStep Build-Sanitizers $Platform
3216-
Invoke-BuildStep Build-XCTest $Platform
3217-
Invoke-BuildStep Build-Testing $Platform
3218-
3219-
# Android swift-inspect only supports 64-bit platforms.
3220-
if ($Platform.Architecture.ABI -in @("arm64-v8a", "x86_64")) {
3221-
Invoke-BuildStep Build-Inspect $Platform
3241+
Invoke-BuildStep Build-SDK $Platform
3242+
Invoke-BuildStep Build-ExperimentalSDK $Platform
3243+
3244+
Get-ChildItem "$(Get-SwiftSDK Android)\usr\lib\swift\android" -File | Where-Object { $_.Name -match ".a$|.so$" } | ForEach-Object {
3245+
Write-Host -BackgroundColor DarkRed -ForegroundColor White "$($_.FullName) is not nested in an architecture directory"
3246+
Move-Item $_.FullName "$(Get-SwiftSDK Android)\usr\lib\swift\android\$($Platform.Architecture.LLVMName)\" | Out-Null
32223247
}
3223-
Invoke-BuildStep Write-SDKSettingsPlist $Platform
3248+
}
32243249

3225-
Invoke-BuildStep Build-ExperimentalRuntime $Platform -Static
3226-
Invoke-BuildStep Build-Foundation $Platform -Static
3250+
Install-Platform $AndroidSDKPlatforms Android
3251+
Write-PlatformInfoPlist Android
3252+
Write-SDKSettingsPlist Android
32273253

3228-
Move-Item "$(Get-SwiftSDK Android)\usr\lib\swift\android\*.a" "$(Get-SwiftSDK Android)\usr\lib\swift\android\$($Platform.Architecture.LLVMName)\"
3229-
Move-Item "$(Get-SwiftSDK Android)\usr\lib\swift\android\*.so" "$(Get-SwiftSDK Android)\usr\lib\swift\android\$($Platform.Architecture.LLVMName)\"
3254+
# Android swift-inspect only supports 64-bit platforms.
3255+
$AndroidSDKPlatforms | Where-Object { @("arm64-v8a", "x86_64") -contains $_.Architecture.ABI } | ForEach-Object {
3256+
Invoke-BuildStep Build-Inspect $_
32303257
}
3231-
Install-Platform $AndroidSDKPlatforms Android
3232-
Invoke-BuildStep Write-PlatformInfoPlist $Platform
32333258
}
32343259

32353260
# Build Macros for distribution

0 commit comments

Comments
 (0)