Skip to content

Commit 9c44b8d

Browse files
committed
utils: extract Build-SDK helper
This creates a helper for building the SDK for a given OS/Architecture. The building of the SDK should be uniform and this ensures that we can maintain that uniformity. This also highlights any structural changes that are being adjusted manually. The desire is to bring this to zero by gaining control over the install rules.
1 parent 7648bce commit 9c44b8d

File tree

1 file changed

+88
-63
lines changed

1 file changed

+88
-63
lines changed

utils/build.ps1

Lines changed: 88 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,31 +2305,49 @@ function Build-ExperimentalRuntime {
23052305
}
23062306
}
23072307

2308-
function Write-SDKSettingsPlist([Hashtable] $Platform) {
2308+
function Write-SDKSettingsPlist([OS] $OS) {
23092309
$SDKSettings = @{
23102310
DefaultProperties = @{
23112311
}
23122312
}
2313-
if ($Platform.OS -eq [OS]::Windows) {
2313+
if ($OS -eq [OS]::Windows) {
23142314
$SDKSettings.DefaultProperties.DEFAULT_USE_RUNTIME = "MD"
23152315
}
2316-
Write-PList -Settings $SDKSettings -Path "$(Get-SwiftSDK $Platform.OS)\SDKSettings.plist"
2316+
Write-PList -Settings $SDKSettings -Path "$(Get-SwiftSDK $OS)\SDKSettings.plist"
23172317

23182318
$SDKSettings = @{
2319-
CanonicalName = "$($Platform.Triple)"
2320-
DisplayName = "$($Platform.OS.ToString())"
2319+
CanonicalName = $OS.ToString()
2320+
DisplayName = $OS.ToString()
23212321
IsBaseSDK = "NO"
23222322
Version = "${ProductVersion}"
23232323
VersionMap = @{}
23242324
DefaultProperties = @{
2325-
PLATFORM_NAME = "$($Platform.OS.ToString())"
2325+
PLATFORM_NAME = $OS.ToString()
23262326
DEFAULT_COMPILER = "${ToolchainIdentifier}"
23272327
}
2328+
SupportedTargets = @{
2329+
$OS.ToString() = @{
2330+
PlatformFamilyDisplayName = $OS.ToString()
2331+
PlatformFamilyName = $OS.ToString()
2332+
}
2333+
}
23282334
}
2329-
if ($Platform.OS -eq [OS]::Windows) {
2330-
$SDKSettings.DefaultProperties.DEFAULT_USE_RUNTIME = "MD"
2335+
switch ($OS) {
2336+
Windows {
2337+
$SDKSettings.DefaultProperties.DEFAULT_USE_RUNTIME = "MD"
2338+
$SDKSettings.SupportedTargets.Windows.LLVMTargetVendor = "unknown"
2339+
$SDKSettings.SupportedTargets.Windows.LLVMTargetSys = "windows"
2340+
$SDKSettings.SupportedTargets.Windows.LLVMTargetTripleEnvironment = "msvc"
2341+
$SDKSettings.SupportedTargets.Windows.Archs = $WindowsSDKPlatforms | ForEach-Object { $_.Architecture.LLVMName } | Sort-Object
2342+
}
2343+
Android {
2344+
$SDKSettings.SupportedTargets.Android.LLVMTargetVendor = "unknown"
2345+
$SDKSettings.SupportedTargets.Android.LLVMTargetSys = "linux"
2346+
$SDKSettings.SupportedTargets.Android.LLVMTargetTripleEnvironment = "android${AndroidAPILevel}"
2347+
$SDKSettings.SupportedTargets.Android.Archs = $AndroidSDKPlatforms | ForEach-Object { $_.Architecture.LLVMName } | Sort-Object
2348+
}
23312349
}
2332-
$SDKSettings | ConvertTo-JSON | Out-FIle -FilePath "$(Get-SwiftSDK $Platform.OS)\SDKSettings.json"
2350+
$SDKSettings | ConvertTo-JSON -Depth 4 | Out-FIle -FilePath "$(Get-SwiftSDK $OS)\SDKSettings.json"
23332351
}
23342352

23352353
function Build-Dispatch([Hashtable] $Platform) {
@@ -2516,18 +2534,18 @@ function Test-Testing {
25162534
throw "testing Testing is not supported"
25172535
}
25182536

2519-
function Write-PlatformInfoPlist([Hashtable] $Platform) {
2537+
function Write-PlatformInfoPlist([OS] $OS) {
25202538
$Settings = @{
25212539
DefaultProperties = @{
25222540
SWIFT_TESTING_VERSION = "$ProductVersion"
25232541
XCTEST_VERSION = "$ProductVersion"
25242542
}
25252543
}
2526-
if ($Platform.OS -eq [OS]::Windows) {
2544+
if ($OS -eq [OS]::Windows) {
25272545
$Settings.DefaultProperties.SWIFTC_FLAGS = @( "-use-ld=lld" )
25282546
}
25292547

2530-
Write-PList -Settings $Settings -Path "$(Get-PlatformRoot $Platform.OS)\Info.plist"
2548+
Write-PList -Settings $Settings -Path "$(Get-PlatformRoot $OS)\Info.plist"
25312549
}
25322550

25332551
# Copies files installed by CMake from the arch-specific platform root,
@@ -2547,12 +2565,44 @@ function Install-Platform([Hashtable[]] $Platforms, [OS] $OS) {
25472565
$PlatformResources = "$(Get-SwiftSDK $Platform.OS)\usr\lib\swift\$($Platform.OS.ToString().ToLowerInvariant())"
25482566
Get-ChildItem -Recurse "$PlatformResources\$($Platform.Architecture.LLVMName)" | ForEach-Object {
25492567
if (".swiftmodule", ".swiftdoc", ".swiftinterface" -contains $_.Extension) {
2568+
Write-Host -BackgroundColor DarkRed -ForegroundColor White "$($_.FullName) is not in a thick module layout"
25502569
Copy-File $_.FullName "$PlatformResources\$($_.BaseName).swiftmodule\$(Get-ModuleTriple $Platform)$($_.Extension)"
25512570
}
25522571
}
25532572
}
25542573
}
25552574

2575+
function Build-SDK([Hashtable] $Platform, [switch] $IncludeMacros = $false) {
2576+
if ($IncludeDS2) {
2577+
Invoke-BuildStep Build-DS2 $Platform
2578+
}
2579+
2580+
# Third Party Dependencies
2581+
Invoke-BuildStep Build-ZLib $Platform
2582+
Invoke-BuildStep Build-XML2 $Platform
2583+
Invoke-BuildStep Build-CURL $Platform
2584+
Invoke-BuildStep Build-LLVM $Platform
2585+
2586+
# Libraries
2587+
Invoke-BuildStep Build-Runtime $Platform
2588+
Invoke-BuildStep Build-Dispatch $Platform
2589+
if ($IncludeMacros) {
2590+
Invoke-BuildStep Build-FoundationMacros $Platform
2591+
Invoke-BuildStep Build-TestingMacros $Platform
2592+
}
2593+
Invoke-BuildStep Build-Foundation $Platform
2594+
Invoke-BuildStep Build-Sanitizers $Platform
2595+
Invoke-BuildStep Build-XCTest $Platform
2596+
Invoke-BuildStep Build-Testing $Platform
2597+
}
2598+
2599+
function Build-ExperimentalSDK([Hashtable] $Platform) {
2600+
# TODO(compnerd) we currently build the experimental SDK with just the static
2601+
# variant. We should aim to build both dynamic and static variants.
2602+
Invoke-BuildStep Build-ExperimentalRuntime $Platform -Static
2603+
Invoke-BuildStep Build-Foundation $Platform -Static
2604+
}
2605+
25562606
function Build-SQLite([Hashtable] $Platform) {
25572607
Build-CMakeProject `
25582608
-Src $SourceCache\swift-toolchain-sqlite `
@@ -3182,69 +3232,44 @@ if (-not $SkipBuild) {
31823232
Invoke-BuildStep Build-XML2 $HostPlatform
31833233
Invoke-BuildStep Build-Compilers $HostPlatform
31843234

3235+
Invoke-BuildStep Build-SDK $BuildPlatform -IncludeMacros
3236+
31853237
foreach ($Platform in $WindowsSDKPlatforms) {
3186-
Invoke-BuildStep Build-ZLib $Platform
3187-
Invoke-BuildStep Build-XML2 $Platform
3188-
Invoke-BuildStep Build-CURL $Platform
3189-
Invoke-BuildStep Build-LLVM $Platform
3190-
3191-
# Build platform: SDK, Redist and XCTest
3192-
Invoke-BuildStep Build-Runtime $Platform
3193-
Invoke-BuildStep Build-Dispatch $Platform
3194-
# FIXME(compnerd) ensure that the _build_ is the first arch and don't rebuild on each arch
3195-
if ($Platform -eq $BuildPlatform) {
3196-
Invoke-BuildStep Build-FoundationMacros $BuildPlatform
3197-
Invoke-BuildStep Build-TestingMacros $BuildPlatform
3198-
}
3199-
Invoke-BuildStep Build-Foundation $Platform
3200-
Invoke-BuildStep Build-Sanitizers $Platform
3201-
Invoke-BuildStep Build-XCTest $Platform
3202-
Invoke-BuildStep Build-Testing $Platform
3203-
Invoke-BuildStep Write-SDKSettingsPlist $Platform
3204-
3205-
Invoke-BuildStep Build-ExperimentalRuntime $Platform -Static
3206-
Invoke-BuildStep Build-Foundation $Platform -Static
3207-
3208-
Copy-File "$(Get-SwiftSDK Windows)\usr\lib\swift\windows\*.lib" "$(Get-SwiftSDK Windows)\usr\lib\swift\windows\$($Platform.Architecture.LLVMName)\"
3238+
Invoke-BuildStep Build-SDK $Platform
3239+
Invoke-BuildStep Build-ExperimentalSDK $Platform
3240+
3241+
Get-ChildItem "$(Get-SwiftSDK Windows)\usr\lib\swift\windows" -Filter "*.lib" -File -ErrorAction Ignore | ForEach-Object {
3242+
Write-Host -BackgroundColor DarkRed -ForegroundColor White "$($_.FullName) is not nested in an architecture directory"
3243+
Move-Item $_.FullName "$(Get-SwiftSDK Windows)\usr\lib\swift\windows\$($Platform.Architecture.LLVMName)\" | Out-Null
3244+
}
3245+
32093246
if ($Platform -eq $HostPlatform) {
3210-
Copy-Directory "$(Get-SwiftSDK Windows)\usr\bin" "$([IO.Path]::Combine((Get-InstallDir $HostPlatform), "Runtimes", $ProductVersion))\usr"
3247+
Copy-Directory "$(Get-SwiftSDK Windows)\usr\bin" "$([IO.Path]::Combine((Get-InstallDir $Platform), "Runtimes", $ProductVersion))\usr"
32113248
}
32123249
}
32133250
Install-Platform $WindowsSDKPlatforms Windows
3214-
Invoke-BuildStep Write-PlatformInfoPlist $HostPlatform
3251+
Write-PlatformInfoPlist Windows
3252+
Write-SDKSettingsPlist Windows
32153253

32163254
if ($Android) {
32173255
foreach ($Platform in $AndroidSDKPlatforms) {
3218-
if ($IncludeDS2) {
3219-
Invoke-BuildStep Build-DS2 $Platform
3220-
}
3221-
Invoke-BuildStep Build-ZLib $Platform
3222-
Invoke-BuildStep Build-XML2 $Platform
3223-
Invoke-BuildStep Build-CURL $Platform
3224-
Invoke-BuildStep Build-LLVM $Platform
3225-
3226-
# Build platform: SDK, Redist and XCTest
3227-
Invoke-BuildStep Build-Runtime $Platform
3228-
Invoke-BuildStep Build-Dispatch $Platform
3229-
Invoke-BuildStep Build-Foundation $Platform
3230-
Invoke-BuildStep Build-Sanitizers $Platform
3231-
Invoke-BuildStep Build-XCTest $Platform
3232-
Invoke-BuildStep Build-Testing $Platform
3233-
3234-
# Android swift-inspect only supports 64-bit platforms.
3235-
if ($Platform.Architecture.ABI -in @("arm64-v8a", "x86_64")) {
3236-
Invoke-BuildStep Build-Inspect $Platform
3256+
Invoke-BuildStep Build-SDK $Platform
3257+
Invoke-BuildStep Build-ExperimentalSDK $Platform
3258+
3259+
Get-ChildItem "$(Get-SwiftSDK Android)\usr\lib\swift\android" -File | Where-Object { $_.Name -match ".a$|.so$" } | ForEach-Object {
3260+
Write-Host -BackgroundColor DarkRed -ForegroundColor White "$($_.FullName) is not nested in an architecture directory"
3261+
Move-Item $_.FullName "$(Get-SwiftSDK Android)\usr\lib\swift\android\$($Platform.Architecture.LLVMName)\" | Out-Null
32373262
}
3238-
Invoke-BuildStep Write-SDKSettingsPlist $Platform
3263+
}
32393264

3240-
Invoke-BuildStep Build-ExperimentalRuntime $Platform -Static
3241-
Invoke-BuildStep Build-Foundation $Platform -Static
3265+
Install-Platform $AndroidSDKPlatforms Android
3266+
Write-PlatformInfoPlist Android
3267+
Write-SDKSettingsPlist Android
32423268

3243-
Move-Item "$(Get-SwiftSDK [OS]::Android)\usr\lib\swift\android\*.a" "$(Get-SwiftSDK [OS]::Android)\usr\lib\swift\android\$($Platform.Architecture.LLVMName)\"
3244-
Move-Item "$(Get-SwiftSDK [OS]::Android)\usr\lib\swift\android\*.so" "$(Get-SwiftSDK [OS]::Android)\usr\lib\swift\android\$($Platform.Architecture.LLVMName)\"
3269+
# Android swift-inspect only supports 64-bit platforms.
3270+
$AndroidSDKPlatforms | Where-Object { @("arm64-v8a", "x86_64") -contains $_.Architecture.ABI } | ForEach-Object {
3271+
Invoke-BuildStep Build-Inspect $_
32453272
}
3246-
Install-Platform $AndroidSDKPlatforms Android
3247-
Invoke-BuildStep Write-PlatformInfoPlist $Platform
32483273
}
32493274

32503275
# Build Macros for distribution

0 commit comments

Comments
 (0)