From 60cd288acdf48e3cd3f19eccf776e8fe23fcc04f Mon Sep 17 00:00:00 2001
From: "Kirill A. Korinsky" <kirill@korins.ky>
Date: Wed, 17 Aug 2022 16:09:26 +0200
Subject: [PATCH] [compiler-rt] allow to define required archs

---
 compiler-rt/cmake/builtin-config-ix.cmake | 18 ++++++++++--------
 compiler-rt/cmake/config-ix.cmake         |  8 ++++++--
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/compiler-rt/cmake/builtin-config-ix.cmake b/compiler-rt/cmake/builtin-config-ix.cmake
index 8de901513beb..904d8ca93fca 100644
--- a/compiler-rt/cmake/builtin-config-ix.cmake
+++ b/compiler-rt/cmake/builtin-config-ix.cmake
@@ -84,14 +84,16 @@ if(APPLE)
   set(DARWIN_osx_BUILTIN_MIN_VER 10.5)
   set(DARWIN_osx_BUILTIN_MIN_VER_FLAG
       -mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER})
-  set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
-  # Add support for arm64 macOS if available in SDK.
-  foreach(arch ${ARM64})
-    sdk_has_arch_support(${DARWIN_osx_SYSROOT} macosx ${arch} MACOS_ARM_SUPPORT)
-    if (MACOS_ARM_SUPPORT)
-     list(APPEND DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${arch})
-    endif()
-  endforeach(arch)
+  if(NOT DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS)
+    set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
+    # Add support for arm64 macOS if available in SDK.
+    foreach(arch ${ARM64})
+      sdk_has_arch_support(${DARWIN_osx_SYSROOT} macosx ${arch} MACOS_ARM_SUPPORT)
+      if (MACOS_ARM_SUPPORT)
+        list(APPEND DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${arch})
+      endif()
+    endforeach(arch)
+  endif()
 
   if(COMPILER_RT_ENABLE_IOS)
     list(APPEND DARWIN_EMBEDDED_PLATFORMS ios)
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index 0e035afb9f10..67d8d64da790 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -431,8 +431,12 @@ if(APPLE)
     list(APPEND DARWIN_osx_LINK_FLAGS -isysroot ${DARWIN_osx_SYSROOT})
   endif()
 
-  # Figure out which arches to use for each OS
-  darwin_get_toolchain_supported_archs(toolchain_arches)
+  if(COMPILER_RT_TOOLCHAIN_ARCHES)
+    set(toolchain_arches ${COMPILER_RT_TOOLCHAIN_ARCHES})
+  else()
+    # Figure out which arches to use for each OS
+    darwin_get_toolchain_supported_archs(toolchain_arches)
+  endif()
   message(STATUS "Toolchain supported arches: ${toolchain_arches}")
 
   if(NOT MACOSX_VERSION_MIN_FLAG)
-- 
2.37.2

