Skip to content

Commit 4c9a444

Browse files
committed
[windows][toolchain] build android compiler-rt builtins when building Android SDK with build.ps1
1 parent 7743741 commit 4c9a444

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

cmake/caches/Windows-aarch64.cmake

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,27 @@ set(LLVM_DEFAULT_TARGET_TRIPLE aarch64-unknown-windows-msvc CACHE STRING "")
2626
set(LLVM_APPEND_VC_REV NO CACHE BOOL "")
2727
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR YES CACHE BOOL "")
2828
set(LLVM_ENABLE_PYTHON YES CACHE BOOL "")
29-
set(LLVM_RUNTIME_TARGETS
30-
aarch64-unknown-windows-msvc
31-
CACHE STRING "")
29+
30+
set(DEFAULT_RUNTIME_TARGETS
31+
aarch64-unknown-windows-msvc)
32+
# Build the android runtimes if NDK path is provided.
33+
if(NOT "$ENV{NDKPATH}" STREQUAL "")
34+
list(APPEND DEFAULT_RUNTIME_TARGETS
35+
aarch64-unknown-linux-android)
36+
endif()
37+
38+
set(LLVM_RUNTIME_TARGETS ${DEFAULT_RUNTIME_TARGETS} CACHE STRING "")
3239
foreach(target ${LLVM_RUNTIME_TARGETS})
3340
set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES
3441
compiler-rt
3542
CACHE STRING "")
3643
set(RUNTIMES_${target}_CMAKE_MT mt CACHE STRING "")
37-
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
44+
if(${target} MATCHES windows-msvc)
45+
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
46+
elseif(${target} MATCHES linux-android)
47+
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Android CACHE STRING "")
48+
set(RUNTIMES_${target}_CMAKE_ANDROID_NDK $ENV{NDKPATH} CACHE PATH "")
49+
endif()
3850
set(RUNTIMES_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
3951
set(RUNTIMES_${target}_COMPILER_RT_BUILD_CRT NO CACHE BOOL "")
4052
set(RUNTIMES_${target}_COMPILER_RT_BUILD_LIBFUZZER NO CACHE BOOL "")

cmake/caches/Windows-x86_64.cmake

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,28 @@ set(LLVM_DEFAULT_TARGET_TRIPLE x86_64-unknown-windows-msvc CACHE STRING "")
2626
set(LLVM_APPEND_VC_REV NO CACHE BOOL "")
2727
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR YES CACHE BOOL "")
2828
set(LLVM_ENABLE_PYTHON YES CACHE BOOL "")
29-
set(LLVM_RUNTIME_TARGETS
29+
30+
set(DEFAULT_RUNTIME_TARGETS
3031
x86_64-unknown-windows-msvc
31-
aarch64-unknown-windows-msvc
32-
CACHE STRING "")
32+
aarch64-unknown-windows-msvc)
33+
# Build the android runtimes if NDK path is provided.
34+
if(NOT "$ENV{NDKPATH}" STREQUAL "")
35+
list(APPEND DEFAULT_RUNTIME_TARGETS
36+
aarch64-unknown-linux-android
37+
x86_64-unknown-linux-android)
38+
endif()
39+
40+
set(LLVM_RUNTIME_TARGETS ${DEFAULT_RUNTIME_TARGETS} CACHE STRING "")
3341
foreach(target ${LLVM_RUNTIME_TARGETS})
3442
set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES
3543
compiler-rt
3644
CACHE STRING "")
3745
set(RUNTIMES_${target}_CMAKE_MT mt CACHE STRING "")
3846
if(${target} MATCHES windows-msvc)
3947
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
48+
elseif(${target} MATCHES linux-android)
49+
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Android CACHE STRING "")
50+
set(RUNTIMES_${target}_CMAKE_ANDROID_NDK $ENV{NDKPATH} CACHE PATH "")
4051
endif()
4152
set(RUNTIMES_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
4253
set(RUNTIMES_${target}_COMPILER_RT_BUILD_BUILTINS YES CACHE BOOL "")

utils/build.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ function Build-CMakeProject {
786786
[string[]] $UseBuiltCompilers = @(), # ASM,C,CXX,Swift
787787
[string[]] $UsePinnedCompilers = @(), # ASM,C,CXX,Swift
788788
[switch] $UseSwiftSwiftDriver = $false,
789+
[switch] $AddAndroidCMakeEnv = $false,
789790
[string] $SwiftSDK = "",
790791
[hashtable] $Defines = @{}, # Values are either single strings or arrays of flags
791792
[string[]] $BuildTargets = @()
@@ -835,6 +836,12 @@ function Build-CMakeProject {
835836
TryAdd-KeyValue $Defines CMAKE_SYSTEM_PROCESSOR $Arch.CMakeName
836837
}
837838

839+
if ($AddAndroidCMakeEnv) {
840+
# Set generic android options if we need to build an Android runtime component
841+
# while building the compiler. Use an environment variable to pass it, to
842+
# ensure that it can be accessed from the cmake cache file.
843+
$env:NDKPATH = Get-AndroidNDKPath
844+
}
838845
if ($Platform -eq "Android") {
839846
$vsWherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
840847
$vsInstallPath = & $vsWherePath -latest -property installationPath
@@ -1316,6 +1323,7 @@ function Build-Compilers() {
13161323
-Bin $CompilersBinaryCache `
13171324
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
13181325
-Arch $Arch `
1326+
-AddAndroidCMakeEnv:$Android `
13191327
-UseMSVCCompilers C,CXX `
13201328
-UsePinnedCompilers Swift `
13211329
-BuildTargets $Targets `

0 commit comments

Comments
 (0)