[libc-commits] [libc] 41c6c75 - [libc] Use the boostrap build's target triple if available.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Tue Jan 10 22:37:13 PST 2023


Author: Siva Chandra Reddy
Date: 2023-01-11T06:37:05Z
New Revision: 41c6c75333c841de8973d77de6f7366fdab4e42d

URL: https://github.com/llvm/llvm-project/commit/41c6c75333c841de8973d77de6f7366fdab4e42d
DIFF: https://github.com/llvm/llvm-project/commit/41c6c75333c841de8973d77de6f7366fdab4e42d.diff

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

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D141428

Added: 
    

Modified: 
    libc/cmake/modules/LLVMLibCArchitectures.cmake
    libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake

Removed: 
    


################################################################################
diff  --git a/libc/cmake/modules/LLVMLibCArchitectures.cmake b/libc/cmake/modules/LLVMLibCArchitectures.cmake
index 6308a2ccdd39e..f925355bcf8c2 100644
--- a/libc/cmake/modules/LLVMLibCArchitectures.cmake
+++ b/libc/cmake/modules/LLVMLibCArchitectures.cmake
@@ -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()
 

diff  --git a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
index fdd477c1155ec..b97b03f7b07a8 100644
--- a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
+++ b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
@@ -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}")


        


More information about the libc-commits mailing list