Skip to content

Commit c48fff0

Browse files
authored
Merge pull request #5060 from etcwilde/ewilde/im-bringing-musl-back
Fixing post-swift-foundation corelibs-foundation static SDK builds
2 parents 1ff9114 + d00e2a6 commit c48fff0

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

CMakeLists.txt

+21
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,29 @@ endif()
8787
FetchContent_MakeAvailable(SwiftFoundationICU SwiftFoundation)
8888

8989
include(CheckLinkerFlag)
90+
include(CheckSymbolExists)
9091

9192
check_linker_flag(C "LINKER:--build-id=sha1" LINKER_SUPPORTS_BUILD_ID)
9293

94+
# Detect if the system libc defines symbols for these functions.
95+
# If it is not availble, swift-corelibs-foundation has its own implementations
96+
# that will be used. If it is available, it should not redefine them.
97+
# Note: SwiftPM does not have the ability to introspect the contents of the SDK
98+
# and therefore will always include these functions in the build and will
99+
# cause build failures on platforms that define these functions.
100+
check_symbol_exists("strlcat" "string.h" HAVE_STRLCAT)
101+
check_symbol_exists("strlcpy" "string.h" HAVE_STRLCPY)
102+
check_symbol_exists("issetugid" "unistd.h" HAVE_ISSETUGID)
103+
add_compile_definitions(
104+
$<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_STRLCAT}>>:HAVE_STRLCAT>
105+
$<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_STRLCPY}>>:HAVE_STRLCPY>
106+
$<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_ISSETUGID}>>:HAVE_ISSETUGID>)
107+
108+
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
109+
check_symbol_exists(sched_getaffinity "sched.h" HAVE_SCHED_GETAFFINITY)
110+
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:HAVE_SCHED_GETAFFINITY>)
111+
endif()
112+
93113
# Precompute module triple for installation
94114
if(NOT SwiftFoundation_MODULE_TRIPLE)
95115
set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info)
@@ -103,6 +123,7 @@ if(NOT SwiftFoundation_MODULE_TRIPLE)
103123
endif()
104124

105125
# System dependencies
126+
find_package(LibRT)
106127
find_package(dispatch CONFIG)
107128
if(NOT dispatch_FOUND)
108129
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")

Sources/Foundation/Port.swift

+6
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM.rawValue)
113113
fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP)
114114
#endif
115115

116+
#if canImport(Musl)
117+
import Musl
118+
fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM)
119+
fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP)
120+
#endif
121+
116122
#if canImport(Glibc) && os(Android) || os(OpenBSD)
117123
import Glibc
118124
fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM)

cmake/modules/FindLibRT.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Find librt library and headers.
66
#
7-
# The mdoule defines the following variables:
7+
# The module defines the following variables:
88
#
99
# ::
1010
#

0 commit comments

Comments
 (0)