[libc-commits] [PATCH] D141428: [libc] Use the boostrap build's target triple if available.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Jan 10 13:56:40 PST 2023


sivachandra created this revision.
sivachandra added a reviewer: lntue.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
sivachandra requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141428

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


Index: libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
===================================================================
--- libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
+++ libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
@@ -61,7 +61,7 @@
 
 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}")
Index: libc/cmake/modules/LLVMLibCArchitectures.cmake
===================================================================
--- libc/cmake/modules/LLVMLibCArchitectures.cmake
+++ libc/cmake/modules/LLVMLibCArchitectures.cmake
@@ -86,17 +86,33 @@
 
 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 @@
 
 
 # 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()
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141428.487981.patch
Type: text/x-patch
Size: 3704 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230110/85c4da06/attachment.bin>


More information about the libc-commits mailing list