https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/203504

>From cf0d18cf8da96251ad41785b5f97a3916220c862 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <[email protected]>
Date: Thu, 11 Jun 2026 20:34:18 +0200
Subject: [PATCH 1/7] runtimes: Pass CMAKE_SYSTEM_NAME based on target triple

Compute the cmake system name from the target triple, rather
than passing through the host's. This is primarily to stop
forwarding OSX specific cmake variables.

This fixes build failures when trying to build gpu libc on mac
hosts. Previously it would fail on several issues, starting with
an unused argument -mmacos-version-min error, followed by other
errors caused by passing -isysroot.

Secondarily, restrict the cmake imported targets when cross compiling.
Without this, the amdgpu build prints many cmake warnings about the
target not supporting shared libraries.

Claude did most of the actual work, though it required quite a few
rounds of prodding to get it into the right place. In particular it
took care of handling all of the cmake platform recognized names from
the triple.

Co-authored-by: Claude Opus 4.6 <[email protected]>
---
 clang/cmake/modules/ClangConfig.cmake.in      |  5 +-
 cmake/Modules/GetTripleCMakeSystemName.cmake  | 65 +++++++++++++++++
 llvm/cmake/modules/LLVMConfig.cmake.in        | 69 +++++++++----------
 .../modules/LLVMExternalProjectUtils.cmake    | 27 +++++++-
 llvm/runtimes/CMakeLists.txt                  |  4 --
 5 files changed, 126 insertions(+), 44 deletions(-)
 create mode 100644 cmake/Modules/GetTripleCMakeSystemName.cmake

diff --git a/clang/cmake/modules/ClangConfig.cmake.in 
b/clang/cmake/modules/ClangConfig.cmake.in
index 68f723d050117..e199c7e17b6b7 100644
--- a/clang/cmake/modules/ClangConfig.cmake.in
+++ b/clang/cmake/modules/ClangConfig.cmake.in
@@ -13,7 +13,10 @@ set(CLANG_LINK_CLANG_DYLIB "@CLANG_LINK_CLANG_DYLIB@")
 set(CLANG_DEFAULT_LINKER "@CLANG_DEFAULT_LINKER@")
 
 # Provide all our library targets to users.
-@CLANG_CONFIG_INCLUDE_EXPORTS@
+# Skip when cross-compiling, as host library targets are not usable.
+if(NOT CMAKE_CROSSCOMPILING)
+  @CLANG_CONFIG_INCLUDE_EXPORTS@
+endif()
 
 # By creating clang-tablegen-targets here, subprojects that depend on Clang's
 # tablegen-generated headers can always depend on this target whether building
