Skip to content

Commit

Permalink
Enable strict concurrency
Browse files Browse the repository at this point in the history
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 documentation to 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.
  • Loading branch information
clintonpi committed Dec 13, 2024
1 parent d381c58 commit 080df47
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
with:
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"

benchmarks:
name: Benchmarks
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jobs:
with:
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"

benchmarks:
name: Benchmarks
Expand Down
8 changes: 7 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.8
// swift-tools-version: 5.9
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftCertificates open source project
Expand Down Expand Up @@ -91,6 +91,12 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
]
}

for target in package.targets {
var settings = target.swiftSettings ?? []
settings.append(.enableExperimentalFeature("StrictConcurrency=complete"))
target.swiftSettings = settings
}

// --- STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- //
for target in package.targets {
if target.type != .plugin {
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ a default verifier and a number of built-in verifier policies.

## Supported Swift Versions

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

## Getting Started

Expand Down
2 changes: 1 addition & 1 deletion Sources/X509/SecKeyWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extension Certificate.PrivateKey {

@usableFromInline
static func keyAttributes(key: SecKey) throws -> [String: any Sendable] {
guard let attributes = SecKeyCopyAttributes(key) as? [CFString: Any] else {
guard let attributes = SecKeyCopyAttributes(key) as? [CFString: any Sendable] else {
throw CertificateError.unsupportedPrivateKey(
reason: "cannot copy SecKey attributes"
)
Expand Down
6 changes: 3 additions & 3 deletions Tests/X509Tests/SecKeyWrapperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//

import XCTest
@preconcurrency import XCTest
@_spi(Testing) @testable import X509

#if canImport(Darwin)
Expand Down Expand Up @@ -62,9 +62,9 @@ final class SecKeyWrapperTests: XCTestCase {
}

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

if !candidate.sep {
Expand Down
2 changes: 1 addition & 1 deletion Tests/X509Tests/SignatureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//

import XCTest
@preconcurrency import XCTest
@preconcurrency import Crypto
import _CryptoExtras
import SwiftASN1
Expand Down

0 comments on commit 080df47

Please sign in to comment.