Skip to content

Commit 9191683

Browse files
authored
Merge pull request #143 from bnbarham/swiftpm-version-details
Add more details for packages that need to support old Swift versions
2 parents 77d7347 + 7ceaf91 commit 9191683

File tree

1 file changed

+76
-8
lines changed

1 file changed

+76
-8
lines changed

Guide.docc/Swift6Mode.md

+76-8
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ invocation using the `-Xswiftc` flag:
2525

2626
### Package manifest
2727

28-
A `Package.swift` file that uses `swift-tools-version` of `6.0` will enable
29-
the Swift 6 language mode for all targets.
30-
You can still set the language mode for the package as a whole using the
31-
`swiftLanguageVersions` property of `Package`.
32-
However, you can now also change the language mode as needed on a
33-
per-target basis using the new `swiftLanguageVersion` build setting:
28+
A `Package.swift` file that uses `swift-tools-version` of `6.0` will enable the Swift 6 language
29+
mode for all targets. You can still set the language mode for the package as a whole using the
30+
`swiftLanguageModes` property of `Package`. However, you can now also change the language mode as
31+
needed on a per-target basis using the new `swiftLanguageMode` build setting:
3432

3533
```swift
3634
// swift-tools-version: 6.0
@@ -41,7 +39,7 @@ let package = Package(
4139
// ...
4240
],
4341
targets: [
44-
// Uses the default tools language mode
42+
// Uses the default tools language mode (6)
4543
.target(
4644
name: "FullyMigrated",
4745
),
@@ -56,9 +54,79 @@ let package = Package(
5654
)
5755
```
5856

57+
Note that if your package needs to continue supporting earlier Swift toolchain versions and you want
58+
to use per-target `swiftLanguageMode`, you will need to create a version-specific manifest for pre-6
59+
toolchains. For example, if you'd like to continue supporting 5.9 toolchains and up, you could have
60+
one manifest `[email protected]`:
61+
```swift
62+
// swift-tools-version: 5.9
63+
64+
let package = Package(
65+
name: "MyPackage",
66+
products: [
67+
// ...
68+
],
69+
targets: [
70+
.target(
71+
name: "FullyMigrated",
72+
),
73+
.target(
74+
name: "NotQuiteReadyYet",
75+
)
76+
]
77+
)
78+
```
79+
80+
And another `Package.swift` for Swift toolchains 6.0+:
81+
```swift
82+
// swift-tools-version: 6.0
83+
84+
let package = Package(
85+
name: "MyPackage",
86+
products: [
87+
// ...
88+
],
89+
targets: [
90+
// Uses the default tools language mode (6)
91+
.target(
92+
name: "FullyMigrated",
93+
),
94+
// Still requires 5
95+
.target(
96+
name: "NotQuiteReadyYet",
97+
swiftSettings: [
98+
.swiftLanguageMode(.v5)
99+
]
100+
)
101+
]
102+
)
103+
```
104+
105+
If instead you would just like to use Swift 6 language mode when it's available (while still
106+
continuing to support older modes) you can keep a single `Package.swift` and specify the version in
107+
a compatible manner:
108+
```swift
109+
// swift-tools-version: 5.9
110+
111+
let package = Package(
112+
name: "MyPackage",
113+
products: [
114+
// ...
115+
],
116+
targets: [
117+
.target(
118+
name: "FullyMigrated",
119+
),
120+
],
121+
// `swiftLanguageVersions` and `.version("6")` to support pre 6.0 swift-tools-version.
122+
swiftLanguageVersions: [.version("6"), .v5]
123+
)
124+
```
125+
126+
59127
## Using Xcode
60128

61-
### Build Settings
129+
### Build Settings
62130

63131
You can control the language mode for an Xcode project or target by setting
64132
the "Swift Language Version" build setting to "6".

0 commit comments

Comments
 (0)