Created
November 19, 2024 00:24
-
-
Save DandyLyons/56dc43d0b98befa670758490b43fff07 to your computer and use it in GitHub Desktop.
Swift `UpcomingFeature` enum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Please feel free to add this gist to your own `Package.swift` file to enable quick type-safe Swift language feature flagging. | |
| extension SwiftSetting { | |
| /// Feature Flag Strings | |
| /// | |
| /// Found at https://www.swift.org/migration/documentation/swift-6-concurrency-migration-guide/sourcecompatibility/ | |
| /// Please update this list as new feature flags are added. | |
| enum UpcomingFeature: String { | |
| /// SE-0418: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0418-inferring-sendable-for-methods.md | |
| case inferringSendableFromCapture = "InferSendableFromCaptures" | |
| /// SE-0423: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0423-dynamic-actor-isolation.md | |
| case dynamicActorIsolation = "DynamicActorIsolation" | |
| /// SE-0434: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0434-global-actor-isolated-types-usability.md | |
| case globalActorIsolatedTypesUsability = "GlobalActorIsolatedTypesUsability" | |
| } | |
| /// Enable an upcoming feature flag, using a static type. | |
| /// | |
| /// - Parameters: | |
| /// - upcomingFeature: The feature flag to enable. | |
| /// - condition: The condition under which the feature flag should be enabled. | |
| /// If `nil`, the feature flag will always be enabled. | |
| /// ## Usage | |
| /// ```swift | |
| /// let package = Package( | |
| /// name: "MyLibrary", | |
| /// products: [ | |
| /// .library( | |
| /// name: "MyLibrary", | |
| /// targets: ["MyLibrary"]), | |
| /// ], | |
| /// targets: [ | |
| /// .target( | |
| /// name: "MyLibrary", | |
| /// swiftSettings: [ | |
| /// .enableUpcomingFeature(.globalActorIsolatedTypesUsability) | |
| /// ] | |
| /// ), | |
| /// | |
| /// ], | |
| /// swiftLanguageVersions: [ | |
| /// .v5 | |
| /// ] | |
| /// ) | |
| /// ``` | |
| static func enableUpcomingFeature(_ upcomingFeature: UpcomingFeature, condition: BuildSettingCondition? = nil) -> SwiftSetting { | |
| enableUpcomingFeature(upcomingFeature.rawValue, condition) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment