[Concurrency][Stdlib] Add SwiftStdlibCurrentOS availability, use it.

If you use SwiftStdlibCurrentOS availability, you will be able to
use new types and functions from within the implementation. This
works by, when appropriate, building with the CurrentOS availability
set to the current deployment target.

rdar://150944675
This commit is contained in:
Alastair Houghton
2025-05-09 16:53:19 +01:00
parent 0e6f3a8d54
commit 28f96e64ab
41 changed files with 416 additions and 266 deletions

View File

@@ -1003,6 +1003,25 @@ function(add_swift_target_library_single target name)
# Define availability macros.
foreach(def ${SWIFT_STDLIB_AVAILABILITY_DEFINITIONS})
list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS "-Xfrontend" "-define-availability" "-Xfrontend" "${def}")
if("${def}" MATCHES "SwiftStdlib .*")
# For each SwiftStdlib x.y, also define SwiftStdlibTargetOS x.y, which,
# will expand to the current `-target` platform if the macro defines a
# newer platform as its availability.
#
# There is a setting, SWIFT_STDLIB_ENABLE_STRICT_AVAILABILITY, which if set
# ON will cause us to use the "proper" availability instead.
string(REPLACE "SwiftStdlib" "SwiftStdlibCurrentOS" current "${def}")
if(NOT SWIFT_STDLIB_ENABLE_STRICT_AVAILABILITY AND SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_AVAILABILITY_NAME)
string(REGEX MATCH "${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_AVAILABILITY_NAME} ([0-9]+(\.[0-9]+)+)" platform_version "${def}")
string(REGEX MATCH "[0-9]+(\.[0-9]+)+" version "${platform_version}")
if(NOT version STREQUAL "9999" AND version VERSION_GREATER "${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_DEPLOYMENT_VERSION}")
string(REGEX REPLACE ":.*" ":${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_AVAILABILITY_NAME} ${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_DEPLOYMENT_VERSION}" current "${current}")
endif()
endif()
list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS "-Xfrontend" "-define-availability" "-Xfrontend" "${current}")
endif()
endforeach()
# Enable -target-min-inlining-version