Skip to content

Commit bd2c3ea

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

File tree

3 files changed

+91
-6
lines changed

3 files changed

+91
-6
lines changed

cmake/caches/Windows-aarch64.cmake

+42-1
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,63 @@ 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+
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
45+
x86_64-unknown-windows-msvc
3046
aarch64-unknown-windows-msvc
31-
CACHE STRING "")
47+
CACHE STRING "")
48+
3249
foreach(target ${LLVM_RUNTIME_TARGETS})
3350
set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES
3451
compiler-rt
3552
CACHE STRING "")
3653
set(RUNTIMES_${target}_CMAKE_MT mt CACHE STRING "")
3754
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
3855
set(RUNTIMES_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
56+
set(RUNTIMES_${target}_COMPILER_RT_BUILD_BUILTINS NO CACHE BOOL "")
3957
set(RUNTIMES_${target}_COMPILER_RT_BUILD_CRT NO CACHE BOOL "")
4058
set(RUNTIMES_${target}_COMPILER_RT_BUILD_LIBFUZZER NO CACHE BOOL "")
59+
set(RUNTIMES_${target}_COMPILER_RT_BUILD_ORC NO CACHE BOOL "")
4160
set(RUNTIMES_${target}_COMPILER_RT_BUILD_PROFILE YES CACHE BOOL "")
4261
set(RUNTIMES_${target}_COMPILER_RT_BUILD_SANITIZERS NO CACHE BOOL "")
4362
set(RUNTIMES_${target}_COMPILER_RT_BUILD_XRAY NO CACHE BOOL "")
4463
endforeach()
4564

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+
4686
set(LLVM_TARGETS_TO_BUILD AArch64 ARM WebAssembly X86 CACHE STRING "")
4787

4888
# Disable certain targets to reduce the configure time or to avoid configuration
@@ -162,6 +202,7 @@ set(LLVM_DISTRIBUTION_COMPONENTS
162202
libclang
163203
libclang-headers
164204
LTO
205+
builtins
165206
runtimes
166207
${LLVM_TOOLCHAIN_TOOLS}
167208
${CLANG_TOOLS}

cmake/caches/Windows-x86_64.cmake

+41-5
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
32-
CACHE STRING "")
47+
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
@@ -167,6 +202,7 @@ set(LLVM_DISTRIBUTION_COMPONENTS
167202
libclang
168203
libclang-headers
169204
LTO
205+
builtins
170206
runtimes
171207
${LLVM_TOOLCHAIN_TOOLS}
172208
${CLANG_TOOLS}

utils/build.ps1

+8
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)