@@ -229,6 +229,7 @@ $ArchX64 = @{
229
229
XCTestInstallRoot = " $BinaryCache \x64\Windows.platform\Developer\Library\XCTest-development" ;
230
230
SwiftTestingInstallRoot = " $BinaryCache \x64\Windows.platform\Developer\Library\Testing-development" ;
231
231
ToolchainInstallRoot = " $BinaryCache \x64\toolchains\$ProductVersion +Asserts" ;
232
+ Cache = @ {};
232
233
}
233
234
234
235
$ArchX86 = @ {
@@ -244,6 +245,7 @@ $ArchX86 = @{
244
245
SDKInstallRoot = " $BinaryCache \x86\Windows.platform\Developer\SDKs\Windows.sdk" ;
245
246
XCTestInstallRoot = " $BinaryCache \x86\Windows.platform\Developer\Library\XCTest-development" ;
246
247
SwiftTestingInstallRoot = " $BinaryCache \x86\Windows.platform\Developer\Library\Testing-development" ;
248
+ Cache = @ {};
247
249
}
248
250
249
251
$ArchARM64 = @ {
@@ -260,6 +262,7 @@ $ArchARM64 = @{
260
262
XCTestInstallRoot = " $BinaryCache \arm64\Windows.platform\Developer\Library\XCTest-development" ;
261
263
ToolchainInstallRoot = " $BinaryCache \arm64\toolchains\$ProductVersion +Asserts" ;
262
264
SwiftTestingInstallRoot = " $BinaryCache \arm64\Windows.platform\Developer\Library\Testing-development" ;
265
+ Cache = @ {};
263
266
}
264
267
265
268
$AndroidARM64 = @ {
@@ -275,6 +278,7 @@ $AndroidARM64 = @{
275
278
SDKInstallRoot = " $BinaryCache \arm64\Android.platform\Developer\SDKs\Android.sdk" ;
276
279
XCTestInstallRoot = " $BinaryCache \arm64\Android.platform\Developer\Library\XCTest-development" ;
277
280
SwiftTestingInstallRoot = " $BinaryCache \arm64\Android.platform\Developer\Library\Testing-development" ;
281
+ Cache = @ {};
278
282
}
279
283
280
284
$AndroidARMv7 = @ {
@@ -290,6 +294,7 @@ $AndroidARMv7 = @{
290
294
SDKInstallRoot = " $BinaryCache \armv7\Android.platform\Developer\SDKs\Android.sdk" ;
291
295
XCTestInstallRoot = " $BinaryCache \armv7\Android.platform\Developer\Library\XCTest-development" ;
292
296
SwiftTestingInstallRoot = " $BinaryCache \armv7\Android.platform\Developer\Library\Testing-development" ;
297
+ Cache = @ {};
293
298
}
294
299
295
300
$AndroidX86 = @ {
@@ -305,6 +310,7 @@ $AndroidX86 = @{
305
310
SDKInstallRoot = " $BinaryCache \x86\Android.platform\Developer\SDKs\Android.sdk" ;
306
311
XCTestInstallRoot = " $BinaryCache \x86\Android.platform\Developer\Library\XCTest-development" ;
307
312
SwiftTestingInstallRoot = " $BinaryCache \x86\Android.platform\Developer\Library\Testing-development" ;
313
+ Cache = @ {};
308
314
}
309
315
310
316
$AndroidX64 = @ {
@@ -320,6 +326,7 @@ $AndroidX64 = @{
320
326
SDKInstallRoot = " $BinaryCache \x64\Android.platform\Developer\SDKs\Android.sdk" ;
321
327
XCTestInstallRoot = " $BinaryCache \x64\Android.platform\Developer\Library\XCTest-development" ;
322
328
SwiftTestingInstallRoot = " $BinaryCache \x64\Android.platform\Developer\Library\Testing-development" ;
329
+ Cache = @ {};
323
330
}
324
331
325
332
$HostArch = switch ($HostArchName ) {
@@ -479,6 +486,36 @@ function Get-BuildProjectCMakeModules([BuildComponent]$Project) {
479
486
return " $BinaryCache \$ ( $Project.value__ ) \cmake\modules"
480
487
}
481
488
489
+ function Get-TargetInfo ($Arch ) {
490
+ # Cache the result of "swift -print-target-info" as $Arch.Cache.TargetInfo
491
+ $CacheKey = " TargetInfo"
492
+ if (-not $Arch.Cache.ContainsKey ($CacheKey )) {
493
+ $CompilersBinaryCache = if ($IsCrossCompiling ) {
494
+ Get-BuildProjectBinaryCache Compilers
495
+ } else {
496
+ Get-HostProjectBinaryCache Compilers
497
+ }
498
+ $ToolchainBinDir = Join-Path - Path $CompilersBinaryCache - ChildPath " bin"
499
+ $CMarkDir = Join-Path - Path (Get-CMarkBinaryCache $BuildArch ) - ChildPath " src"
500
+ $SwiftExe = Join-Path - Path $ToolchainBinDir - ChildPath " swift.exe"
501
+ Isolate- EnvVars {
502
+ $env: Path = " $ToolchainBinDir ;$CMarkDir ;$ ( Get-PinnedToolchainRuntime ) ;${env: Path} "
503
+ $TargetInfoJson = & $SwiftExe - target $Arch.LLVMTarget - print- target- info
504
+ if ($LastExitCode -ne 0 ) {
505
+ throw " Unable to print target info for $ ( $Arch.LLVMTarget ) $TargetInfoJson "
506
+ }
507
+ $TargetInfo = $TargetInfoJson | ConvertFrom-Json
508
+ $Arch.Cache [$CacheKey ] = $TargetInfo.target
509
+ }
510
+ }
511
+ return $Arch.Cache [$CacheKey ]
512
+ }
513
+
514
+ function Get-ModuleTriple ($Arch ) {
515
+ $targetInfo = Get-TargetInfo - Arch $Arch
516
+ return $targetInfo.moduleTriple
517
+ }
518
+
482
519
function Copy-File ($Src , $Dst ) {
483
520
# Create the directory tree first so Copy-Item succeeds
484
521
# If $Dst is the target directory, make sure it ends with "\"
@@ -1150,8 +1187,8 @@ function Build-CMakeProject {
1150
1187
if (-not ($Platform -eq " Windows" )) {
1151
1188
TryAdd- KeyValue $Defines CMAKE_Swift_COMPILER_WORKS = " YES"
1152
1189
}
1153
- TryAdd- KeyValue $Defines CMAKE_Swift_COMPILER_TARGET $Arch.LLVMTarget.Replace (" $AndroidAPILevel " , " " )
1154
1190
if ($UseBuiltCompilers.Contains (" Swift" )) {
1191
+ TryAdd- KeyValue $Defines CMAKE_Swift_COMPILER_TARGET (Get-ModuleTriple $Arch )
1155
1192
$RuntimeBinaryCache = Get-TargetProjectBinaryCache $Arch Runtime
1156
1193
$SwiftResourceDir = " ${RuntimeBinaryCache} \lib\swift"
1157
1194
@@ -1191,6 +1228,7 @@ function Build-CMakeProject {
1191
1228
}
1192
1229
1193
1230
} else {
1231
+ TryAdd- KeyValue $Defines CMAKE_Swift_COMPILER_TARGET $Arch.LLVMTarget
1194
1232
$SwiftArgs += @ (" -sdk" , (Get-PinnedToolchainSDK ))
1195
1233
}
1196
1234
@@ -1826,12 +1864,10 @@ function Build-RegsGen2($Arch) {
1826
1864
}
1827
1865
1828
1866
function Build-DS2 ([Platform ]$Platform , $Arch ) {
1829
- $ArchName = $Arch.LLVMTarget.Replace (" $AndroidAPILevel " , " " )
1830
-
1831
1867
Build-CMakeProject `
1832
1868
- Src " $SourceCache \ds2" `
1833
1869
- Bin " $ ( $Arch.BinaryCache ) \$Platform \ds2" `
1834
- - InstallTo " $ ( $Arch.PlatformInstallRoot ) \Developer\Library\$ArchName " `
1870
+ - InstallTo " $ ( $Arch.PlatformInstallRoot ) \Developer\Library\$ ( Get-ModuleTriple $Arch ) " `
1835
1871
- Arch $Arch `
1836
1872
- Platform $Platform `
1837
1873
- BuildTargets default `
@@ -1983,7 +2019,7 @@ function Build-Runtime([Platform]$Platform, $Arch) {
1983
2019
- CacheScript $SourceCache \swift\cmake\caches\Runtime- $Platform - $ ($Arch.LLVMName ).cmake `
1984
2020
- UseBuiltCompilers C, CXX, Swift `
1985
2021
- Defines ($PlatformDefines + @ {
1986
- CMAKE_Swift_COMPILER_TARGET = $Arch .LLVMTarget.Replace ( " $AndroidAPILevel " , " " );
2022
+ CMAKE_Swift_COMPILER_TARGET = ( Get-ModuleTriple $Arch );
1987
2023
CMAKE_Swift_COMPILER_WORKS = " YES" ;
1988
2024
CMAKE_SYSTEM_NAME = $Platform.ToString ();
1989
2025
LLVM_DIR = " $ ( Get-TargetProjectBinaryCache $Arch LLVM) \lib\cmake\llvm" ;
@@ -2297,7 +2333,7 @@ function Install-Platform([Platform]$Platform, $Arch) {
2297
2333
Get-ChildItem - Recurse " $PlatformLibSrc \$ ( $Arch.LLVMName ) " | ForEach-Object {
2298
2334
if (" .swiftmodule" , " .swiftdoc" , " .swiftinterface" -contains $_.Extension ) {
2299
2335
$DstDir = " $PlatformLibDst \$ ( $_.BaseName ) .swiftmodule"
2300
- Copy-File $_.FullName " $DstDir \$ ( $Arch.LLVMTarget ) $ ( $_.Extension ) "
2336
+ Copy-File $_.FullName " $DstDir \$ ( Get-ModuleTriple $Arch ) $ ( $_.Extension ) "
2301
2337
} else {
2302
2338
Copy-File $_.FullName " $PlatformLibDst \$ ( $Arch.LLVMName ) \"
2303
2339
}
0 commit comments