From 828269b7e68039f8bc0bdac66e2fd5c58b6d3471 Mon Sep 17 00:00:00 2001
Patch-Source: https://github.com/dotnet/runtime/pull/90251
From: Antoine Martin <dev@ayakael.net>
Date: Wed, 9 Aug 2023 11:36:39 -0400
Subject: [PATCH 1/1] Rename CMAKE var for mono on libc-musl

---
 src/mono/CMakeLists.txt           |  6 +++---
 src/mono/mono/mini/CMakeLists.txt | 12 ++++++------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/runtime/src/coreclr/pgosupport.cmake b/src/runtime/src/coreclr/pgosupport.cmake
index 719ac14ad99..34a42781ab2 100644
--- a/src/runtime/src/coreclr/pgosupport.cmake
+++ b/src/runtime/src/coreclr/pgosupport.cmake
@@ -25,13 +25,13 @@ function(add_pgo TargetName)
                 target_compile_options(${TargetName} PRIVATE -flto -fprofile-instr-generate)
                 set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -flto -fprofile-instr-generate")
                 if(CMAKE_CROSSCOMPILING AND CMAKE_C_COMPILER_ID MATCHES "Clang")
-                    if (CLR_CMAKE_HOST_ALPINE_LINUX)
+                    if (CLR_CMAKE_TARGET_LINUX_MUSL)
                         set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -resource-dir ${CMAKE_SYSROOT}/usr/lib/clang/${CMAKE_C_COMPILER_VERSION}")
-                    else(CLR_CMAKE_HOST_ALPINE_LINUX)
+                    else(CLR_CMAKE_TARGET_LINUX_MUSL)
                         string(REPLACE "." ";" CLANG_VERSION "${CMAKE_C_COMPILER_VERSION}")
                         list(POP_FRONT CLANG_VERSION CLANG_VERSION_MAJOR)
                         set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -resource-dir ${CMAKE_SYSROOT}/usr/lib/llvm-${CLANG_VERSION_MAJOR}/lib/clang/${CMAKE_C_COMPILER_VERSION}")
-                    endif(CLR_CMAKE_HOST_ALPINE_LINUX)
+                    endif(CLR_CMAKE_TARGET_LINUX_MUSL)
                 endif(CMAKE_CROSSCOMPILING AND CMAKE_C_COMPILER_ID MATCHES "Clang")
                 if(NOT LD_LLVM)
                     set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -fuse-ld=gold")
diff --git a/src/runtime/src/mono/CMakeLists.txt b/src/runtime/src/mono/CMakeLists.txt
index e04d9e9d364..00e54a25d69 100644
--- a/src/runtime/src/mono/CMakeLists.txt
+++ b/src/runtime/src/mono/CMakeLists.txt
@@ -943,10 +943,10 @@ else()
   set(DISABLE_DLLMAP 1)
 endif()
 
-if(CLR_CMAKE_HOST_ALPINE_LINUX)
-  # Setting RLIMIT_NOFILE breaks debugging of coreclr on Alpine Linux for some reason
+if(CLR_CMAKE_TARGET_LINUX_MUSL)
+  # Setting RLIMIT_NOFILE breaks debugging of coreclr on musl-libc for some reason
   add_definitions(-DDONT_SET_RLIMIT_NOFILE)
-  # On Alpine Linux, we need to ensure that the reported stack range for the primary thread is
+  # On musl-libc, we need to ensure that the reported stack range for the primary thread is
   # larger than the initial committed stack size.
   add_definitions(-DENSURE_PRIMARY_STACK_SIZE)
 endif()
diff --git a/src/runtime/src/mono/mono/mini/CMakeLists.txt.orig b/src/runtime/src/mono/mono/mini/CMakeLists.txt
index 5d6ef3d..c3e5414 100644
--- a/src/runtime/src/mono/mono/mini/CMakeLists.txt.orig
+++ b/src/runtime/src/mono/mono/mini/CMakeLists.txt
@@ -400,9 +400,9 @@ if(NOT DISABLE_SHARED_LIBS)
   endif()
   target_compile_definitions(monosgen-shared PRIVATE -DMONO_DLL_EXPORT)
   # Alpine Linux implements ucontext in a different library
-  if(CLR_CMAKE_HOST_ALPINE_LINUX AND TARGET_S390X)
+  if(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X)
     target_link_libraries(monosgen-shared PRIVATE ucontext)
-  endif(CLR_CMAKE_HOST_ALPINE_LINUX AND TARGET_S390X)
+  endif(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X)
   set_target_properties(monosgen-shared PROPERTIES OUTPUT_NAME ${MONO_SHARED_LIB_NAME})
   if(MONO_SET_RPATH_ORIGIN)
     set_target_properties(monosgen-shared PROPERTIES INSTALL_RPATH "$ORIGIN")
@@ -601,10 +601,10 @@ if(NOT DISABLE_EXECUTABLES)
     target_link_libraries(mono-sgen PRIVATE icu_shim_objects)
   endif()
   target_link_libraries(mono-sgen PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${ICU_LIBS} ${Z_LIBS})
-  # Alpine Linux implements ucontext in a different library
-  if(CLR_CMAKE_HOST_ALPINE_LINUX AND TARGET_S390X)
+  # musl-libc implements ucontext in a different library
+  if(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X)
     target_link_libraries(mono-sgen PRIVATE ucontext)
-  endif(CLR_CMAKE_HOST_ALPINE_LINUX AND TARGET_S390X)
+  endif(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X)
   if(NOT DISABLE_COMPONENTS AND STATIC_COMPONENTS AND NOT DISABLE_LINK_STATIC_COMPONENTS)
     # if components are built statically, link them into runtime.
     target_sources(mono-sgen PRIVATE "${mono-components-objects}")
