Skip to content

Commit ad6dbb9

Browse files
[CMake] [Shims] [Darwin] Support building with and for the new Apple SDKs
The Apple SDKs have been providing the Darwin overlay since macOS 10.14.4, iOS 12.2, et al. More recently the SDK version has diverged from the Swift version making them incompatible. Stop building the overlay from Swift. macOS 15.0, iOS 18.0, et al has started unconditionally declaring `lgamma_r` in <math.h>, add a __has_include in SwiftShims to detect that and not redeclare it when building against those SDK versions.
1 parent 2ec23ae commit ad6dbb9

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,16 @@ option(SWIFT_BUILD_CLANG_OVERLAYS
244244
"Build Swift overlays for the clang builtin modules"
245245
TRUE)
246246

247-
option(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY
248-
"Build dynamic variants of the Swift SDK overlay"
249-
TRUE)
247+
# The SDK overlay is provided by the SDK itself on Darwin platforms.
248+
if (SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
249+
option(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY
250+
"Build dynamic variants of the Swift SDK overlay"
251+
FALSE)
252+
else()
253+
option(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY
254+
"Build dynamic variants of the Swift SDK overlay"
255+
TRUE)
256+
endif()
250257

251258
option(SWIFT_BUILD_STATIC_SDK_OVERLAY
252259
"Build static variants of the Swift SDK overlay"

stdlib/public/SwiftShims/swift/shims/LibcShims.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,16 @@ long double _stdlib_squareRootl(long double _self) {
170170
// Apple's math.h does not declare lgamma_r() etc by default, but they're
171171
// unconditionally exported by libsystem_m.dylib in all OS versions that
172172
// support Swift development; we simply need to provide declarations here.
173-
#if defined(__APPLE__)
173+
// In the macOS 15.0, iOS 18.0, et al SDKs, math.h unconditionally declares
174+
// lgamma_r() when building for Swift. Detect those SDKs by checking for a
175+
// header which was added in those versions. (Redeclaring the function
176+
// would cause an error where `lgamma_r` is ambiguous between the SDK
177+
// `_math.lgamma_r` and this `SwiftShims.lgamma_r`.)
178+
#if defined(__APPLE__) && !__has_include(<_modules/_math_h.h>)
174179
float lgammaf_r(float x, int *psigngam);
175180
double lgamma_r(double x, int *psigngam);
176181
long double lgammal_r(long double x, int *psigngam);
177-
#endif // defined(__APPLE__)
182+
#endif // defined(__APPLE__) && !__has_include(<_modules/_math_h.h>)
178183

179184
#ifdef __cplusplus
180185
} // extern "C"

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import multiprocessing
1010
import os
11+
import platform
1112

1213
import android.adb.commands
1314

@@ -1136,7 +1137,7 @@ def create_argument_parser():
11361137
help='build static variants of the Swift standard library')
11371138

11381139
option('--build-swift-dynamic-sdk-overlay', toggle_true,
1139-
default=True,
1140+
default=platform.system() != "Darwin",
11401141
help='build dynamic variants of the Swift SDK overlay')
11411142

11421143
option('--build-swift-static-sdk-overlay', toggle_true,

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
import multiprocessing
11+
import platform
1112

1213
from build_swift import argparse
1314
from build_swift import defaults
@@ -79,7 +80,7 @@
7980
'build_runtime_with_host_compiler': False,
8081
'build_stdlib_deployment_targets': ['all'],
8182
'build_subdir': None,
82-
'build_swift_dynamic_sdk_overlay': True,
83+
'build_swift_dynamic_sdk_overlay': platform.system() != "Darwin",
8384
'build_swift_dynamic_stdlib': True,
8485
'build_swift_inspect': False,
8586
'build_swift_private_stdlib': True,

0 commit comments

Comments
 (0)