Skip to content

Commit 142ec33

Browse files
authored
Merge pull request #40043 from lorentey/define-availability-macros-outside-cmake
2 parents 4592132 + 9b10335 commit 142ec33

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

CMakeLists.txt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -525,17 +525,8 @@ 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")
528+
file(STRINGS "utils/availability-macros.def" SWIFT_STDLIB_AVAILABILITY_DEFINITIONS)
529+
list(FILTER SWIFT_STDLIB_AVAILABILITY_DEFINITIONS EXCLUDE REGEX "^\\s*(#.*)?$")
539530

540531
#
541532
# Include CMake modules

test/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,6 @@ 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-
392388
foreach(test_subset ${TEST_SUBSETS})
393389
set(directories)
394390
set(dependencies ${test_dependencies})

test/lit.cfg

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,13 @@ 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 availability macros for known stdlib releases.
435-
for macro in lit_config.params.get('availability_macros', '').split(";"):
434+
# Load availability macros for known stdlib releases.
435+
def load_availability_macros():
436+
path = os.path.join(os.path.dirname(__file__), "../utils/availability-macros.def")
437+
lines = open(path, 'r').read().splitlines()
438+
pattern = re.compile(r"\s*(#.*)?")
439+
return filter(lambda l: pattern.fullmatch(l) is None, lines)
440+
for macro in load_availability_macros():
436441
config.swift_frontend_test_options += " -define-availability '{0}'".format(macro)
437442
config.swift_driver_test_options += " -Xfrontend -define-availability -Xfrontend '{0}'".format(macro)
438443

utils/availability-macros.def

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# This file defines availability macros mapping Swift releases to ABI stable
2+
# OS releases that include the corresponding Swift Standard Library version.
3+
#
4+
# The macros defined here are available for use in all Swift libraries and swift
5+
# lit tests defined in this repository. They can be used in place of a full
6+
# version constraint list in `@available` attributes. That is to say, instead of
7+
#
8+
# @available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *)
9+
#
10+
# we can write
11+
#
12+
# @available(SwiftStdlib 5.2, *)
13+
#
14+
# Comments in this file start with `#`. Comments and empty lines are ignored.
15+
# Each of the remaining lines must define an availability macro in the same
16+
# format used by the `-define-availability` frontend command line option.
17+
18+
# 9999 is the generic unknown future Swift release. It always needs to resolve
19+
# to the special placeholder version numbers 9999.
20+
21+
SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999
22+
23+
# The last entry in this list corresponds to the Swift version currently under
24+
# development. This usually resolves to placeholder version numbers (9999) until
25+
# the corresponding operating systems get announced.
26+
27+
SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2
28+
SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0
29+
SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4
30+
SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0
31+
SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5
32+
SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0
33+
SwiftStdlib 5.6:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999
34+
35+
# Local Variables:
36+
# mode: conf-unix
37+
# End:

0 commit comments

Comments
 (0)