[libc] [llvm] [LLVM] Replace use of `LLVM_RUNTIMES_TARGET` with `LLVM_DEFAULT_TARGET_TRIPLE` (PR #136208)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 21 16:55:01 PDT 2025


https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/136208

>From 43e38f21059f43115a269e2141eac77360f47118 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Thu, 17 Apr 2025 16:39:19 -0500
Subject: [PATCH] [libc] Fix passing the full runtime target for multilibs

Summary:
The multilib builds pass `+name` to the runtime target. We were using
this as a strict triple and passing it to the compiler. Parse out the
triple portion in this case.
---
 flang-rt/CMakeLists.txt                        |  4 ++--
 flang-rt/README.md                             |  9 ++++-----
 flang-rt/cmake/modules/AddFlangRT.cmake        |  4 ++--
 flang-rt/lib/runtime/CMakeLists.txt            |  2 +-
 libc/cmake/modules/LLVMLibCArchitectures.cmake | 16 ++++++++--------
 libc/docs/gpu/building.rst                     | 12 ++++++------
 6 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/flang-rt/CMakeLists.txt b/flang-rt/CMakeLists.txt
index b3b6e00f7c0c8..fca91c6057156 100644
--- a/flang-rt/CMakeLists.txt
+++ b/flang-rt/CMakeLists.txt
@@ -223,9 +223,9 @@ endif()
 
 # The GPU targets require a few mandatory arguments to make the standard CMake
 # check flags happy.
-if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn")
+if ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn")
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
-elseif ("${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx")
+elseif ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^nvptx")
   set(CMAKE_REQUIRED_FLAGS
       "${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument")
 endif()
diff --git a/flang-rt/README.md b/flang-rt/README.md
index d79ddcaf20639..6b82beb5268f0 100644
--- a/flang-rt/README.md
+++ b/flang-rt/README.md
@@ -107,11 +107,10 @@ The `CMAKE_Fortran_COMPILER_WORKS` parameter must be set because otherwise CMake
 will test whether the Fortran compiler can compile and link programs which will
 obviously fail without a runtime library available yet.
 
-Building Flang-RT for cross-compilation triple, the target triple can
-be selected using `LLVM_DEFAULT_TARGET_TRIPLE` AND `LLVM_RUNTIMES_TARGET`.
-Of course, Flang-RT can be built multiple times with different build
-configurations, but have to be located manually when using with the Flang
-driver using the `-L` option.
+Building Flang-RT for cross-compilation triple, the target triple can be
+selected using `LLVM_DEFAULT_TARGET_TRIPLE`. Of course, Flang-RT can be built
+multiple times with different build configurations, but have to be located
+manually when using with the Flang driver using the `-L` option.
 
 After configuration, build, test, and install the runtime via
 
diff --git a/flang-rt/cmake/modules/AddFlangRT.cmake b/flang-rt/cmake/modules/AddFlangRT.cmake
index 93a21277caff8..be87a6fb837e3 100644
--- a/flang-rt/cmake/modules/AddFlangRT.cmake
+++ b/flang-rt/cmake/modules/AddFlangRT.cmake
@@ -234,11 +234,11 @@ function (add_flangrt_library name)
     endif ()
 
     # Add target specific options if necessary.
-    if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn")
+    if ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn")
       target_compile_options(${tgtname} PRIVATE
           $<$<COMPILE_LANGUAGE:CXX>:-nogpulib -flto -fvisibility=hidden>
         )
-    elseif ("${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx")
+    elseif ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^nvptx")
       target_compile_options(${tgtname} PRIVATE
           $<$<COMPILE_LANGUAGE:CXX>:-nogpulib -flto -fvisibility=hidden -Wno-unknown-cuda-version --cuda-feature=+ptx63>
         )
diff --git a/flang-rt/lib/runtime/CMakeLists.txt b/flang-rt/lib/runtime/CMakeLists.txt
index c5e7bdce5b2fd..24557c4272f4a 100644
--- a/flang-rt/lib/runtime/CMakeLists.txt
+++ b/flang-rt/lib/runtime/CMakeLists.txt
@@ -172,7 +172,7 @@ else ()
   set(f128_sources "")
 endif ()
 
-if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn|^nvptx")
+if ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn|^nvptx")
   set(sources ${gpu_sources})
 else ()
   set(sources ${supported_sources} ${host_sources} ${f128_sources})
diff --git a/libc/cmake/modules/LLVMLibCArchitectures.cmake b/libc/cmake/modules/LLVMLibCArchitectures.cmake
index 62f3a2e3bdb59..484d5f5c2cce6 100644
--- a/libc/cmake/modules/LLVMLibCArchitectures.cmake
+++ b/libc/cmake/modules/LLVMLibCArchitectures.cmake
@@ -108,24 +108,24 @@ 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)
+# One should not set LLVM_DEFAULT_TARGET_TRIPLE and LIBC_TARGET_TRIPLE
+if(LLVM_DEFAULT_TARGET_TRIPLE AND LLVM_RUNTIMES_BUILD AND LIBC_TARGET_TRIPLE)
   message(FATAL_ERROR
-          "libc build: Specify only LLVM_RUNTIMES_TARGET if you are doing a "
+          "libc build: Specify only LLVM_DEFAULT_TARGET_TRIPLE 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})
+if(LLVM_DEFAULT_TARGET_TRIPLE AND LLVM_RUNTIMES_BUILD)
+  set(explicit_target_triple ${LLVM_DEFAULT_TARGET_TRIPLE})
 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 or
-# LLVM_RUNTIMES_TARGET (for runtimes/bootstrap build). If one of them is set,
+# LLVM_DEFAULT_TARGET_TRIPLE (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)
@@ -200,14 +200,14 @@ endif()
 
 
 # If the compiler target triple is not the same as the triple specified by
-# LIBC_TARGET_TRIPLE or LLVM_RUNTIMES_TARGET, we will add a --target option
+# LIBC_TARGET_TRIPLE or LLVM_DEFAULT_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(explicit_target_triple AND
    (NOT (libc_compiler_triple STREQUAL explicit_target_triple)))
   set(LIBC_CROSSBUILD TRUE)
   if(CMAKE_COMPILER_IS_GNUCXX)