diff --git a/cmake/Modules/GetTripleCMakeSystemName.cmake 
b/cmake/Modules/GetTripleCMakeSystemName.cmake
new file mode 100644
index 0000000000000..9bfb90d630387
--- /dev/null
+++ b/cmake/Modules/GetTripleCMakeSystemName.cmake
@@ -0,0 +1,65 @@
+#===--------------------------------------------------------------------===//
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for details.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+#===--------------------------------------------------------------------===//
+
+# Extract the OS component from a target triple and map it to the
+# corresponding CMake system name.
+#
+# Usage:
+#   get_triple_cmake_system_name(<triple> <out_var>)
+#
+# Parses the triple (arch-vendor-os[-env]) and sets <out_var> to the
+# CMake-style system name (e.g. "Darwin", "Linux", "Windows").
+# Unrecognized OS values are mapped to "Generic".
+
+function(get_triple_cmake_system_name triple out_var)
+  string(REPLACE "-" ";" _components "${triple}")
+  list(LENGTH _components _len)
+  if(_len LESS 3)
+    set(${out_var} "${CMAKE_HOST_SYSTEM_NAME}" PARENT_SCOPE)
+    return()
+  endif()
+
+  list(GET _components 1 _vendor)
+  list(GET _components 2 _os)
+
+  if("${_vendor}" STREQUAL "apple" OR "${_os}" MATCHES "^darwin|^macos")
+    set(${out_var} "Darwin" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^linux")
+    set(${out_var} "Linux" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^win32|^windows")
+    set(${out_var} "Windows" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^freebsd|^kfreebsd")
+    set(${out_var} "FreeBSD" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^fuchsia")
+    set(${out_var} "Fuchsia" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^netbsd")
+    set(${out_var} "NetBSD" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^openbsd")
+    set(${out_var} "OpenBSD" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^dragonfly")
+    set(${out_var} "DragonFly" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^solaris")
+    set(${out_var} "SunOS" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^aix")
+    set(${out_var} "AIX" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^haiku")
+    set(${out_var} "Haiku" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^wasi")
+    set(${out_var} "WASI" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^rtems")
+    set(${out_var} "RTEMS" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^zos")
+    set(${out_var} "OS390" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^hurd")
+    set(${out_var} "GNU" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^serenity")
+    set(${out_var} "SerenityOS" PARENT_SCOPE)
+  else()
+    set(${out_var} "Generic" PARENT_SCOPE)
+  endif()
+endfunction()
diff --git a/llvm/cmake/modules/LLVMConfig.cmake.in 
b/llvm/cmake/modules/LLVMConfig.cmake.in
index 300c25e7c6101..6ef0cef7d0296 100644
--- a/llvm/cmake/modules/LLVMConfig.cmake.in
+++ b/llvm/cmake/modules/LLVMConfig.cmake.in
@@ -56,52 +56,47 @@ set(LLVM_ENABLE_ASSERTIONS @LLVM_ENABLE_ASSERTIONS@)
 set(LLVM_ENABLE_EH @LLVM_ENABLE_EH@)
 
 set(LLVM_ENABLE_FFI @LLVM_ENABLE_FFI@)
-if(LLVM_ENABLE_FFI)
-  find_package(FFI)
-endif()
-
 set(LLVM_ENABLE_RTTI @LLVM_ENABLE_RTTI@)
-
-set(LLVM_ENABLE_LIBEDIT @HAVE_LIBEDIT@)
-if(LLVM_ENABLE_LIBEDIT)
-  find_package(LibEdit)
-endif()
-
 set(LLVM_ENABLE_THREADS @LLVM_ENABLE_THREADS@)
-
 set(LLVM_ENABLE_UNWIND_TABLES @LLVM_ENABLE_UNWIND_TABLES@)
-
 set(LLVM_ENABLE_ZLIB @LLVM_ENABLE_ZLIB@)
-if(LLVM_ENABLE_ZLIB)
-  set(ZLIB_ROOT @ZLIB_ROOT@)
-  find_package(ZLIB)
-endif()
-
 set(LLVM_ENABLE_ZSTD @LLVM_ENABLE_ZSTD@)
-if(LLVM_ENABLE_ZSTD)
-  find_package(zstd)
-endif()
-
 set(LLVM_ENABLE_LIBXML2 @LLVM_ENABLE_LIBXML2@)
-if(LLVM_ENABLE_LIBXML2)
-  find_package(LibXml2)
-endif()
-
 set(LLVM_ENABLE_CURL @LLVM_ENABLE_CURL@)
-if(LLVM_ENABLE_CURL)
-  find_package(CURL)
-endif()
-
 set(LLVM_ENABLE_HTTPLIB @LLVM_ENABLE_HTTPLIB@)
-if(LLVM_ENABLE_HTTPLIB)
-  find_package(httplib)
-endif()
-
 set(LLVM_WITH_Z3 @LLVM_WITH_Z3@)
-
 set(LLVM_ENABLE_DIA_SDK @LLVM_ENABLE_DIA_SDK@)
-if(LLVM_ENABLE_DIA_SDK)
-  find_package(DIASDK)
+set(LLVM_ENABLE_LIBEDIT @HAVE_LIBEDIT@)
+
+# These are host libraries that LLVM was built with. Only find them when the
+# consumer can actually use them (i.e. not when cross-compiling for an
+# incompatible target).
+if(NOT CMAKE_CROSSCOMPILING)
+  if(LLVM_ENABLE_FFI)
+    find_package(FFI)
+  endif()
+  if(LLVM_ENABLE_LIBEDIT)
+    find_package(LibEdit)
+  endif()
+  if(LLVM_ENABLE_ZLIB)
+    set(ZLIB_ROOT @ZLIB_ROOT@)
+    find_package(ZLIB)
+  endif()
+  if(LLVM_ENABLE_ZSTD)
+    find_package(zstd)
+  endif()
+  if(LLVM_ENABLE_LIBXML2)
+    find_package(LibXml2)
+  endif()
+  if(LLVM_ENABLE_CURL)
+    find_package(CURL)
+  endif()
+  if(LLVM_ENABLE_HTTPLIB)
+    find_package(httplib)
+  endif()
+  if(LLVM_ENABLE_DIA_SDK)
+    find_package(DIASDK)
+  endif()
 endif()
 
 set(LLVM_NATIVE_ARCH @LLVM_NATIVE_ARCH@)
@@ -152,7 +147,7 @@ set(LLVM_ENABLE_SHARED_LIBS @BUILD_SHARED_LIBS@)
 set(LLVM_DEFAULT_EXTERNAL_LIT "@LLVM_CONFIG_DEFAULT_EXTERNAL_LIT@")
 set(LLVM_LIT_ARGS "@LLVM_LIT_ARGS@")
 
-if(NOT TARGET LLVMSupport)
+if(NOT TARGET LLVMSupport AND NOT CMAKE_CROSSCOMPILING)
   @LLVM_CONFIG_INCLUDE_EXPORTS@
   @llvm_config_include_buildtree_only_exports@
 endif()
diff --git a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake 
b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
index 47b12dc9a3d8c..fcb7e3c32cc2e 100644
--- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
@@ -85,9 +85,16 @@ function(llvm_ExternalProject_Add name source_dir)
   endforeach()
 
   # If CMAKE_SYSTEM_NAME is not set explicitly in the arguments passed to us,
-  # reflect CMake's own default.
+  # derive it from the target triple if available, otherwise reflect CMake's
+  # own default. This ensures that cross-compilation targets get the correct
+  # platform files (e.g. AMDGPU targets on a Darwin host won't get macOS 
flags).
   if (NOT _cmake_system_name)
-    set(_cmake_system_name "${CMAKE_HOST_SYSTEM_NAME}")
+    if(ARG_TARGET_TRIPLE)
+      include(GetTripleCMakeSystemName)
+      get_triple_cmake_system_name("${ARG_TARGET_TRIPLE}" _cmake_system_name)
+    else()
+      set(_cmake_system_name "${CMAKE_HOST_SYSTEM_NAME}")
+    endif()
   endif()
 
   if(NOT ARG_TARGET_TRIPLE)
@@ -376,6 +383,22 @@ function(llvm_ExternalProject_Add name source_dir)
     list(APPEND compiler_args -DCMAKE_CXX_COMPILER_TARGET=${ARG_TARGET_TRIPLE})
     list(APPEND compiler_args 
-DCMAKE_Fortran_COMPILER_TARGET=${ARG_TARGET_TRIPLE})
     list(APPEND compiler_args -DCMAKE_ASM_COMPILER_TARGET=${ARG_TARGET_TRIPLE})
+
+    # Pass CMAKE_SYSTEM_NAME derived from the target triple so the sub-build
+    # loads the correct platform files instead of the host's.
+    if(NOT "${_cmake_system_name}" STREQUAL "${CMAKE_HOST_SYSTEM_NAME}")
+      list(APPEND compiler_args -DCMAKE_SYSTEM_NAME=${_cmake_system_name})
+    endif()
+
+    # Forward Darwin-specific variables only when targeting Darwin.
+    if("${_cmake_system_name}" STREQUAL "Darwin")
+      if(CMAKE_OSX_SYSROOT)
+        list(APPEND compiler_args -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT})
+      endif()
+      if(CMAKE_OSX_DEPLOYMENT_TARGET)
+        list(APPEND compiler_args 
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET})
+      endif()
+    endif()
   endif()
 
   if(CMAKE_VERBOSE_MAKEFILE)
diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index bbc91a709c553..ae08b5993412d 100644
--- a/llvm/runtimes/CMakeLists.txt
+++ b/llvm/runtimes/CMakeLists.txt
@@ -4,10 +4,6 @@
 # the two files.
 
 set(COMMON_CMAKE_ARGS 
"-DHAVE_LLVM_LIT=ON;-DCLANG_RESOURCE_DIR=${CLANG_RESOURCE_DIR}")
-if(APPLE AND CMAKE_OSX_SYSROOT AND (LLVM_TARGET_TRIPLE STREQUAL 
LLVM_HOST_TRIPLE))
-  # Only propagate the host sysroot for native runtimes builds.
-  list(APPEND RUNTIMES_CMAKE_ARGS "-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}")
-endif()
 foreach(proj ${LLVM_ENABLE_RUNTIMES})
   string(TOUPPER "${proj}" canon_name)
   STRING(REGEX REPLACE "-" "_" canon_name ${canon_name})

>From 0f7ed6ac48bd6934b8be3f1d77500e05b09d39ed Mon Sep 17 00:00:00 2001
From: Matt Arsenault <[email protected]>
Date: Fri, 12 Jun 2026 13:38:07 +0200
Subject: [PATCH 2/7] Handle mingw

---
 cmake/Modules/GetTripleCMakeSystemName.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmake/Modules/GetTripleCMakeSystemName.cmake 
b/cmake/Modules/GetTripleCMakeSystemName.cmake
index 9bfb90d630387..8ffb541abb1d5 100644
--- a/cmake/Modules/GetTripleCMakeSystemName.cmake
+++ b/cmake/Modules/GetTripleCMakeSystemName.cmake
@@ -31,7 +31,7 @@ function(get_triple_cmake_system_name triple out_var)
     set(${out_var} "Darwin" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^linux")
     set(${out_var} "Linux" PARENT_SCOPE)
-  elseif("${_os}" MATCHES "^win32|^windows")
+  elseif("${_os}" MATCHES "^win32|^windows|^mingw")
     set(${out_var} "Windows" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^freebsd|^kfreebsd")
     set(${out_var} "FreeBSD" PARENT_SCOPE)

>From e02a9deb15365caf725dbfb78ffff75c221ad88b Mon Sep 17 00:00:00 2001
From: Matt Arsenault <[email protected]>
Date: Fri, 12 Jun 2026 13:40:32 +0200
Subject: [PATCH 3/7] Handle more cases from the chart

---
 cmake/Modules/GetTripleCMakeSystemName.cmake | 23 +++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/cmake/Modules/GetTripleCMakeSystemName.cmake 
b/cmake/Modules/GetTripleCMakeSystemName.cmake
index 8ffb541abb1d5..2b03197ca9394 100644
--- a/cmake/Modules/GetTripleCMakeSystemName.cmake
+++ b/cmake/Modules/GetTripleCMakeSystemName.cmake
@@ -27,16 +27,29 @@ function(get_triple_cmake_system_name triple out_var)
   list(GET _components 1 _vendor)
   list(GET _components 2 _os)
 
-  if("${_vendor}" STREQUAL "apple" OR "${_os}" MATCHES "^darwin|^macos")
+  if("${_os}" MATCHES "^darwin|^macos")
+    set(${out_var} "Darwin" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^ios")
+    set(${out_var} "iOS" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^tvos")
+    set(${out_var} "tvOS" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^watchos")
+    set(${out_var} "watchOS" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^xros|^visionos")
+    set(${out_var} "visionOS" PARENT_SCOPE)
+  elseif("${_vendor}" STREQUAL "apple")
+    # Catch-all for other Apple triples (e.g. driverkit, bridgeos).
     set(${out_var} "Darwin" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^linux")
     set(${out_var} "Linux" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^win32|^windows|^mingw")
     set(${out_var} "Windows" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^cygwin")
+    set(${out_var} "CYGWIN" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^msys")
+    set(${out_var} "MSYS" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^freebsd|^kfreebsd")
     set(${out_var} "FreeBSD" PARENT_SCOPE)
-  elseif("${_os}" MATCHES "^fuchsia")
-    set(${out_var} "Fuchsia" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^netbsd")
     set(${out_var} "NetBSD" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^openbsd")
@@ -47,8 +60,12 @@ function(get_triple_cmake_system_name triple out_var)
     set(${out_var} "SunOS" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^aix")
     set(${out_var} "AIX" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^fuchsia")
+    set(${out_var} "Fuchsia" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^haiku")
     set(${out_var} "Haiku" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^emscripten")
+    set(${out_var} "Emscripten" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^wasi")
     set(${out_var} "WASI" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^rtems")

>From ba338cf9740e4b3a2a38170d1f108576fd67be63 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <[email protected]>
Date: Fri, 12 Jun 2026 22:23:34 +0200
Subject: [PATCH 4/7] Match android and cygwin from environment

---
 cmake/Modules/GetTripleCMakeSystemName.cmake | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/cmake/Modules/GetTripleCMakeSystemName.cmake 
b/cmake/Modules/GetTripleCMakeSystemName.cmake
index 2b03197ca9394..2bc3aad52e00b 100644
--- a/cmake/Modules/GetTripleCMakeSystemName.cmake
+++ b/cmake/Modules/GetTripleCMakeSystemName.cmake
@@ -26,8 +26,20 @@ function(get_triple_cmake_system_name triple out_var)
 
   list(GET _components 1 _vendor)
   list(GET _components 2 _os)
+  set(_env "")
+  if(_len GREATER_EQUAL 4)
+    list(GET _components 3 _env)
+  endif()
 
-  if("${_os}" MATCHES "^darwin|^macos")
+  # Check the special environment components first, since it can
+  # override the usual OS mapping.
+  if("${_env}" MATCHES "^android")
+    set(${out_var} "Android" PARENT_SCOPE)
+  elseif("${_env}" MATCHES "^cygnus|^cygwin")
+    set(${out_var} "CYGWIN" PARENT_SCOPE)
+  elseif("${_env}" MATCHES "^msys")
+    set(${out_var} "MSYS" PARENT_SCOPE)
+  elseif("${_os}" MATCHES "^darwin|^macos")
     set(${out_var} "Darwin" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^ios")
     set(${out_var} "iOS" PARENT_SCOPE)
@@ -44,10 +56,6 @@ function(get_triple_cmake_system_name triple out_var)
     set(${out_var} "Linux" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^win32|^windows|^mingw")
     set(${out_var} "Windows" PARENT_SCOPE)
-  elseif("${_os}" MATCHES "^cygwin")
-    set(${out_var} "CYGWIN" PARENT_SCOPE)
-  elseif("${_os}" MATCHES "^msys")
-    set(${out_var} "MSYS" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^freebsd|^kfreebsd")
     set(${out_var} "FreeBSD" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^netbsd")

>From 32fbf02a9de97cefcd6a7e3716e78b87194b9c80 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <[email protected]>
Date: Fri, 12 Jun 2026 23:31:25 +0200
Subject: [PATCH 5/7] Remove noncanonical matching

---
 cmake/Modules/GetTripleCMakeSystemName.cmake | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/cmake/Modules/GetTripleCMakeSystemName.cmake 
b/cmake/Modules/GetTripleCMakeSystemName.cmake
index 2bc3aad52e00b..6cd8d3c59324e 100644
--- a/cmake/Modules/GetTripleCMakeSystemName.cmake
+++ b/cmake/Modules/GetTripleCMakeSystemName.cmake
@@ -14,7 +14,8 @@
 #
 # Parses the triple (arch-vendor-os[-env]) and sets <out_var> to the
 # CMake-style system name (e.g. "Darwin", "Linux", "Windows").
-# Unrecognized OS values are mapped to "Generic".
+# Unrecognized OS values are mapped to "Generic". This expects a
+# normalized triple.
 
 function(get_triple_cmake_system_name triple out_var)
   string(REPLACE "-" ";" _components "${triple}")
@@ -35,10 +36,8 @@ function(get_triple_cmake_system_name triple out_var)
   # override the usual OS mapping.
   if("${_env}" MATCHES "^android")
     set(${out_var} "Android" PARENT_SCOPE)
-  elseif("${_env}" MATCHES "^cygnus|^cygwin")
+  elseif("${_env}" MATCHES "^cygnus")
     set(${out_var} "CYGWIN" PARENT_SCOPE)
-  elseif("${_env}" MATCHES "^msys")
-    set(${out_var} "MSYS" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^darwin|^macos")
     set(${out_var} "Darwin" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^ios")
@@ -54,7 +53,7 @@ function(get_triple_cmake_system_name triple out_var)
     set(${out_var} "Darwin" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^linux")
     set(${out_var} "Linux" PARENT_SCOPE)
-  elseif("${_os}" MATCHES "^win32|^windows|^mingw")
+  elseif("${_os}" MATCHES "^windows")
     set(${out_var} "Windows" PARENT_SCOPE)
   elseif("${_os}" MATCHES "^freebsd|^kfreebsd")
     set(${out_var} "FreeBSD" PARENT_SCOPE)

>From b2bc66b10364d5a4553245d79a97f02dcd639086 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <[email protected]>
Date: Sat, 13 Jun 2026 08:18:27 +0200
Subject: [PATCH 6/7] Use clang to canonicalize the triple

---
 cmake/Modules/NormalizeTriple.cmake           | 36 ++++++++++++++
 .../modules/LLVMExternalProjectUtils.cmake    | 47 ++++++++++++-------
 runtimes/CMakeLists.txt                       | 18 +------
 3 files changed, 67 insertions(+), 34 deletions(-)
 create mode 100644 cmake/Modules/NormalizeTriple.cmake

diff --git a/cmake/Modules/NormalizeTriple.cmake 
b/cmake/Modules/NormalizeTriple.cmake
new file mode 100644
index 0000000000000..08f09a22bdbb0
--- /dev/null
+++ b/cmake/Modules/NormalizeTriple.cmake
@@ -0,0 +1,36 @@
+#===--------------------------------------------------------------------===//
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for details.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+#===--------------------------------------------------------------------===//
+
+# Normalize a target triple using clang's -print-target-triple.
+#
+# Usage:
+#   normalize_triple(<compiler> <triple> <out_var>)
+#
+# Runs <compiler> --target=<triple> -print-target-triple to produce a
+# canonical triple. If the compiler invocation fails (e.g. the compiler
+# is not clang), <triple> is returned unchanged.
+
+function(normalize_triple compiler triple out_var)
+  set(_prefix "")
+  if(CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
+    set(_prefix "/clang:")
+  endif()
+  execute_process(
+    COMMAND "${compiler}" "${_prefix}--target=${triple}" 
"${_prefix}-print-target-triple"
+    RESULT_VARIABLE _result
+    OUTPUT_VARIABLE _output
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+    ERROR_QUIET)
+  if(_result EQUAL 0 AND _output)
+    set(${out_var} "${_output}" PARENT_SCOPE)
+  else()
+    # TODO(#97876): Report an error.
+    message(WARNING "Failed to execute `${compiler} 
${_prefix}--target=${triple} ${_prefix}-print-target-triple` to normalize 
target triple.")
+    set(${out_var} "${triple}" PARENT_SCOPE)
+  endif()
+endfunction()
diff --git a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake 
b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
index fcb7e3c32cc2e..3d32d3cb45d24 100644
--- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
@@ -84,27 +84,44 @@ function(llvm_ExternalProject_Add name source_dir)
     endif()
   endforeach()
 
+  if(NOT ARG_TARGET_TRIPLE)
+    set(target_triple ${LLVM_DEFAULT_TARGET_TRIPLE})
+  else()
+    set(target_triple ${ARG_TARGET_TRIPLE})
+  endif()
+
+  is_msvc_triple(is_msvc_target "${target_triple}")
+
+  if(ARG_USE_TOOLCHAIN AND NOT CMAKE_CROSSCOMPILING)
+    set(_cmake_c_compiler 
"${LLVM_RUNTIME_OUTPUT_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX}")
+    set(_cmake_cxx_compiler 
"${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++${CMAKE_EXECUTABLE_SUFFIX}")
+    set(_cmake_asm_compiler "${_cmake_c_compiler}")
+    if(is_msvc_target)
+      set(_cmake_c_compiler 
"${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX}")
+      set(_cmake_cxx_compiler "${_cmake_c_compiler}")
+      set(_cmake_asm_compiler "${_cmake_c_compiler}")
+    endif()
+  else()
+    set(_cmake_c_compiler "${CMAKE_C_COMPILER}")
+    set(_cmake_cxx_compiler "${CMAKE_CXX_COMPILER}")
+    set(_cmake_asm_compiler "${CMAKE_C_COMPILER}")
+  endif()
+
   # If CMAKE_SYSTEM_NAME is not set explicitly in the arguments passed to us,
   # derive it from the target triple if available, otherwise reflect CMake's
   # own default. This ensures that cross-compilation targets get the correct
   # platform files (e.g. AMDGPU targets on a Darwin host won't get macOS 
flags).
   if (NOT _cmake_system_name)
     if(ARG_TARGET_TRIPLE)
+      include(NormalizeTriple)
+      normalize_triple("${_cmake_c_compiler}" "${ARG_TARGET_TRIPLE}" 
_normalized_triple)
       include(GetTripleCMakeSystemName)
-      get_triple_cmake_system_name("${ARG_TARGET_TRIPLE}" _cmake_system_name)
+      get_triple_cmake_system_name("${_normalized_triple}" _cmake_system_name)
     else()
       set(_cmake_system_name "${CMAKE_HOST_SYSTEM_NAME}")
     endif()
   endif()
 
-  if(NOT ARG_TARGET_TRIPLE)
-    set(target_triple ${LLVM_DEFAULT_TARGET_TRIPLE})
-  else()
-    set(target_triple ${ARG_TARGET_TRIPLE})
-  endif()
-
-  is_msvc_triple(is_msvc_target "${target_triple}")
-
   if(NOT ARG_TOOLCHAIN_TOOLS)
     set(ARG_TOOLCHAIN_TOOLS clang)
     # AIX 64-bit XCOFF and big AR format is not yet supported in some of these 
tools.
@@ -235,15 +252,9 @@ function(llvm_ExternalProject_Add name source_dir)
 
   if(ARG_USE_TOOLCHAIN AND NOT CMAKE_CROSSCOMPILING)
     if(CLANG_IN_TOOLCHAIN)
-      if(is_msvc_target)
-        set(compiler_args 
-DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX}
-                          
-DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX}
-                          
-DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
-      else()
-        set(compiler_args 
-DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX}
-                          
-DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++${CMAKE_EXECUTABLE_SUFFIX}
-                          
-DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX})
-      endif()
+      set(compiler_args -DCMAKE_C_COMPILER=${_cmake_c_compiler}
+                        -DCMAKE_CXX_COMPILER=${_cmake_cxx_compiler}
+                        -DCMAKE_ASM_COMPILER=${_cmake_asm_compiler})
     endif()
     if(FLANG_IN_TOOLCHAIN)
       list(APPEND compiler_args 
-DCMAKE_Fortran_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/flang${CMAKE_EXECUTABLE_SUFFIX})
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index 0a84ef3957f76..36ebe594edc0d 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -228,22 +228,8 @@ message(STATUS "LLVM default target triple: 
${LLVM_DEFAULT_TARGET_TRIPLE}")
 set(LLVM_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
 
 if(CMAKE_C_COMPILER_ID MATCHES "Clang")
-  set(option_prefix "")
-  if (CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
-    set(option_prefix "/clang:")
-  endif()
-  set(print_target_triple ${CMAKE_C_COMPILER} 
${option_prefix}--target=${LLVM_DEFAULT_TARGET_TRIPLE} 
${option_prefix}-print-target-triple)
-  execute_process(COMMAND ${print_target_triple}
-    RESULT_VARIABLE result
-    OUTPUT_VARIABLE output
-    OUTPUT_STRIP_TRAILING_WHITESPACE)
-  if(result EQUAL 0)
-    set(LLVM_DEFAULT_TARGET_TRIPLE ${output})
-  else()
-    string(REPLACE ";" " " print_target_triple "${print_target_triple}")
-    # TODO(#97876): Report an error.
-    message(WARNING "Failed to execute `${print_target_triple}` to normalize 
target triple.")
-  endif()
+  include(NormalizeTriple)
+  normalize_triple("${CMAKE_C_COMPILER}" "${LLVM_DEFAULT_TARGET_TRIPLE}" 
LLVM_DEFAULT_TARGET_TRIPLE)
 endif()
 
 # Determine output and install paths based on LLVM_TARGET_TRIPLE

>From 6015c470900f16382d669b2050cc1ce00431752f Mon Sep 17 00:00:00 2001
From: Matt Arsenault <[email protected]>
Date: Sun, 14 Jun 2026 09:38:20 +0200
Subject: [PATCH 7/7] Remove LLVM-LIBC-FIXME XFAILs from tests that
 unexpectedly passed

---
 .../container.adaptors.format/format.functions.format.pass.cpp  | 2 --
 .../container.adaptors.format/format.functions.vformat.pass.cpp | 2 --
 .../format.range.fmtmap/format.functions.format.pass.cpp        | 2 --
 .../format.range.fmtmap/format.functions.vformat.pass.cpp       | 2 --
 .../format.range.fmtset/format.functions.format.pass.cpp        | 2 --
 .../format.range.fmtset/format.functions.vformat.pass.cpp       | 2 --
 .../format.range.fmtstr/format.functions.format.pass.cpp        | 2 --
 .../format.range.fmtstr/format.functions.vformat.pass.cpp       | 2 --
 .../format/format.range/format.range.fmtstr/format.pass.cpp     | 2 --
 .../format/format.range/format.range.fmtstr/parse.pass.cpp      | 2 --
 .../format.range.formatter/format.functions.format.pass.cpp     | 2 --
 .../format.range.formatter/format.functions.vformat.pass.cpp    | 2 --
 12 files changed, 24 deletions(-)

diff --git 
a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.format.pass.cpp
 
b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.format.pass.cpp
index 3f210aca6b436..17dce2e54ea3d 100644
--- 
a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.format.pass.cpp
+++ 
b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.format.pass.cpp
@@ -12,8 +12,6 @@
 
 // XFAIL: availability-fp_to_chars-missing
 
-// Missing mkstemp
-// XFAIL: LLVM-LIBC-FIXME
 
 // [container.adaptors.format]
 // For each of queue, priority_queue, and stack, the library provides the
diff --git 
a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.vformat.pass.cpp
 
b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.vformat.pass.cpp
index 21aab0a2c2f94..4b07dab790f92 100644
--- 
a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.vformat.pass.cpp
+++ 
b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.vformat.pass.cpp
@@ -12,8 +12,6 @@
 
 // XFAIL: availability-fp_to_chars-missing
 
-// Missing mkstemp
-// XFAIL: LLVM-LIBC-FIXME
 
 // [container.adaptors.format]
 // For each of queue, priority_queue, and stack, the library provides the
diff --git 
a/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.format.pass.cpp
 
b/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.format.pass.cpp
index e6691a57f2d11..830ad92d89321 100644
--- 
a/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.format.pass.cpp
+++ 
b/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.format.pass.cpp
@@ -12,8 +12,6 @@
 
 // XFAIL: availability-fp_to_chars-missing
 
-// Missing mkstemp
-// XFAIL: LLVM-LIBC-FIXME
 
 // <format>
 
diff --git 
a/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.vformat.pass.cpp
 
b/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.vformat.pass.cpp
index 1529b6ee65beb..41281a6eca458 100644
--- 
a/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.vformat.pass.cpp
+++ 
b/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.vformat.pass.cpp
@@ -12,8 +12,6 @@
 
 // XFAIL: availability-fp_to_chars-missing
 
-// Missing mkstemp
-// XFAIL: LLVM-LIBC-FIXME
 
 // <format>
 
diff --git 
a/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.format.pass.cpp
 
b/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.format.pass.cpp
index 0f92158fffe5c..7ab0a30af76e4 100644
--- 
a/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.format.pass.cpp
+++ 
b/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.format.pass.cpp
@@ -12,8 +12,6 @@
 
 // XFAIL: availability-fp_to_chars-missing
 
-// Missing mkstemp
-// XFAIL: LLVM-LIBC-FIXME
 
 // <format>
 
diff --git 
a/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.vformat.pass.cpp
 
b/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.vformat.pass.cpp
index 9a4a0f763b707..e591b8178a905 100644
--- 
a/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.vformat.pass.cpp
+++ 
b/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.vformat.pass.cpp
@@ -12,8 +12,6 @@
 
 // XFAIL: availability-fp_to_chars-missing
 
-// Missing mkstemp
-// XFAIL: LLVM-LIBC-FIXME
 
 // <format>
 
diff --git 
a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.format.pass.cpp
 
b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.format.pass.cpp
index f003123a417be..7d44f9554539f 100644
--- 
a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.format.pass.cpp
+++ 
b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.format.pass.cpp
@@ -12,8 +12,6 @@
 
 // XFAIL: availability-fp_to_chars-missing
 
-// Missing mkstemp
-// XFAIL: LLVM-LIBC-FIXME
 
 // <format>
 
diff --git 
a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.vformat.pass.cpp
 
b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.vformat.pass.cpp
index 9a464e6e38d13..d08e8658f1e10 100644
--- 
a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.vformat.pass.cpp
+++ 
b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.functions.vformat.pass.cpp
@@ -12,8 +12,6 @@
 
 // XFAIL: availability-fp_to_chars-missing
 
-// Missing mkstemp
-// XFAIL: LLVM-LIBC-FIXME
 
 // <format>
 
diff --git 
a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.pass.cpp
 
b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.pass.cpp
index 3b8dea6031470..bd71bd4c3b0b4 100644
--- 
a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.pass.cpp
+++ 
b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/format.pass.cpp
@@ -8,8 +8,6 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
 
-// Missing mkstemp
-// XFAIL: LLVM-LIBC-FIXME
 
 // <format>
 
diff --git 
a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/parse.pass.cpp
 
b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/parse.pass.cpp
index 54332754de6f6..ae85301d91434 100644
--- 
a/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/parse.pass.cpp
+++ 
b/libcxx/test/std/utilities/format/format.range/format.range.fmtstr/parse.pass.cpp
@@ -8,8 +8,6 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
 
-// Missing mkstemp
-// XFAIL: LLVM-LIBC-FIXME
 
 // <format>
 
diff --git 
a/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.format.pass.cpp
 
b/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.format.pass.cpp
index eb267637a0411..f1a9cd8178ab7 100644
--- 
a/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.format.pass.cpp
+++ 
b/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.format.pass.cpp
@@ -12,8 +12,6 @@
 
 // XFAIL: availability-fp_to_chars-missing
 
-// Missing mkstemp
-// XFAIL: LLVM-LIBC-FIXME
 
 // <format>
 
diff --git 
a/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.vformat.pass.cpp
 
b/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.vformat.pass.cpp
index 9d206312f3c75..5412a47cd7e35 100644
--- 
a/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.vformat.pass.cpp
+++ 
b/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.vformat.pass.cpp
@@ -12,8 +12,6 @@
 
 // XFAIL: availability-fp_to_chars-missing
 
-// Missing mkstemp
-// XFAIL: LLVM-LIBC-FIXME
 
 // <format>
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to