Skip to content

Commit 9a15308

Browse files
committed
Replace bespoke availability system
Removes the script based availability system with the experimental availability macro feature.
1 parent d89ca1d commit 9a15308

29 files changed

+230
-251
lines changed

.github/workflows/pull_request.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,27 @@ jobs:
1010
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
1111
with:
1212
linux_os_versions: '["jammy", "focal"]'
13-
enable_macos_checks: false
14-
macos_xcode_versions: '["16.3"]'
13+
enable_macos_checks: true
14+
swift_flags: "-Xbuild-tools-swiftc -DSYSTEM_CI"
15+
16+
build-abi-stable:
17+
name: Build ABI Stable
18+
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
19+
with:
20+
enable_linux_checks: false
21+
enable_macos_checks: true
22+
enable_windows_checks: false
23+
# Only build
24+
macos_build_command: "xcrun swift build --build-tests"
25+
# Only test against latest Xcode
26+
macos_exclude_xcode_versions: |
27+
[
28+
{"xcode_version": "16.0"},
29+
{"xcode_version": "16.1"},
30+
{"xcode_version": "16.2"},
31+
]
32+
# Enable availability to match ABI stable verion of system.
33+
swift_flags: "-Xbuild-tools-swiftc -DSYSTEM_CI -Xbuild-tools-swiftc -DSYSTEM_ABI_STABLE"
1534

1635
soundness:
1736
name: Soundness

Package.swift

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,70 @@
1212

1313
import PackageDescription
1414

