[libcxx-commits] [PATCH] D140925: [CMake] Use Clang to infer the target triple

Petr Hosek via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jan 3 14:30:20 PST 2023


phosek created this revision.
phosek added reviewers: smeenai, ldionne, mstorsjo, mgorny.
Herald added subscribers: Enna1, abrachet.
Herald added a project: All.
phosek requested review of this revision.
Herald added projects: clang, Sanitizers, libc++, libc++abi.
Herald added subscribers: libcxx-commits, Sanitizers, cfe-commits.
Herald added a reviewer: libc++.
Herald added a reviewer: libc++abi.

When using Clang as a compiler, use Clang to normalize the triple that's
used to construct path for runtime library build and install paths. This
ensures that paths are consistent and avoids the issue where the build
uses a different triple spelling.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140925

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake
  compiler-rt/lib/builtins/CMakeLists.txt
  runtimes/CMakeLists.txt


Index: runtimes/CMakeLists.txt
===================================================================
--- runtimes/CMakeLists.txt
+++ runtimes/CMakeLists.txt
@@ -164,6 +164,20 @@
 set(LLVM_RUNTIME_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
   "Triple used as runtime instrallation path.")
 
+if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+  set(CXX_TARGET_TRIPLE ${CMAKE_CXX_COMPILER} --target=${LLVM_RUNTIME_TRIPLE} -print-target-triple)
+  execute_process(COMMAND ${CXX_TARGET_TRIPLE}
+    RESULT_VARIABLE result
+    OUTPUT_VARIABLE output
+    OUTPUT_STRIP_TRAILING_WHITESPACE)
+  if(result EQUAL 0)
+    set(LLVM_RUNTIME_TRIPLE ${output})
+  else()
+    string(REPLACE ";" " " CXX_TARGET_TRIPLE "${CXX_TARGET_TRIPLE}")
+    message(WARNING "Failed to execute `${CXX_TARGET_TRIPLE}` to normalize target triple.")
+  endif()
+endif()
+
 option(LLVM_INCLUDE_TESTS "Generate build targets for the runtimes unit tests." ON)
 option(LLVM_INCLUDE_DOCS "Generate build targets for the runtimes documentation." ON)
 option(LLVM_ENABLE_SPHINX "Use Sphinx to generate the runtimes documentation." OFF)
Index: compiler-rt/lib/builtins/CMakeLists.txt
===================================================================
--- compiler-rt/lib/builtins/CMakeLists.txt
+++ compiler-rt/lib/builtins/CMakeLists.txt
@@ -35,6 +35,19 @@
   if (NOT LLVM_RUNTIMES_BUILD)
     load_llvm_config()
   endif()
+  if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+    set(CXX_TARGET_TRIPLE ${CMAKE_CXX_COMPILER} --target=${LLVM_RUNTIME_TRIPLE} -print-target-triple)
+    execute_process(COMMAND ${CXX_TARGET_TRIPLE}
+      RESULT_VARIABLE result
+      OUTPUT_VARIABLE output
+      OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if(result EQUAL 0)
+      set(LLVM_RUNTIME_TRIPLE ${output})
+    else()
+      string(REPLACE ";" " " CXX_TARGET_TRIPLE "${CXX_TARGET_TRIPLE}")
+      message(WARNING "Failed to execute `${CXX_TARGET_TRIPLE}` to normalize target triple.")
+    endif()
+  endif()
   construct_compiler_rt_default_triple()
 
   include(SetPlatformToolchainTools)
Index: clang/cmake/caches/Fuchsia-stage2.cmake
===================================================================
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -86,7 +86,7 @@
   set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx" CACHE STRING "")
 endif()
 
-foreach(target aarch64-unknown-linux-gnu;armv7-unknown-linux-gnueabihf;i386-unknown-linux-gnu;x86_64-unknown-linux-gnu)
+foreach(target aarch64-linux-gnu;armv7-linux-gnueabihf;i386-linux-gnu;x86_64-linux-gnu)
   if(LINUX_${target}_SYSROOT)
     # Set the per-target builtins options.
     list(APPEND BUILTIN_TARGETS "${target}")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140925.486088.patch
Type: text/x-patch
Size: 2697 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230103/4952ffa0/attachment-0001.bin>


More information about the libcxx-commits mailing list