|
| 1 | +# Swift Language Version Per Target |
| 2 | + |
| 3 | +* Proposal: [SE-NNNN](NNNN-swiftpm-per-target-swift-language-version-setting.md) |
| 4 | +* Authors: [Pavel Yaskevich](https://github.com/xedin) |
| 5 | +* Review Manager: TBD |
| 6 | +* Status: **Awaiting Implementation** |
| 7 | + |
| 8 | +## Introduction |
| 9 | + |
| 10 | +The current Swift Package Manager manifest API for specifying Swift language version(s) applies to an entire package which is limiting when adopting new language versions that have implications for source compatibility. |
| 11 | + |
| 12 | +Swift-evolution thread: [Pitch: [SwiftPM] Swift Language Version Per Target](https://forums.swift.org/t/pitch-swiftpm-swift-language-version-per-target/71067) |
| 13 | + |
| 14 | +## Motivation |
| 15 | + |
| 16 | +Adopting new language versions at the target granularity allows for gradual migration to prevent possible disruptions. Swift 6, for example, turns on strict concurrency by default, which can have major implications for the project in the form of new errors that were previously downgraded to warnings. SwiftPM should allow to specify a language version per target so that package authors can incrementally transition their project to the newer version. |
| 17 | + |
| 18 | +## Proposed solution |
| 19 | + |
| 20 | +Add a new Swift target setting API, similar to `enable{Upcoming, Experimental}Feature`, to specify a Swift language version that should be used to build the target, if such version is not specified, fallback to the current language version determination logic. |
| 21 | + |
| 22 | +## Detailed design |
| 23 | + |
| 24 | +Add a new `swiftLanguageVersion` API to `SwiftSetting` limited to manifests >= 6.0: |
| 25 | + |
| 26 | +``` |
| 27 | +public struct SwiftSetting { |
| 28 | + // ... other settings |
| 29 | + |
| 30 | + @available(_PackageDescription, introduced: 6.0) |
| 31 | + public static func swiftLanguageVersion( |
| 32 | + _ version: SwiftVersion, |
| 33 | + _ condition: BuildSettingCondition? = nil |
| 34 | + ) -> SwiftSetting { |
| 35 | + ... |
| 36 | + } |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +## Security |
| 41 | + |
| 42 | +New language version setting has no implications on security, safety or privacy. |
| 43 | + |
| 44 | +## Impact on existing packages |
| 45 | + |
| 46 | +Since this is a new API, all existing packages will use the default behavior - version specified at the package level when set or determined based on the tools version. |
| 47 | + |
| 48 | +## Alternatives considered |
| 49 | + |
| 50 | +- Add a new setting for 'known-safe' flags, of which `-swift-version` could be the first. This seems less user-friendly and error prone than re-using `SwiftLanguageVersion`, which has known language versions as its cases (with a plaintext escape hatch when necessary). |
| 51 | + |
| 52 | +- Add new initializer parameter to `Target` API and all of the convenience static functions, this is less flexible because it would require a default value. |
| 53 | + |
0 commit comments