Skip to content

Commit 5fd8063

Browse files
authored
Enable strict concurrency (#213)
Motivation: To catch potential data races at build time. Modifications: - Bump Swift tools version from 5.8 to 5.9 in Package.swift. - Enable strict concurrency in Package.swift. - Adjust the documentation section on the supported Swift versions. - Implement minor fixes for the surfaced strict concurrency warnings. - Add `-require-explicit-sendable` to the 6.0, nightly 6.0 and nightly main CI checks. Result: Strict concurrency adoption.
1 parent d381c58 commit 5fd8063

File tree

7 files changed

+25
-14
lines changed

7 files changed

+25
-14
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
1313
with:
1414
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
15-
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
16-
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
17-
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
18-
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
15+
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
16+
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
17+
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
18+
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
1919

2020
benchmarks:
2121
name: Benchmarks

.github/workflows/pull_request.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ jobs:
2323
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
2424
with:
2525
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
26-
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
27-
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
28-
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
29-
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
26+
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
27+
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
28+
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
29+
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
3030

3131
benchmarks:
3232
name: Benchmarks

Package.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.8
1+
// swift-tools-version: 5.9
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftCertificates open source project
@@ -91,6 +91,12 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
9191
]
9292
}
9393

94+
for target in package.targets {
95+
var settings = target.swiftSettings ?? []
96+
settings.append(.enableExperimentalFeature("StrictConcurrency=complete"))
97+
target.swiftSettings = settings
98+
}
99+
94100
// --- STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- //
95101
for target in package.targets {
96102
if target.type != .plugin {

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ a default verifier and a number of built-in verifier policies.
2424

2525
## Supported Swift Versions
2626

27-
This library was introduced with support for Swift 5.7 or later. This library will
28-
support the latest stable Swift version and the two versions prior.
27+
This library will support the latest stable Swift version and the two versions prior.
2928

3029
## Getting Started
3130

Sources/X509/SecKeyWrapper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extension Certificate.PrivateKey {
6666

6767
@usableFromInline
6868
static func keyAttributes(key: SecKey) throws -> [String: any Sendable] {
69-
guard let attributes = SecKeyCopyAttributes(key) as? [CFString: Any] else {
69+
guard let attributes = SecKeyCopyAttributes(key) as? [CFString: any Sendable] else {
7070
throw CertificateError.unsupportedPrivateKey(
7171
reason: "cannot copy SecKey attributes"
7272
)

Tests/X509Tests/SecKeyWrapperTests.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
import XCTest
1616
@_spi(Testing) @testable import X509
17+
#if canImport(Darwin)
18+
@preconcurrency import Security
19+
#endif
1720

1821
#if canImport(Darwin)
1922
final class SecKeyWrapperTests: XCTestCase {
@@ -62,9 +65,9 @@ final class SecKeyWrapperTests: XCTestCase {
6265
}
6366

6467
@available(macOS 11.0, iOS 14, tvOS 14, watchOS 7, *)
65-
func testPEMExport() throws {
68+
func testPEMExport() async throws {
6669
for candidate in try generateCandidateKeys() {
67-
try XCTContext.runActivity(named: "Testing \(candidate.type) key (size: \(candidate.keySize))") { _ in
70+
try await XCTContext.runActivity(named: "Testing \(candidate.type) key (size: \(candidate.keySize))") { _ in
6871
let secKeyWrapper = try Certificate.PrivateKey.SecKeyWrapper(key: candidate.key)
6972

7073
if !candidate.sep {

Tests/X509Tests/SignatureTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import XCTest
1717
import _CryptoExtras
1818
import SwiftASN1
1919
@testable import X509
20+
#if canImport(Darwin)
21+
@preconcurrency import Security
22+
#endif
2023

2124
final class SignatureTests: XCTestCase {
2225
static let now = Date()

0 commit comments

Comments
 (0)