Skip to content

Commit 2732765

Browse files
committed
[CMake] Introduce availability macros for all known stdlib releases
Introduce "SwiftStdlib x.y"-style availability macros for all known releases of the stdlib, adding them to the swift flags of all Swift libraries and tests.
1 parent 5e78c3b commit 2732765

File tree

7 files changed

+25
-12
lines changed

7 files changed

+25
-12
lines changed

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,18 @@ if(SWIFT_ENABLE_DISPATCH AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
525525
endif()
526526
endif()
527527

528+
set(SWIFT_STDLIB_AVAILABILITY_DEFINITIONS
529+
"SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2"
530+
"SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0"
531+
"SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4"
532+
"SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0"
533+
"SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5"
534+
"SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0"
535+
"SwiftStdlib 5.6:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999"
536+
"SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999" # Unknown future release
537+
CACHE STRING
538+
"Availability macros for stdlib versions")
539+
528540
#
529541
# Include CMake modules
530542
#

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,11 @@ function(add_swift_target_library name)
17221722
"Either SHARED, STATIC, or OBJECT_LIBRARY must be specified")
17231723
endif()
17241724

1725+
# Define availability macros.
1726+
foreach(def ${SWIFT_STDLIB_AVAILABILITY_DEFINITIONS})
1727+
list(APPEND SWIFTLIB_SWIFT_COMPILE_FLAGS "-Xfrontend" "-define-availability" "-Xfrontend" "${def}")
1728+
endforeach()
1729+
17251730
# In the standard library and overlays, warn about implicit overrides
17261731
# as a reminder to consider when inherited protocols need different
17271732
# behavior for their requirements.

stdlib/private/StdlibUnittest/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ add_swift_target_library(swiftStdlibUnittest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES}
5555
SWIFT_MODULE_DEPENDS_HAIKU Glibc
5656
SWIFT_MODULE_DEPENDS_WINDOWS CRT WinSDK
5757
SWIFT_COMPILE_FLAGS ${swift_stdlib_unittest_compile_flags} ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
58-
-Xfrontend -define-availability
59-
-Xfrontend "SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0"
6058
INSTALL_IN_COMPONENT stdlib-experimental
6159
DARWIN_INSTALL_NAME_DIR "${SWIFT_DARWIN_STDLIB_PRIVATE_INSTALL_NAME_DIR}"
6260
LINK_LIBRARIES ${swift_stdlib_unittest_link_libraries})

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
127127
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
128128
-parse-stdlib
129129
-Xfrontend -enable-experimental-concurrency
130-
-Xfrontend -define-availability
131-
-Xfrontend "SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0"
132130
${SWIFT_RUNTIME_CONCURRENCY_SWIFT_FLAGS}
133131
${swift_concurrency_options}
134132
INSTALL_IN_COMPONENT ${swift_concurrency_install_component}

stdlib/public/Distributed/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ add_swift_target_library(swift_Distributed ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
3434
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
3535
-parse-stdlib
3636
-Xfrontend -enable-experimental-distributed
37-
-Xfrontend -define-availability
38-
-Xfrontend "SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0"
39-
-Xfrontend -define-availability
40-
-Xfrontend "SwiftStdlib 5.6:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999"
4137
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
4238

4339
SWIFT_MODULE_DEPENDS _Concurrency

test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ foreach(SDK ${SWIFT_SDKS})
385385
list(APPEND LIT_ARGS "--param" "distributed")
386386
endif()
387387

388+
# Define availability macros, escaping semicolons to get around CMake
389+
string(REPLACE ";" "\\$<SEMICOLON>" availability_defs "${SWIFT_STDLIB_AVAILABILITY_DEFINITIONS}")
390+
list(APPEND LIT_ARGS "--param" "availability_macros=${availability_defs}")
391+
388392
foreach(test_subset ${TEST_SUBSETS})
389393
set(directories)
390394
set(dependencies ${test_dependencies})

test/lit.cfg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,10 @@ swift_version = lit_config.params.get('swift-version',
431431
lit_config.note('Compiling with -swift-version ' + swift_version)
432432
config.swift_test_options = '-swift-version ' + swift_version
433433

434-
# Define a macro for the next release OS version.
435-
swift_stdlib_macro = '\'SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0\''
436-
config.swift_frontend_test_options += ' -define-availability ' + swift_stdlib_macro
437-
config.swift_driver_test_options += ' -Xfrontend -define-availability -Xfrontend ' + swift_stdlib_macro
434+
# Define availability macros for known stdlib releases.
435+
for macro in lit_config.params.get('availability_macros').split(";"):
436+
config.swift_frontend_test_options += " -define-availability '{0}'".format(macro)
437+
config.swift_driver_test_options += " -Xfrontend -define-availability -Xfrontend '{0}'".format(macro)
438438

439439
differentiable_programming = lit_config.params.get('differentiable_programming', None)
440440
if differentiable_programming is not None:

0 commit comments

Comments
 (0)