From 01ea5e2ad81aec4c55f1a7350a7cf28abce2cda4 Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Wed, 23 Oct 2024 15:31:13 -0700 Subject: [PATCH] Fix module ownership of pthread.h + CoreFoundation --- CMakeLists.txt | 20 ++++++++++++++++--- Sources/CoreFoundation/include/CFPriv.h | 3 --- .../include/ForSwiftFoundationOnly.h | 4 ++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa842040f1..ae410b09f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,15 +120,25 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux) endif() # Precompute module triple for installation -if(NOT SwiftFoundation_MODULE_TRIPLE) +if(NOT SwiftFoundation_MODULE_TRIPLE OR NOT SwiftFoundation_GLIBC_MODULE_PATHS) set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info) if(CMAKE_Swift_COMPILER_TARGET) list(APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET}) endif() execute_process(COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json) string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple") - set(SwiftFoundation_MODULE_TRIPLE "${module_triple}" CACHE STRING "swift module triple used for installed swiftmodule and swiftinterface files") - mark_as_advanced(SwiftFoundation_MODULE_TRIPLE) + if (NOT SwiftFoundation_GLIBC_MODULE_PATHS) + string(JSON glibc_module_path_length LENGTH "${target_info_json}" "paths" "runtimeLibraryImportPaths") + MATH(EXPR glibc_module_path_length "${glibc_module_path_length} - 1") + foreach(i RANGE ${glibc_module_path_length}) + string(JSON value GET "${target_info_json}" "paths" "runtimeLibraryImportPaths" ${i}) + list(APPEND SwiftFoundation_GLIBC_MODULE_PATHS "${value}") + endforeach() + endif() + if(NOT SwiftFoundation_MODULE_TRIPLE) + set(SwiftFoundation_MODULE_TRIPLE "${module_triple}" CACHE STRING "swift module triple used for installed swiftmodule and swiftinterface files") + mark_as_advanced(SwiftFoundation_MODULE_TRIPLE) + endif() endif() # System dependencies @@ -171,6 +181,10 @@ list(APPEND _Foundation_common_build_flags "-Wno-switch" "-fblocks") +foreach(path ${SwiftFoundation_GLIBC_MODULE_PATHS}) + list(APPEND _Foundation_common_build_flags "-I${path}") +endforeach() + if(NOT CMAKE_SYSTEM_NAME STREQUAL "WASI") list(APPEND _Foundation_common_build_flags "-DDEPLOYMENT_ENABLE_LIBDISPATCH" diff --git a/Sources/CoreFoundation/include/CFPriv.h b/Sources/CoreFoundation/include/CFPriv.h index b9a025d06f..67f853560e 100644 --- a/Sources/CoreFoundation/include/CFPriv.h +++ b/Sources/CoreFoundation/include/CFPriv.h @@ -592,9 +592,6 @@ CF_EXPORT CFMessagePortRef _CFMessagePortCreateLocalEx(CFAllocatorRef allocator, #if __has_include() #include #endif -#if _POSIX_THREADS -#include -#endif #include CF_INLINE CFAbsoluteTime _CFAbsoluteTimeFromFileTimeSpec(struct timespec ts) { diff --git a/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h b/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h index f3c7f51bb2..40c324b7ac 100644 --- a/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h +++ b/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h @@ -44,6 +44,10 @@ #include #endif #if _POSIX_THREADS +#if __has_include() +// Import SwiftGlibc.h before pthread.h (when available) to ensure the compiler understands that pthread.h is not owned by CoreFoundation +#include +#endif #include #endif #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__wasi__)