From b3d92a2410ee84a02e07a0d65635c499629c5abf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Thu, 17 Sep 2026 10:01:37 +0200 Subject: [PATCH] [release/10.0] Unify native API availability probes Backport e83e69b64f77ecdfabe2e2a97fe8eb8192ea0259 (#134073), adapting the PAL probe because the earlier pipe2 fix is absent. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: efb15d16-e184-4ac5-9673-69a0e061f9bb --- eng/native/configurecompiler.cmake | 10 ++++++++++ src/coreclr/pal/src/configure.cmake | 8 +++++++- .../external/libunwind_extras/configure.cmake | 8 ++++++-- src/native/libs/configure.cmake | 13 ++++--------- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 95641492aaaf54..ede3d895f7fffa 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -17,6 +17,16 @@ include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) include(CheckLinkerFlag) +# Apple platforms like macOS/iOS allow targeting older operating system versions with a single SDK, +# so the mere presence of a symbol in the SDK does not tell us whether the deployment target supports it. +# The compiler warns when using an API unavailable at the deployment target. Turn that into an error +# for feature probes via CMAKE_REQUIRED_FLAGS, so check_symbol_exists() and other compile checks +# correctly identify whether the API is supported on the target. +check_c_compiler_flag("-Werror=unguarded-availability" COMPILER_SUPPORTS_W_ERROR_UNGUARDED_AVAILABILITY) +if(COMPILER_SUPPORTS_W_ERROR_UNGUARDED_AVAILABILITY) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unguarded-availability") +endif() + # "configureoptimization.cmake" must be included after CLR_CMAKE_HOST_UNIX has been set. include(${CMAKE_CURRENT_LIST_DIR}/configureoptimization.cmake) diff --git a/src/coreclr/pal/src/configure.cmake b/src/coreclr/pal/src/configure.cmake index 3d89ba2f593a13..958ad2b82be067 100644 --- a/src/coreclr/pal/src/configure.cmake +++ b/src/coreclr/pal/src/configure.cmake @@ -7,6 +7,7 @@ include(CheckIncludeFiles) include(CheckStructHasMember) include(CheckTypeSize) include(CheckLibraryExists) +include(CMakePushCheckState) if(CLR_CMAKE_TARGET_FREEBSD) set(CMAKE_REQUIRED_INCLUDES ${CROSS_ROOTFS}/usr/local/include) @@ -140,7 +141,12 @@ check_function_exists(directio HAVE_DIRECTIO) check_function_exists(semget HAS_SYSV_SEMAPHORES) check_function_exists(pthread_mutex_init HAS_PTHREAD_MUTEXES) check_function_exists(ttrace HAVE_TTRACE) -check_function_exists(pipe2 HAVE_PIPE2) + +cmake_push_check_state() +list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) +check_symbol_exists(pipe2 unistd.h HAVE_PIPE2) +cmake_pop_check_state() + check_function_exists(strerrorname_np HAVE_STRERRORNAME_NP) check_cxx_source_compiles(" diff --git a/src/native/external/libunwind_extras/configure.cmake b/src/native/external/libunwind_extras/configure.cmake index c95dfbefc84996..3dffe2e4ce660a 100644 --- a/src/native/external/libunwind_extras/configure.cmake +++ b/src/native/external/libunwind_extras/configure.cmake @@ -1,6 +1,7 @@ include(CheckCSourceCompiles) include(CheckIncludeFiles) -include(CheckFunctionExists) +include(CheckSymbolExists) +include(CMakePushCheckState) if(CLR_CMAKE_HOST_WIN32) # Our posix abstraction layer will provide these headers @@ -36,7 +37,10 @@ endif(CLR_CMAKE_HOST_WIN32) check_include_files(link.h HAVE_LINK_H) check_include_files(sys/link.h HAVE_SYS_LINK_H) -check_function_exists(pipe2 HAVE_PIPE2) +cmake_push_check_state() +list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) +check_symbol_exists(pipe2 unistd.h HAVE_PIPE2) +cmake_pop_check_state() check_c_source_compiles(" int main(int argc, char **argv) diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index 1f3aeca478ed2b..d590bb9096e2cf 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -8,6 +8,7 @@ include(CheckSymbolExists) include(CheckTypeSize) include(CheckLibraryExists) include(CheckFunctionExists) +include(CMakePushCheckState) if (CLR_CMAKE_TARGET_APPLE) # Xcode's clang does not include /usr/local/include by default, but brew's does. @@ -38,15 +39,6 @@ if (CMAKE_C_COMPILER_ID MATCHES "Clang") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wno-error=builtin-requires-header") endif() -# Apple platforms like macOS/iOS allow targeting older operating system versions with a single SDK, -# the mere presence of a symbol in the SDK doesn't tell us whether the deployment target really supports it. -# The compiler raises a warning when using an unsupported API, turn that into an error so check_symbol_exists() -# can correctly identify whether the API is supported on the target. -check_c_compiler_flag("-Wunguarded-availability" "C_SUPPORTS_WUNGUARDED_AVAILABILITY") -if(C_SUPPORTS_WUNGUARDED_AVAILABILITY) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wunguarded-availability") -endif() - # in_pktinfo: Find whether this struct exists check_include_files( "sys/socket.h;linux/in.h" @@ -193,10 +185,13 @@ check_symbol_exists( unistd.h HAVE_PIPE) +cmake_push_check_state() +list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) check_symbol_exists( pipe2 unistd.h HAVE_PIPE2) +cmake_pop_check_state() check_symbol_exists( getmntinfo