[libc] Use the boostrap build's target triple if available.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D141428
This commit is contained in:
Siva Chandra Reddy 2023-01-03 21:05:25 +00:00
parent 32aea4bb84
commit 41c6c75333
2 changed files with 34 additions and 15 deletions

View File

@ -86,17 +86,33 @@ endif()
set(LIBC_TARGET_ARCHITECTURE ${compiler_arch})
set(LIBC_TARGET_OS ${compiler_sys})
set(LIBC_CROSSBUILD FALSE)
# One should not set LLVM_RUNTIMES_TARGET and LIBC_TARGET_TRIPLE
if(LLVM_RUNTIMES_TARGET AND LIBC_TARGET_TRIPLE)
message(FATAL_ERROR
"libc build: Specify only LLVM_RUNTIMES_TARGET if you are doing a "
"runtimes/bootstrap build. If you are doing a standalone build, "
"specify only LIBC_TARGET_TRIPLE.")
endif()
set(explicit_target_triple)
if(LLVM_RUNTIMES_TARGET)
set(explicit_target_triple ${LLVM_RUNTIMES_TARGET})
elseif(LIBC_TARGET_TRIPLE)
set(explicit_target_triple ${LIBC_TARGET_TRIPLE})
endif()
# The libc's target architecture and OS are set to match the compiler's default
# target triple above. However, one can explicitly set LIBC_TARGET_TRIPLE. If it
# is and does not match the compiler's target triple, then we will use it set up
# libc's target architecture and OS.
if(LIBC_TARGET_TRIPLE)
get_arch_and_system_from_triple(${LIBC_TARGET_TRIPLE} libc_arch libc_sys)
# target triple above. However, one can explicitly set LIBC_TARGET_TRIPLE or
# LLVM_RUNTIMES_TARGET (for runtimes/bootstrap build). If one of them is set,
# then we will use that target triple to deduce libc's target OS and
# architecture.
if(explicit_target_triple)
get_arch_and_system_from_triple(${explicit_target_triple} libc_arch libc_sys)
if(NOT libc_arch)
message(FATAL_ERROR
"libc build: Invalid or unknown triple in LIBC_TARGET_TRIPLE: "
"${LIBC_TARGET_TRIPLE}")
"libc build: Invalid or unknown triple: ${explicit_target_triple}")
endif()
set(LIBC_TARGET_ARCHITECTURE ${libc_arch})
set(LIBC_TARGET_OS ${libc_sys})
@ -136,16 +152,19 @@ endif()
# If the compiler target triple is not the same as the triple specified by
# LIBC_TARGET_TRIPLE, we will add a --target option if the compiler is clang.
# If the compiler is GCC we just error out as there is no equivalent of an
# option like --target.
if(LIBC_TARGET_TRIPLE AND
(NOT (libc_compiler_triple STREQUAL LIBC_TARGET_TRIPLE)))
# LIBC_TARGET_TRIPLE or LLVM_RUNTIMES_TARGET, we will add a --target option
# if the compiler is clang. If the compiler is GCC we just error out as there
# is no equivalent of an option like --target.
if(explicit_target_triple AND
(NOT (libc_compiler_triple STREQUAL explicit_target_triple)))
set(LIBC_CROSSBUILD TRUE)
if(CMAKE_COMPILER_IS_GNUCXX)
message(FATAL_ERROR
"GCC target triple and LIBC_TARGET_TRIPLE do not match.")
"GCC target triple and the explicity specified target triple do "
"not match.")
else()
list(APPEND LIBC_COMPILE_OPTIONS_DEFAULT "--target=${LIBC_TARGET_TRIPLE}")
list(APPEND
LIBC_COMPILE_OPTIONS_DEFAULT "--target=${explicit_target_triple}")
endif()
endif()

View File

@ -61,7 +61,7 @@ _generate_check_code()
set(LIBC_CPU_FEATURES "" CACHE PATH "Host supported CPU features")
if(CMAKE_CROSSCOMPILING)
if(LIBC_CROSSBUILD)
_intersection(cpu_features "${ALL_CPU_FEATURES}" "${LIBC_CPU_FEATURES}")
if(NOT "${cpu_features}" STREQUAL "${LIBC_CPU_FEATURES}")
message(FATAL_ERROR "Unsupported CPU features: ${cpu_features}")