15-
let cSettings: [CSetting] = [
16-
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
15+
struct Available {
16+
var name: String
17+
var version: String
18+
var osAvailability: String
19+
var sourceAvailability: String
20+
21+
init(
22+
_ version: String,
23+
_ osAvailability: String
24+
) {
25+
self.name = "System"
26+
self.version = version
27+
self.osAvailability = osAvailability
28+
self.sourceAvailability = "macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, visionOS 1.0"
29+
}
30+
31+
var swiftSetting: SwiftSetting {
32+
#if SYSTEM_ABI_STABLE
33+
// Use availability matching Darwin API.
34+
let availability = self.osAvailability
35+
#else
36+
// Use availability matching SwiftPM default.
37+
let availability = self.sourceAvailability
38+
#endif
39+
return .enableExperimentalFeature(
40+
"AvailabilityMacro=\(self.name) \(version):\(availability)")
41+
}
42+
}
43+
44+
let availability: [Available] = [
45+
Available("0.0.1", "macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0"),
46+
47+
Available("0.0.2", "macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0"),
48+
49+
Available("0.0.3", "macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4"),
50+
Available("1.1.0", "macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4"),
51+
52+
Available("1.1.1", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4"),
53+
Available("1.2.0", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4"),
54+
55+
Available("1.2.1", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4"),
56+
Available("1.3.0", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4"),
57+
58+
Available("1.3.1", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4, visionOS 1.0"),
59+
Available("1.3.2", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4, visionOS 1.0"),
60+
Available("1.4.0", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4, visionOS 1.0"),
61+
62+
Available("1.4.1", "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"),
63+
Available("1.4.2", "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"),
64+
Available("1.5.0", "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"),
65+
Available("1.6.0", "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"),
66+
]
67+
68+
let swiftSettingsAvailability = availability.map(\.swiftSetting)
69+
70+
#if SYSTEM_CI
71+
let swiftSettingsCI: [SwiftSetting] = [
72+
.unsafeFlags(["-require-explicit-availability=error"]),
1773
]
74+
#else
75+
let swiftSettingsCI: [SwiftSetting] = []
76+
#endif
1877

19-
let swiftSettings: [SwiftSetting] = [
78+
let swiftSettings = swiftSettingsAvailability + swiftSettingsCI + [
2079
.define(
2180
"SYSTEM_PACKAGE_DARWIN",
2281
.when(platforms: [.macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .visionOS])),
@@ -25,6 +84,22 @@ let swiftSettings: [SwiftSetting] = [
2584
.enableExperimentalFeature("Lifetimes"),
2685
]
2786

87+
let cSettings: [CSetting] = [
88+
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
89+
]
90+
91+
#if SYSTEM_ABI_STABLE
92+
let platforms: [SupportedPlatform] = [
93+
.macOS("26"),
94+
.iOS("26"),
95+
.watchOS("26"),
96+
.tvOS("26"),
97+
.visionOS("26"),
98+
]
99+
#else
100+
let platforms: [SupportedPlatform]? = nil
101+
#endif
102+
28103
#if os(Linux)
29104
let filesToExclude = ["CMakeLists.txt"]
30105
#else
@@ -39,6 +114,7 @@ let testsToExclude = ["IORequestTests.swift", "IORingTests.swift"]
39114

40115
let package = Package(
41116
name: "swift-system",
117+
platforms: platforms,
42118
products: [
43119
.library(name: "SystemPackage", targets: ["SystemPackage"]),
44120
],
@@ -63,3 +139,4 @@ let package = Package(
63139
cSettings: cSettings,
64140
swiftSettings: swiftSettings),
65141
])
142+

Sources/System/Errno.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/// An error number used by system calls to communicate what kind of error
1111
/// occurred.
1212
@frozen
13-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
13+
@available(System 0.0.1, *)
1414
public struct Errno: RawRepresentable, Error, Hashable, Codable {
1515
/// The raw C error number.
1616
@_alwaysEmitIntoClient
@@ -1391,7 +1391,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
13911391
}
13921392

13931393
// Constants defined in header but not man page
1394-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
1394+
@available(System 0.0.1, *)
13951395
extension Errno {
13961396
/// Operation would block.
13971397
///
@@ -1520,7 +1520,7 @@ extension Errno {
15201520
#endif
15211521
}
15221522

1523-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
1523+
@available(System 0.0.1, *)
15241524
extension Errno {
15251525
// TODO: We want to provide safe access to `errno`, but we need a
15261526
// release-barrier to do so.
@@ -1535,14 +1535,14 @@ extension Errno {
15351535
}
15361536

15371537
// Use "hidden" entry points for `NSError` bridging
1538-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
1538+
@available(System 0.0.1, *)
15391539
extension Errno {
15401540
public var _code: Int { Int(rawValue) }
15411541

15421542
public var _domain: String { "NSPOSIXErrorDomain" }
15431543
}
15441544

1545-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
1545+
@available(System 0.0.1, *)
15461546
extension Errno: CustomStringConvertible, CustomDebugStringConvertible {
15471547
/// A textual representation of the most recent error
15481548
/// returned by a system call.
@@ -1562,7 +1562,7 @@ extension Errno: CustomStringConvertible, CustomDebugStringConvertible {
15621562
public var debugDescription: String { self.description }
15631563
}
15641564

1565-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
1565+
@available(System 0.0.1, *)
15661566
extension Errno {
15671567
@_alwaysEmitIntoClient
15681568
public static func ~=(_ lhs: Errno, _ rhs: Error) -> Bool {

Sources/System/FileDescriptor.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// of `FileDescriptor` values,
1515
/// in the same way as you manage a raw C file handle.
1616
@frozen
17-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
17+
@available(System 0.0.1, *)
1818
public struct FileDescriptor: RawRepresentable, Hashable, Codable {
1919
/// The raw C file handle.
2020
@_alwaysEmitIntoClient
@@ -26,7 +26,7 @@ public struct FileDescriptor: RawRepresentable, Hashable, Codable {
2626
}
2727

2828
// Standard file descriptors.
29-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
29+
@available(System 0.0.1, *)
3030
extension FileDescriptor {
3131
/// The standard input file descriptor, with a numeric value of 0.
3232
@_alwaysEmitIntoClient
@@ -41,11 +41,11 @@ extension FileDescriptor {
4141
public static var standardError: FileDescriptor { .init(rawValue: 2) }
4242
}
4343

44-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
44+
@available(System 0.0.1, *)
4545
extension FileDescriptor {
4646
/// The desired read and write access for a newly opened file.
4747
@frozen
48-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
48+
@available(System 0.0.1, *)
4949
public struct AccessMode: RawRepresentable, Sendable, Hashable, Codable {
5050
/// The raw C access mode.
5151
@_alwaysEmitIntoClient
@@ -88,7 +88,7 @@ extension FileDescriptor {
8888

8989
/// Options that specify behavior for a newly-opened file.
9090
@frozen
91-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
91+
@available(System 0.0.1, *)
9292
public struct OpenOptions: OptionSet, Sendable, Hashable, Codable {
9393
/// The raw C options.
9494
@_alwaysEmitIntoClient
@@ -326,7 +326,7 @@ extension FileDescriptor {
326326

327327
/// Options for specifying what a file descriptor's offset is relative to.
328328
@frozen
329-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
329+
@available(System 0.0.1, *)
330330
public struct SeekOrigin: RawRepresentable, Sendable, Hashable, Codable {
331331
/// The raw C value.
332332
@_alwaysEmitIntoClient
@@ -402,7 +402,7 @@ extension FileDescriptor {
402402
}
403403
}
404404

405-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
405+
@available(System 0.0.1, *)
406406
extension FileDescriptor.AccessMode
407407
: CustomStringConvertible, CustomDebugStringConvertible
408408
{
@@ -421,7 +421,7 @@ extension FileDescriptor.AccessMode
421421
public var debugDescription: String { self.description }
422422
}
423423

424-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
424+
@available(System 0.0.1, *)
425425
extension FileDescriptor.SeekOrigin
426426
: CustomStringConvertible, CustomDebugStringConvertible
427427
{
@@ -444,7 +444,7 @@ extension FileDescriptor.SeekOrigin
444444
public var debugDescription: String { self.description }
445445
}
446446

447-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
447+
@available(System 0.0.1, *)
448448
extension FileDescriptor.OpenOptions
449449
: CustomStringConvertible, CustomDebugStringConvertible
450450
{

Sources/System/FileHelpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
See https://swift.org/LICENSE.txt for license information
88
*/
99

10-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
10+
@available(System 0.0.1, *)
1111
extension FileDescriptor {
1212
/// Runs a closure and then closes the file descriptor, even if an error occurs.
1313
///

Sources/System/FileOperations.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
See https://swift.org/LICENSE.txt for license information
88
*/
99

10-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
10+
@available(System 0.0.1, *)
1111
extension FileDescriptor {
1212
/// Opens or creates a file for reading or writing.
1313
///
@@ -368,7 +368,7 @@ extension FileDescriptor {
368368
}
369369

370370
#if !os(WASI)
371-
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
371+
@available(System 0.0.2, *)
372372
extension FileDescriptor {
373373
/// Duplicates this file descriptor and return the newly created copy.
374374
///
@@ -398,15 +398,15 @@ extension FileDescriptor {
398398
///
399399
/// The corresponding C functions are `dup` and `dup2`.
400400
@_alwaysEmitIntoClient
401-
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
401+
@available(System 0.0.2, *)
402402
public func duplicate(
403403
as target: FileDescriptor? = nil,
404404
retryOnInterrupt: Bool = true
405405
) throws -> FileDescriptor {
406406
try _duplicate(as: target, retryOnInterrupt: retryOnInterrupt).get()
407407
}
408408

409-
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
409+
@available(System 0.0.2, *)
410410
@usableFromInline
411411
internal func _duplicate(
412412
as target: FileDescriptor?,
@@ -435,20 +435,20 @@ extension FileDescriptor {
435435
#endif
436436

437437
#if !os(WASI)
438-
@available(/*System 1.1.0: macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4*/iOS 8, *)
438+
@available(System 1.1.0, *)
439439
extension FileDescriptor {
440440
/// Creates a unidirectional data channel, which can be used for interprocess communication.
441441
///
442442
/// - Returns: The pair of file descriptors.
443443
///
444444
/// The corresponding C function is `pipe`.
445445
@_alwaysEmitIntoClient
446-
@available(/*System 1.1.0: macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4*/iOS 8, *)
446+
@available(System 1.1.0, *)
447447
public static func pipe() throws -> (readEnd: FileDescriptor, writeEnd: FileDescriptor) {
448448
try _pipe().get()
449449
}
450450

451-
@available(/*System 1.1.0: macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4*/iOS 8, *)
451+
@available(System 1.1.0, *)
452452
@usableFromInline
453453
internal static func _pipe() -> Result<(readEnd: FileDescriptor, writeEnd: FileDescriptor), Errno> {
454454
var fds: (Int32, Int32) = (-1, -1)
@@ -463,7 +463,7 @@ extension FileDescriptor {
463463
}
464464
#endif
465465

466-
@available(/*System 1.2.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
466+
@available(System 1.2.0, *)
467467
extension FileDescriptor {
468468
/// Truncates or extends the file referenced by this file descriptor.
469469
///
@@ -485,7 +485,7 @@ extension FileDescriptor {
485485
/// associated with the file.
486486
///
487487
/// The corresponding C function is `ftruncate`.
488-
@available(/*System 1.2.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
488+
@available(System 1.2.0, *)
489489
@_alwaysEmitIntoClient
490490
public func resize(
491491
to newSize: Int64,
@@ -497,7 +497,7 @@ extension FileDescriptor {
497497
).get()
498498
}
499499

500-
@available(/*System 1.2.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
500+
@available(System 1.2.0, *)
501501
@usableFromInline
502502
internal func _resize(
503503
to newSize: Int64,

Sources/System/FilePath/FilePath.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
/// However, the rules for path equivalence
3838
/// are file-system–specific and have additional considerations
3939
/// like case insensitivity, Unicode normalization, and symbolic links.
40-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
40+
@available(System 0.0.1, *)
4141
public struct FilePath: Sendable {
4242
// TODO(docs): Section on all the new syntactic operations, lexical normalization, decomposition,
4343
// components, etc.
@@ -59,16 +59,16 @@ public struct FilePath: Sendable {
5959
}
6060
}
6161

62-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
62+
@available(System 0.0.1, *)
6363
extension FilePath {
6464
/// The length of the file path, excluding the null terminator.
6565
public var length: Int { _storage.length }
6666
}
6767

68-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
68+
@available(System 0.0.1, *)
6969
extension FilePath: Hashable {}
7070

71-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
71+
@available(System 0.0.1, *)
7272
extension FilePath: Codable {
7373
// Encoder is synthesized; it probably should have been explicit and used
7474
// a single-value container, but making that change now is somewhat risky.

0 commit comments

Comments
 (0)