Skip to content

Commit aa0f8e6

Browse files
authored
Add a SWIFT_STDLIB_OS_VERSIONING flag to avoid querying OS version at runtime, use it in the freestanding build (swiftlang#33791)
1 parent 9fb7769 commit aa0f8e6

File tree

8 files changed

+19
-4
lines changed

8 files changed

+19
-4
lines changed

stdlib/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ option(SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
2525
"Build the standard libraries assuming that they will be used in an environment with only a single thread."
2626
FALSE)
2727

28+
option(SWIFT_STDLIB_OS_VERSIONING
29+
"Build stdlib with availability based on OS versions (Darwin only)."
30+
TRUE)
31+
2832
#
2933
# End of user-configurable options.
3034
#

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ function(_add_target_variant_c_compile_flags)
313313
list(APPEND result "-DSWIFT_STDLIB_SINGLE_THREADED_RUNTIME")
314314
endif()
315315

316+
if(SWIFT_STDLIB_OS_VERSIONING)
317+
list(APPEND result "-DSWIFT_RUNTIME_OS_VERSIONING")
318+
endif()
319+
316320
set("${CFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE)
317321
endfunction()
318322

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ function(_add_target_variant_swift_compile_flags
264264
list(APPEND result "-D" "SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING")
265265
endif()
266266

267+
if(SWIFT_STDLIB_OS_VERSIONING)
268+
list(APPEND result "-D" "SWIFT_RUNTIME_OS_VERSIONING")
269+
endif()
270+
267271
set("${result_var_name}" "${result}" PARENT_SCOPE)
268272
endfunction()
269273

stdlib/public/core/Availability.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public func _stdlib_isOSVersionAtLeast(
2424
_ minor: Builtin.Word,
2525
_ patch: Builtin.Word
2626
) -> Builtin.Int1 {
27-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
27+
#if (os(macOS) || os(iOS) || os(tvOS) || os(watchOS)) && SWIFT_RUNTIME_OS_VERSIONING
2828
if Int(major) == 9999 {
2929
return true._value
3030
}
@@ -43,7 +43,7 @@ public func _stdlib_isOSVersionAtLeast(
4343
#endif
4444
}
4545

46-
#if os(macOS)
46+
#if os(macOS) && SWIFT_RUNTIME_OS_VERSIONING
4747
// This is a magic entry point known to the compiler. It is called in
4848
// generated code for API availability checking.
4949
@_semantics("availability.osversion")

stdlib/public/runtime/BackDeployment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "../SwiftShims/FoundationShims.h"
1616
#include <stdlib.h>
1717

18-
#if defined(__APPLE__) && defined(__MACH__)
18+
#if defined(__APPLE__) && defined(__MACH__) && defined(SWIFT_RUNTIME_OS_VERSIONING)
1919

2020
#if SWIFT_CLASS_IS_SWIFT_MASK_GLOBAL_VARIABLE
2121
static unsigned long long computeIsSwiftMask() {

stdlib/public/stubs/Availability.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "swift/Runtime/Config.h"
1818

19-
#if SWIFT_OBJC_INTEROP
19+
#if SWIFT_OBJC_INTEROP && defined(SWIFT_RUNTIME_OS_VERSIONING)
2020
#include "swift/Basic/Lazy.h"
2121
#include "swift/Runtime/Debug.h"
2222
#include <TargetConditionals.h>

utils/build-presets.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,6 +2455,7 @@ swift-objc-interop=0
24552455
swift-enable-compatibility-overrides=0
24562456
swift-runtime-macho-no-dyld=1
24572457
swift-stdlib-single-threaded-runtime=1
2458+
swift-stdlib-os-versioning=0
24582459

24592460
[preset: stdlib_S_standalone_minimal_macho_x86_64,build]
24602461
mixin-preset=

utils/build-script-impl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ KNOWN_SETTINGS=(
196196
swift-enable-compatibility-overrides "1" "whether to support back-deploying compatibility fixes for newer apps running on older runtimes"
197197
swift-runtime-macho-no-dyld "0" "whether to build stdlib assuming the runtime environment does not support dynamic modules"
198198
swift-stdlib-single-threaded-runtime "0" "whether to build stdlib as a single-threaded runtime only"
199+
swift-stdlib-os-versioning "1" "whether to build stdlib with availability based on OS versions (Darwin only)"
199200

200201
## FREESTANDING Stdlib Options
201202
swift-freestanding-sdk "" "which SDK to use when building the FREESTANDING stdlib"
@@ -1776,6 +1777,7 @@ for host in "${ALL_HOSTS[@]}"; do
17761777
-DSWIFT_STDLIB_SINGLE_THREADED_RUNTIME:BOOL=$(true_false "${SWIFT_STDLIB_SINGLE_THREADED_RUNTIME}")
17771778
-DSWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS:BOOL=$(true_false "${SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS}")
17781779
-DSWIFT_RUNTIME_MACHO_NO_DYLD:BOOL=$(true_false "${SWIFT_RUNTIME_MACHO_NO_DYLD}")
1780+
-DSWIFT_STDLIB_OS_VERSIONING:BOOL=$(true_false "${SWIFT_STDLIB_OS_VERSIONING}")
17791781
-DSWIFT_NATIVE_LLVM_TOOLS_PATH:STRING="${native_llvm_tools_path}"
17801782
-DSWIFT_NATIVE_CLANG_TOOLS_PATH:STRING="${native_clang_tools_path}"
17811783
-DSWIFT_NATIVE_SWIFT_TOOLS_PATH:STRING="${native_swift_tools_path}"

0 commit comments

Comments
 (0)