-    message(FATAL_ERROR
+    message(WARNING
             "GCC target triple (${libc_compiler_triple}) and the explicity "
             "specified target triple (${explicit_target_triple}) do not match.")
   else()
diff --git a/libc/docs/gpu/building.rst b/libc/docs/gpu/building.rst
index 9f9528b30d9bf..5e1c59d8fbdd4 100644
--- a/libc/docs/gpu/building.rst
+++ b/libc/docs/gpu/building.rst
@@ -100,12 +100,12 @@ targeting a GPU architecture.
   $> TARGET_C_COMPILER=</path/to/clang>
   $> TARGET_CXX_COMPILER=</path/to/clang++>
   $> cmake ../runtimes \ # Point to the runtimes build
-     -G Ninja                                  \
-     -DLLVM_ENABLE_RUNTIMES=libc               \
-     -DCMAKE_C_COMPILER=$TARGET_C_COMPILER     \
-     -DCMAKE_CXX_COMPILER=$TARGET_CXX_COMPILER \
-     -DLLVM_LIBC_FULL_BUILD=ON                 \
-     -DLLVM_RUNTIMES_TARGET=$TARGET_TRIPLE     \
+     -G Ninja                                    \
+     -DLLVM_ENABLE_RUNTIMES=libc                 \
+     -DCMAKE_C_COMPILER=$TARGET_C_COMPILER       \
+     -DCMAKE_CXX_COMPILER=$TARGET_CXX_COMPILER   \
+     -DLLVM_LIBC_FULL_BUILD=ON                   \
+     -DLLVM_DEFAULT_TARGET_TRIPLE=$TARGET_TRIPLE \
      -DCMAKE_BUILD_TYPE=Release
   $> ninja install
 



More information about the llvm-commits mailing list