Skip to content

Commit 6a7be95

Browse files
authored
Merge pull request #74754 from hyp/eng/android-compiler-rt-buildps1
[windows][toolchain] build android compiler-rt builtins when buildin…
2 parents 7ca4041 + 063a41c commit 6a7be95

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

cmake/caches/Windows-x86_64.cmake

+40-4
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,34 @@ 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+
30+
set(DEFAULT_BUILTIN_TARGETS
31+
x86_64-unknown-windows-msvc
32+
aarch64-unknown-windows-msvc)
33+
# Build the android builtins if NDK path is provided.
34+
if(NOT "$ENV{NDKPATH}" STREQUAL "")
35+
list(APPEND DEFAULT_BUILTIN_TARGETS
36+
aarch64-unknown-linux-android
37+
x86_64-unknown-linux-android)
38+
endif()
39+
40+
# The builtin targets are used to build the compiler-rt builtins.
41+
set(LLVM_BUILTIN_TARGETS ${DEFAULT_BUILTIN_TARGETS} CACHE STRING "")
42+
43+
# The runtime targets are used to build the compiler-rt profile library.
2944
set(LLVM_RUNTIME_TARGETS
3045
x86_64-unknown-windows-msvc
3146
aarch64-unknown-windows-msvc
3247
CACHE STRING "")
48+
3349
foreach(target ${LLVM_RUNTIME_TARGETS})
3450
set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES
3551
compiler-rt
3652
CACHE STRING "")
3753
set(RUNTIMES_${target}_CMAKE_MT mt CACHE STRING "")
38-
if(${target} MATCHES windows-msvc)
39-
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
40-
endif()
54+
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
4155
set(RUNTIMES_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
42-
set(RUNTIMES_${target}_COMPILER_RT_BUILD_BUILTINS YES CACHE BOOL "")
56+
set(RUNTIMES_${target}_COMPILER_RT_BUILD_BUILTINS NO CACHE BOOL "")
4357
set(RUNTIMES_${target}_COMPILER_RT_BUILD_CRT NO CACHE BOOL "")
4458
set(RUNTIMES_${target}_COMPILER_RT_BUILD_LIBFUZZER NO CACHE BOOL "")
4559
set(RUNTIMES_${target}_COMPILER_RT_BUILD_ORC NO CACHE BOOL "")
@@ -48,6 +62,27 @@ foreach(target ${LLVM_RUNTIME_TARGETS})
4862
set(RUNTIMES_${target}_COMPILER_RT_BUILD_XRAY NO CACHE BOOL "")
4963
endforeach()
5064

65+
foreach(target ${LLVM_BUILTIN_TARGETS})
66+
set(BUILTINS_${target}_CMAKE_MT mt CACHE STRING "")
67+
if(${target} MATCHES windows-msvc)
68+
set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
69+
elseif(${target} MATCHES linux-android)
70+
# Use a single 'linux' directory and arch-based lib names on Android.
71+
set(BUILTINS_${target}_LLVM_ENABLE_PER_TARGET_RUNTIME_DIR NO CACHE BOOL "")
72+
set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Android CACHE STRING "")
73+
if(${target} MATCHES aarch64)
74+
set(BUILTINS_${target}_CMAKE_ANDROID_ARCH_ABI arm64-v8a CACHE STRING "")
75+
else()
76+
set(BUILTINS_${target}_CMAKE_ANDROID_ARCH_ABI x86_64 CACHE STRING "")
77+
endif()
78+
set(BUILTINS_${target}_CMAKE_ANDROID_NDK $ENV{NDKPATH} CACHE PATH "")
79+
set(BUILTINS_${target}_CMAKE_ANDROID_API 21 CACHE STRING "")
80+
set(BUILTINS_${target}_CMAKE_C_COMPILER_TARGET "${target}21" CACHE STRING "")
81+
set(BUILTINS_${target}_CMAKE_CXX_COMPILER_TARGET "${target}21" CACHE STRING "")
82+
endif()
83+
set(BUILTINS_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
84+
endforeach()
85+
5186
set(LLVM_TARGETS_TO_BUILD AArch64 ARM WebAssembly X86 CACHE STRING "")
5287

5388
# Disable certain targets to reduce the configure time or to avoid configuration
@@ -168,6 +203,7 @@ set(LLVM_DISTRIBUTION_COMPONENTS
168203
libclang
169204
libclang-headers
170205
LTO
206+
builtins
171207
runtimes
172208
${LLVM_TOOLCHAIN_TOOLS}
173209
${CLANG_TOOLS}

utils/build.ps1

+8
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ function Build-CMakeProject {
795795
[string[]] $UseBuiltCompilers = @(), # ASM,C,CXX,Swift
796796
[string[]] $UsePinnedCompilers = @(), # ASM,C,CXX,Swift
797797
[switch] $UseSwiftSwiftDriver = $false,
798+
[switch] $AddAndroidCMakeEnv = $false,
798799
[string] $SwiftSDK = "",
799800
[hashtable] $Defines = @{}, # Values are either single strings or arrays of flags
800801
[string[]] $BuildTargets = @()
@@ -844,6 +845,12 @@ function Build-CMakeProject {
844845
TryAdd-KeyValue $Defines CMAKE_SYSTEM_PROCESSOR $Arch.CMakeName
845846
}
846847

848+
if ($AddAndroidCMakeEnv) {
849+
# Set generic android options if we need to build an Android runtime component
850+
# while building the compiler. Use an environment variable to pass it, to
851+
# ensure that it can be accessed from the cmake cache file.
852+
$env:NDKPATH = Get-AndroidNDKPath
853+
}
847854
if ($Platform -eq "Android") {
848855
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
849856
$VSInstallPath = & $vswhere -nologo -latest -products * -property installationPath
@@ -1333,6 +1340,7 @@ function Build-Compilers() {
13331340
-Bin $CompilersBinaryCache `
13341341
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
13351342
-Arch $Arch `
1343+
-AddAndroidCMakeEnv:$Android `
13361344
-UseMSVCCompilers C,CXX `
13371345
-UsePinnedCompilers Swift `
13381346
-BuildTargets $Targets `

0 commit comments

Comments
 (0)