Skip to content

Commit da11b51

Browse files
committed
utils: begin supporting new NDKs when building
Add support for multiple NDKs for Android SDKs to be built. This is in preparation to migrate to r27c as the default NDK to use.
1 parent ed9eef2 commit da11b51

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

utils/build.ps1

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ param
139139
[string] $PinnedToolchainVariant = "Asserts",
140140
[string] $PythonVersion = "3.9.10",
141141
[ValidatePattern("^r(?:[1-9]|[1-9][0-9])(?:[a-z])?$")]
142-
[string] $AndroidNDKVersion = "r26b",
142+
[string] $AndroidNDKVersion = "r27c",
143143
[ValidatePattern("^\d+\.\d+\.\d+(?:-\w+)?")]
144144
[string] $WinSDKVersion = "",
145145
[switch] $Android = $false,
@@ -346,13 +346,32 @@ $BuildArch = switch ($BuildArchName) {
346346
default { throw "Unsupported processor architecture" }
347347
}
348348

349+
$KnownNDKs = @{
350+
r26b = @{
351+
URL = "https://dl.google.com/android/repository/android-ndk-r26b-windows.zip"
352+
SHA256 = "A478D43D4A45D0D345CDA6BE50D79642B92FB175868D9DC0DFC86181D80F691E"
353+
ClangVersion = 17
354+
}
355+
r27c = @{
356+
URL = "https://dl.google.com/android/repository/android-ndk-r27c-windows.zip"
357+
SHA256 = "27E49F11E0CEE5800983D8AF8F4ACD5BF09987AA6F790D4439DDA9F3643D2494"
358+
ClangVersion = 18
359+
}
360+
}
361+
362+
349363
$IsCrossCompiling = $HostArchName -ne $BuildArchName
350364

351365
$TimingData = New-Object System.Collections.Generic.List[System.Object]
352366

367+
function Get-AndroidNDK {
368+
$NDK = $KnownNDKs[$AndroidNDKVersion]
369+
if ($NDK -eq $null) { throw "Unsupported Android NDK version" }
370+
return $NDK
371+
}
372+
353373
function Get-AndroidNDKPath {
354-
$androidNDKPath = Join-Path -Path $BinaryCache -ChildPath "android-ndk-$AndroidNDKVersion"
355-
return $androidNDKPath
374+
return Join-Path -Path $BinaryCache -ChildPath "android-ndk-$AndroidNDKVersion"
356375
}
357376

358377
function Get-FlexExecutable {
@@ -859,14 +878,8 @@ function Fetch-Dependencies {
859878
Install-PythonModules
860879

861880
if ($Android) {
862-
# Only a specific NDK version is supported right now.
863-
if ($AndroidNDKVersion -ne "r26b") {
864-
throw "Unsupported Android NDK version"
865-
}
866-
$NDKURL = "https://dl.google.com/android/repository/android-ndk-r26b-windows.zip"
867-
$NDKHash = "A478D43D4A45D0D345CDA6BE50D79642B92FB175868D9DC0DFC86181D80F691E"
868-
DownloadAndVerify $NDKURL "$BinaryCache\android-ndk-$AndroidNDKVersion-windows.zip" $NDKHash
869-
881+
$NDK = Get-AndroidNDK
882+
DownloadAndVerify $NDK.URL "$BinaryCache\android-ndk-$AndroidNDKVersion-windows.zip" $NDK.SHA256
870883
Extract-ZipFile -ZipFileName "android-ndk-$AndroidNDKVersion-windows.zip" -BinaryCache $BinaryCache -ExtractPath "android-ndk-$AndroidNDKVersion" -CreateExtractPath $false
871884
}
872885

@@ -1104,9 +1117,6 @@ function Build-CMakeProject {
11041117
TryAdd-KeyValue $Defines SWIFT_ANDROID_NDK_PATH "$androidNDKPath"
11051118
TryAdd-KeyValue $Defines CMAKE_C_COMPILER_WORKS YES
11061119
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER_WORKS YES
1107-
# The current Android NDK ships with Clang 17,
1108-
# which doesn't provide the _Builtin_float module.
1109-
TryAdd-KeyValue $Defines SWIFT_BUILD_CLANG_OVERLAYS_SKIP_BUILTIN_FLOAT YES
11101120
}
11111121

11121122
TryAdd-KeyValue $Defines CMAKE_BUILD_TYPE Release
@@ -1256,7 +1266,7 @@ function Build-CMakeProject {
12561266
"-Xclang-linker", "--sysroot",
12571267
"-Xclang-linker", "$androidNDKPath\toolchains\llvm\prebuilt\windows-x86_64\sysroot",
12581268
"-Xclang-linker", "-resource-dir",
1259-
"-Xclang-linker", "$androidNDKPath\toolchains\llvm\prebuilt\windows-x86_64\lib\clang\17"
1269+
"-Xclang-linker", "$androidNDKPath\toolchains\llvm\prebuilt\windows-x86_64\lib\clang\$($(Get-AndroidNDK).ClangVersion)"
12601270
)
12611271
}
12621272
}
@@ -2064,16 +2074,17 @@ function Build-CURL([Platform]$Platform, $Arch) {
20642074

20652075
function Build-Runtime([Platform]$Platform, $Arch) {
20662076
$PlatformDefines = @{}
2067-
if ($Platform -eq "Android") {
2077+
if ($Platform -eq [Platform]::Android) {
20682078
$PlatformDefines += @{
20692079
LLVM_ENABLE_LIBCXX = "YES";
20702080
SWIFT_USE_LINKER = "lld";
20712081
SWIFT_INCLUDE_TESTS = "NO";
20722082
SWIFT_INCLUDE_TEST_BINARIES = "NO";
2083+
# Clang[<18] doesn't provide the _Builtin_float module.
2084+
SWIFT_BUILD_CLANG_OVERLAYS_SKIP_BUILTIN_FLOAT = "YES";
20732085
}
20742086
}
20752087

2076-
20772088
Isolate-EnvVars {
20782089
$env:Path = "$(Get-CMarkBinaryCache $Arch)\src;$(Get-PinnedToolchainRuntime);${env:Path}"
20792090

0 commit comments

Comments
 (0)