Skip to content

Replace bespoke availability system #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,40 @@ let cSettings: [CSetting] = [
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
]

let availability = [
("0.0.1", "macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0"),
("0.0.2", "macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0"),
// FIXME: 0.0.3
("1.1.0", "macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4"),
// FIXME: 1.1.1
("1.2.0", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4"),
// FIXME: 1.2.1
("1.3.0", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4"),
// FIXME: 1.3.1
// FIXME: 1.3.2
("1.4.0", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4"),
// FIXME: 1.4.1
// FIXME: 1.4.2
// FIXME: 1.5.0
]

let swiftSettings: [SwiftSetting] = [
.define(
"SYSTEM_PACKAGE_DARWIN",
.when(platforms: [.macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .visionOS])),
.define("SYSTEM_PACKAGE"),
.define("ENABLE_MOCKING", .when(configuration: .debug)),
]
] + availability.map { (version, osAvailability) -> SwiftSetting in
#if SYSTEM_PACKAGE
// Matches default SwiftPM availability
let availability = "macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, visionOS 1.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also include visionOS in the availabilities above?

#else
let availability = osAvailability
#endif

return .enableExperimentalFeature(
"AvailabilityMacro=System \(version):\(availability)")
}

let package = Package(
name: "swift-system",
Expand Down
12 changes: 6 additions & 6 deletions Sources/System/Errno.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/// An error number used by system calls to communicate what kind of error
/// occurred.
@frozen
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
@available(System 0.0.1, *)
public struct Errno: RawRepresentable, Error, Hashable, Codable {
/// The raw C error number.
@_alwaysEmitIntoClient
Expand Down Expand Up @@ -1391,7 +1391,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
}

// Constants defined in header but not man page
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
@available(System 0.0.1, *)
extension Errno {
/// Operation would block.
///
Expand Down Expand Up @@ -1520,7 +1520,7 @@ extension Errno {
#endif
}

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

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

public var _domain: String { "NSPOSIXErrorDomain" }
}

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

@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
@available(System 0.0.1, *)
extension Errno {
@_alwaysEmitIntoClient
public static func ~=(_ lhs: Errno, _ rhs: Error) -> Bool {
Expand Down
18 changes: 9 additions & 9 deletions Sources/System/FileDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/// of `FileDescriptor` values,
/// in the same way as you manage a raw C file handle.
@frozen
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
@available(System 0.0.1, *)
public struct FileDescriptor: RawRepresentable, Hashable, Codable {
/// The raw C file handle.
@_alwaysEmitIntoClient
Expand All @@ -26,7 +26,7 @@ public struct FileDescriptor: RawRepresentable, Hashable, Codable {
}

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

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

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

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

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

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

@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
@available(System 0.0.1, *)
extension FileDescriptor.OpenOptions
: CustomStringConvertible, CustomDebugStringConvertible
{
Expand Down
2 changes: 1 addition & 1 deletion Sources/System/FileHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
See https://swift.org/LICENSE.txt for license information
*/

@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
@available(System 0.0.1, *)
extension FileDescriptor {
/// Runs a closure and then closes the file descriptor, even if an error occurs.
///
Expand Down
20 changes: 10 additions & 10 deletions Sources/System/FileOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
See https://swift.org/LICENSE.txt for license information
*/

@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
@available(System 0.0.1, *)
extension FileDescriptor {
/// Opens or creates a file for reading or writing.
///
Expand Down Expand Up @@ -368,7 +368,7 @@ extension FileDescriptor {
}

#if !os(WASI)
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
@available(System 0.0.2, *)
extension FileDescriptor {
/// Duplicates this file descriptor and return the newly created copy.
///
Expand Down Expand Up @@ -398,15 +398,15 @@ extension FileDescriptor {
///
/// The corresponding C functions are `dup` and `dup2`.
@_alwaysEmitIntoClient
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
@available(System 0.0.2, *)
public func duplicate(
as target: FileDescriptor? = nil,
retryOnInterrupt: Bool = true
) throws -> FileDescriptor {
try _duplicate(as: target, retryOnInterrupt: retryOnInterrupt).get()
}

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
@available(System 0.0.2, *)
@usableFromInline
internal func _duplicate(
as target: FileDescriptor?,
Expand Down Expand Up @@ -435,20 +435,20 @@ extension FileDescriptor {
#endif

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

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

@available(/*System 1.2.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
@available(System 1.2.0, *)
extension FileDescriptor {
/// Truncates or extends the file referenced by this file descriptor.
///
Expand All @@ -485,7 +485,7 @@ extension FileDescriptor {
/// associated with the file.
///
/// The corresponding C function is `ftruncate`.
@available(/*System 1.2.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
@available(System 1.2.0, *)
@_alwaysEmitIntoClient
public func resize(
to newSize: Int64,
Expand All @@ -497,7 +497,7 @@ extension FileDescriptor {
).get()
}

@available(/*System 1.2.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
@available(System 1.2.0, *)
@usableFromInline
internal func _resize(
to newSize: Int64,
Expand Down
8 changes: 4 additions & 4 deletions Sources/System/FilePath/FilePath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
/// However, the rules for path equivalence
/// are file-system–specific and have additional considerations
/// like case insensitivity, Unicode normalization, and symbolic links.
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
@available(System 0.0.1, *)
public struct FilePath: Sendable {
// TODO(docs): Section on all the new syntactic operations, lexical normalization, decomposition,
// components, etc.
Expand All @@ -59,16 +59,16 @@ public struct FilePath: Sendable {
}
}

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

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

@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
@available(System 0.0.1, *)
extension FilePath: Codable {
// Encoder is synthesized; it probably should have been explicit and used
// a single-value container, but making that change now is somewhat risky.
Expand Down
16 changes: 8 additions & 8 deletions Sources/System/FilePath/FilePathComponentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

// MARK: - API

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
@available(System 0.0.2, *)
extension FilePath {
/// A bidirectional, range replaceable collection of the non-root components
/// that make up a file path.
Expand All @@ -28,7 +28,7 @@ extension FilePath {
///
/// path.components.removeAll { $0.kind == .currentDirectory }
/// // path is "/home/username/bin/scripts/tree"
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
@available(System 0.0.2, *)
public struct ComponentView: Sendable {
internal var _path: FilePath
internal var _start: SystemString.Index
Expand Down Expand Up @@ -64,11 +64,11 @@ extension FilePath {
}
}

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
@available(System 0.0.2, *)
extension FilePath.ComponentView: BidirectionalCollection {
public typealias Element = FilePath.Component

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
@available(System 0.0.2, *)
public struct Index: Sendable, Comparable, Hashable {
internal typealias Storage = SystemString.Index

Expand Down Expand Up @@ -100,7 +100,7 @@ extension FilePath.ComponentView: BidirectionalCollection {
}
}

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
@available(System 0.0.2, *)
extension FilePath.ComponentView: RangeReplaceableCollection {
public init() {
self.init(FilePath())
Expand Down Expand Up @@ -150,7 +150,7 @@ extension FilePath.ComponentView: RangeReplaceableCollection {
}
}

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
@available(System 0.0.2, *)
extension FilePath {
/// Create a file path from a root and a collection of components.
public init<C: Collection>(
Expand Down Expand Up @@ -179,7 +179,7 @@ extension FilePath {

// MARK: - Internals

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
@available(System 0.0.2, *)
extension FilePath.ComponentView: _PathSlice {
internal var _range: Range<SystemString.Index> {
_start ..< _path._storage.endIndex
Expand All @@ -192,7 +192,7 @@ extension FilePath.ComponentView: _PathSlice {

// MARK: - Invariants

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
@available(System 0.0.2, *)
extension FilePath.ComponentView {
internal func _invariantCheck() {
#if DEBUG
Expand Down
Loading
Loading