Skip to content
Draft
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
19 changes: 19 additions & 0 deletions Sources/PackageDescription/SupportedPlatforms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ public struct Platform: Equatable {
public static let openbsd: Platform = Platform(name: "openbsd")
}

@available(_PackageDescription, introduced: 5.11)
extension Platform: CaseIterable {
public static var allCases: [Platform] {
// Why visionOS does not need something like @available(_PackageDescription, introduced: 5.9)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some question here:

  1. Why some new platform (eg. Platform.visionOS) is not marked with @available(_PackageDescription, introduced: 5.x) while some is marked(eg. Platform.openbsd)
  2. We can't use if #available(_PackageDescription 5.2, *) currently. When a new platform is introduced on Swift 5.11 and is marked as @available(_PackageDescription, introduced: 5.11), how can I append it conditionally?

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. That seems like a mistake.
  2. I think we would need #available support to make this work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Got it. Then maybe I can add check the time when they are added and add the corresponding available mark in this PR.
  2. if #avaiable(_PackageDescription 5.2, *) is currently not a valid Swift statement and a Swift Proposal for this may be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've seen some usage on Swift repo with if #available(SwiftStdlib 5.3, *) maybe it is already supported upstream 🤔 and all we should do is add some flag?

Copy link
Contributor Author

@Kyle-Ye Kyle-Ye Jan 1, 2024

Choose a reason for hiding this comment

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

let availabilityDefinition = PackageDescription.SwiftSetting.unsafeFlags([
    "-Xfrontend",
    "-define-availability",
    "-Xfrontend",
    "SwiftStdlib 5.7:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0",
    "-Xfrontend",
    "-define-availability",
    "-Xfrontend",
    "SwiftStdlib 5.8:macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4",
    "-Xfrontend",
    "-define-availability",
    "-Xfrontend",
    "SwiftStdlib 5.9:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999",
])

Found the trick here, looks like SwiftStdlib is just a typealias for the OS check.

var defaultCases: [Platform] = [.macOS, .macCatalyst, .iOS, .tvOS, .watchOS, .visionOS, .driverKit, .linux]
// if #available(_PackageDescription 5.2, *) {
defaultCases.append(.windows)
defaultCases.append(.android)
// }
// if #available(_PackageDescription 5.3, *) {
defaultCases.append(.wasi)
// }
// if #available(_PackageDescription 5.8, *) {
defaultCases.append(.openbsd)
// }
return defaultCases
}
}

/// A platform that the Swift package supports.
///
/// By default, Swift Package Manager assigns a predefined minimum deployment version for each
Expand Down