Skip to content

Commit e0f1615

Browse files
authored
Merge pull request #5069 from etcwilde/ewilde/main-musl-builds
[main] Fixing post-swift-foundation corelibs-foundation MUSL static SDK builds
2 parents 2973067 + b22db59 commit e0f1615

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
@@ -95,9 +95,29 @@ endif()
9595
FetchContent_MakeAvailable(SwiftFoundationICU SwiftFoundation)
9696

9797
include(CheckLinkerFlag)
98+
include(CheckSymbolExists)
9899

99100
check_linker_flag(C "LINKER:--build-id=sha1" LINKER_SUPPORTS_BUILD_ID)
100101

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

115135
# We know libdispatch is always unavailable on WASI
116136
if(NOT CMAKE_SYSTEM_NAME STREQUAL WASI)
137+
find_package(LibRT)
117138
find_package(dispatch CONFIG)
118139
if(NOT dispatch_FOUND)
119140
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)