Skip to content

Commit 43d8183

Browse files
authored
[build.ps1] remove Android API level from Dispatch.swiftmodule names (#78800)
* [android] remove Android API level from Dispatch.swiftmodule names * [build.ps1] use swift -print-target-info to determine module triple * PR feedback * fix comment * add swift pinned toolchain to path before invoking swift.exe * run swift.exe from the built toolchain instead of the pinned toolchain * include pinned toolchain runtime in path
1 parent 654d39b commit 43d8183

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

utils/build.ps1

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ $ArchX64 = @{
229229
XCTestInstallRoot = "$BinaryCache\x64\Windows.platform\Developer\Library\XCTest-development";
230230
SwiftTestingInstallRoot = "$BinaryCache\x64\Windows.platform\Developer\Library\Testing-development";
231231
ToolchainInstallRoot = "$BinaryCache\x64\toolchains\$ProductVersion+Asserts";
232+
Cache = @{};
232233
}
233234

234235
$ArchX86 = @{
@@ -244,6 +245,7 @@ $ArchX86 = @{
244245
SDKInstallRoot = "$BinaryCache\x86\Windows.platform\Developer\SDKs\Windows.sdk";
245246
XCTestInstallRoot = "$BinaryCache\x86\Windows.platform\Developer\Library\XCTest-development";
246247
SwiftTestingInstallRoot = "$BinaryCache\x86\Windows.platform\Developer\Library\Testing-development";
248+
Cache = @{};
247249
}
248250

249251
$ArchARM64 = @{
@@ -260,6 +262,7 @@ $ArchARM64 = @{
260262
XCTestInstallRoot = "$BinaryCache\arm64\Windows.platform\Developer\Library\XCTest-development";
261263
ToolchainInstallRoot = "$BinaryCache\arm64\toolchains\$ProductVersion+Asserts";
262264
SwiftTestingInstallRoot = "$BinaryCache\arm64\Windows.platform\Developer\Library\Testing-development";
265+
Cache = @{};
263266
}
264267

265268
$AndroidARM64 = @{
@@ -275,6 +278,7 @@ $AndroidARM64 = @{
275278
SDKInstallRoot = "$BinaryCache\arm64\Android.platform\Developer\SDKs\Android.sdk";
276279
XCTestInstallRoot = "$BinaryCache\arm64\Android.platform\Developer\Library\XCTest-development";
277280
SwiftTestingInstallRoot = "$BinaryCache\arm64\Android.platform\Developer\Library\Testing-development";
281+
Cache = @{};
278282
}
279283

280284
$AndroidARMv7 = @{
@@ -290,6 +294,7 @@ $AndroidARMv7 = @{
290294
SDKInstallRoot = "$BinaryCache\armv7\Android.platform\Developer\SDKs\Android.sdk";
291295
XCTestInstallRoot = "$BinaryCache\armv7\Android.platform\Developer\Library\XCTest-development";
292296
SwiftTestingInstallRoot = "$BinaryCache\armv7\Android.platform\Developer\Library\Testing-development";
297+
Cache = @{};
293298
}
294299

295300
$AndroidX86 = @{
@@ -305,6 +310,7 @@ $AndroidX86 = @{
305310
SDKInstallRoot = "$BinaryCache\x86\Android.platform\Developer\SDKs\Android.sdk";
306311
XCTestInstallRoot = "$BinaryCache\x86\Android.platform\Developer\Library\XCTest-development";
307312
SwiftTestingInstallRoot = "$BinaryCache\x86\Android.platform\Developer\Library\Testing-development";
313+
Cache = @{};
308314
}
309315

310316
$AndroidX64 = @{
@@ -320,6 +326,7 @@ $AndroidX64 = @{
320326
SDKInstallRoot = "$BinaryCache\x64\Android.platform\Developer\SDKs\Android.sdk";
321327
XCTestInstallRoot = "$BinaryCache\x64\Android.platform\Developer\Library\XCTest-development";
322328
SwiftTestingInstallRoot = "$BinaryCache\x64\Android.platform\Developer\Library\Testing-development";
329+
Cache = @{};
323330
}
324331

325332
$HostArch = switch ($HostArchName) {
@@ -479,6 +486,36 @@ function Get-BuildProjectCMakeModules([BuildComponent]$Project) {
479486
return "$BinaryCache\$($Project.value__)\cmake\modules"
480487
}
481488

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+
482519
function Copy-File($Src, $Dst) {
483520
# Create the directory tree first so Copy-Item succeeds
484521
# If $Dst is the target directory, make sure it ends with "\"
@@ -1150,8 +1187,8 @@ function Build-CMakeProject {
11501187
if (-not ($Platform -eq "Windows")) {
11511188
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER_WORKS = "YES"
11521189
}
1153-
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER_TARGET $Arch.LLVMTarget.Replace("$AndroidAPILevel", "")
11541190
if ($UseBuiltCompilers.Contains("Swift")) {
1191+
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER_TARGET (Get-ModuleTriple $Arch)
11551192
$RuntimeBinaryCache = Get-TargetProjectBinaryCache $Arch Runtime
11561193
$SwiftResourceDir = "${RuntimeBinaryCache}\lib\swift"
11571194

@@ -1191,6 +1228,7 @@ function Build-CMakeProject {
11911228
}
11921229

11931230
} else {
1231+
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER_TARGET $Arch.LLVMTarget
11941232
$SwiftArgs += @("-sdk", (Get-PinnedToolchainSDK))
11951233
}
11961234

@@ -1826,12 +1864,10 @@ function Build-RegsGen2($Arch) {
18261864
}
18271865

18281866
function Build-DS2([Platform]$Platform, $Arch) {
1829-
$ArchName = $Arch.LLVMTarget.Replace("$AndroidAPILevel","")
1830-
18311867
Build-CMakeProject `
18321868
-Src "$SourceCache\ds2" `
18331869
-Bin "$($Arch.BinaryCache)\$Platform\ds2" `
1834-
-InstallTo "$($Arch.PlatformInstallRoot)\Developer\Library\$ArchName" `
1870+
-InstallTo "$($Arch.PlatformInstallRoot)\Developer\Library\$(Get-ModuleTriple $Arch)" `
18351871
-Arch $Arch `
18361872
-Platform $Platform `
18371873
-BuildTargets default `
@@ -1983,7 +2019,7 @@ function Build-Runtime([Platform]$Platform, $Arch) {
19832019
-CacheScript $SourceCache\swift\cmake\caches\Runtime-$Platform-$($Arch.LLVMName).cmake `
19842020
-UseBuiltCompilers C,CXX,Swift `
19852021
-Defines ($PlatformDefines + @{
1986-
CMAKE_Swift_COMPILER_TARGET = $Arch.LLVMTarget.Replace("$AndroidAPILevel", "");
2022+
CMAKE_Swift_COMPILER_TARGET = (Get-ModuleTriple $Arch);
19872023
CMAKE_Swift_COMPILER_WORKS = "YES";
19882024
CMAKE_SYSTEM_NAME = $Platform.ToString();
19892025
LLVM_DIR = "$(Get-TargetProjectBinaryCache $Arch LLVM)\lib\cmake\llvm";
@@ -2297,7 +2333,7 @@ function Install-Platform([Platform]$Platform, $Arch) {
22972333
Get-ChildItem -Recurse "$PlatformLibSrc\$($Arch.LLVMName)" | ForEach-Object {
22982334
if (".swiftmodule", ".swiftdoc", ".swiftinterface" -contains $_.Extension) {
22992335
$DstDir = "$PlatformLibDst\$($_.BaseName).swiftmodule"
2300-
Copy-File $_.FullName "$DstDir\$($Arch.LLVMTarget)$($_.Extension)"
2336+
Copy-File $_.FullName "$DstDir\$(Get-ModuleTriple $Arch)$($_.Extension)"
23012337
} else {
23022338
Copy-File $_.FullName "$PlatformLibDst\$($Arch.LLVMName)\"
23032339
}

0 commit comments

Comments
 (0)