Skip to content

Commit cd814e2

Browse files
committed
Improve the instructions for enabling strict concurrency in SwiftPM.
1 parent 3c53d70 commit cd814e2

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

documentation/concurrency/index.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,52 @@ Data-race safety in the Swift 6 language mode is designed for incremental migrat
88

99
Complete data-race safety checking can be enabled as warnings in the Swift 5 language mode using the `-strict-concurrency` compiler flag.
1010

11-
## At the command line
11+
## Using the Swift compiler
1212

1313
To enable complete concurrency checking when running `swift` or `swiftc` directly at the command line, pass `-strict-concurrency=complete`:
1414

1515
```
1616
~ swift -strict-concurrency=complete main.swift
1717
```
1818

19-
## In a Swift package manifest
19+
## Using SwiftPM
20+
21+
### In a SwiftPM command-line invocation
22+
23+
`-strict-concurrency=complete` can be passed in a Swift package manager command-line invocation using the `-Xswiftc` flag:
24+
25+
```
26+
~ swift build -Xswiftc -strict-concurrency=complete
27+
~ swift test -Xswiftc -strict-concurrency=complete
28+
```
29+
30+
This can be useful to gauge the amount of concurrency warnings before adding the flag permanently in the package manifest as described in the following section.
31+
32+
### In a SwiftPM package manifest
2033

2134
To enable complete concurrency checking for a target in a Swift package using Swift 5.9 or Swift 5.10 tools, use [`SwiftSetting.enableExperimentalFeature`](https://developer.apple.com/documentation/packagedescription/swiftsetting/enableexperimentalfeature(_:_:)) in the Swift settings for the given target:
2235

2336
```swift
24-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
37+
.target(
38+
name: "MyTarget",
39+
swiftSettings: [
40+
.enableExperimentalFeature("StrictConcurrency")
41+
]
42+
)
2543
```
2644

2745
When using Swift 6.0 tools or later, use [`SwiftSetting.enableUpcomingFeature`](https://developer.apple.com/documentation/packagedescription/swiftsetting/enableupcomingfeature(_:_:)) in the Swift settings for the given target:
2846

2947
```swift
30-
swiftSettings: [.enableUpcomingFeature("StrictConcurrency")]
48+
.target(
49+
name: "MyTarget",
50+
swiftSettings: [
51+
.enableUpcomingFeature("StrictConcurrency")
52+
]
53+
)
3154
```
3255

33-
## In Xcode
56+
## Using Xcode
3457

3558
To enable complete concurrency checking in an Xcode project, set the "Swift Strict Concurrency" setting to "Complete" in the Xcode build settings. Alternatively, you can set `SWIFT_STRICT_CONCURRENCY` to `complete` in an xcconfig file:
3659

0 commit comments

Comments
 (0)