Skip to content

Commit 96b9e08

Browse files
authored
Merge pull request #2392 from xedin/swiftpm-swiftlang-version-per-target
Proposal: [SwiftPM] Swift Language Version Per Target
2 parents 7c7387e + 435b85d commit 96b9e08

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Swift Language Version Per Target
2+
3+
* Proposal: [SE-0435](0435-swiftpm-per-target-swift-language-version-setting.md)
4+
* Authors: [Pavel Yaskevich](https://github.com/xedin)
5+
* Review Manager: [Becca Royal-Gordon](https://github.com/beccadax)
6+
* Status: **Active Review (April 30...May 13, 2024)**
7+
* Implementation: [apple/swift-package-manager#7439](https://github.com/apple/swift-package-manager/pull/7439)
8+
* Review: ([pitch](https://forums.swift.org/t/pitch-swiftpm-swift-language-version-per-target/71067))
9+
10+
## Introduction
11+
12+
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.
13+
14+
Swift-evolution thread: [Pitch: [SwiftPM] Swift Language Version Per Target](https://forums.swift.org/t/pitch-swiftpm-swift-language-version-per-target/71067)
15+
16+
## Motivation
17+
18+
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.
19+
20+
## Proposed solution
21+
22+
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.
23+
24+
## Detailed design
25+
26+
Add a new `swiftLanguageVersion` API to `SwiftSetting` limited to manifests >= 6.0:
27+
28+
```
29+
public struct SwiftSetting {
30+
// ... other settings
31+
32+
@available(_PackageDescription, introduced: 6.0)
33+
public static func swiftLanguageVersion(
34+
_ version: SwiftVersion,
35+
_ condition: BuildSettingCondition? = nil
36+
) -> SwiftSetting {
37+
...
38+
}
39+
}
40+
```
41+
42+
## Security
43+
44+
New language version setting has no implications on security, safety or privacy.
45+
46+
## Impact on existing packages
47+
48+
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.
49+
50+
## Alternatives considered
51+
52+
- 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).
53+
54+
- 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.
55+

0 commit comments

Comments
 (0)