Skip to content

Commit 527128c

Browse files
authored
Enable complete concurrency checking, fix warnings (#26)
We should enable complete concurrency checking by default, as it already uncovered an issue with `LocalSwiftSDKGenerator` sharing `self` with mutable properties (`var downloadArtifacts`) across different tasks.
1 parent cc75a0b commit 527128c

File tree

9 files changed

+36
-33
lines changed

9 files changed

+36
-33
lines changed

Package.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ let package = Package(
3333
dependencies: [
3434
"SwiftSDKGenerator",
3535
.product(name: "ArgumentParser", package: "swift-argument-parser"),
36+
],
37+
swiftSettings: [
38+
.enableExperimentalFeature("StrictConcurrency=complete"),
3639
]
3740
),
3841
.target(
@@ -43,12 +46,18 @@ let package = Package(
4346
.product(name: "AsyncHTTPClient", package: "async-http-client"),
4447
.product(name: "SystemPackage", package: "swift-system"),
4548
],
46-
exclude: ["Dockerfiles"]
49+
exclude: ["Dockerfiles"],
50+
swiftSettings: [
51+
.enableExperimentalFeature("StrictConcurrency=complete"),
52+
]
4753
),
4854
.testTarget(
4955
name: "SwiftSDKGeneratorTests",
5056
dependencies: [
5157
.target(name: "SwiftSDKGenerator"),
58+
],
59+
swiftSettings: [
60+
.enableExperimentalFeature("StrictConcurrency=complete"),
5261
]
5362
),
5463
.target(

Sources/SwiftSDKGenerator/Generator/LocalSwiftSDKGenerator.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Foundation
1414
import SystemPackage
1515

1616
/// Implementation of ``SwiftSDKGenerator`` for the local file system.
17-
public final class LocalSwiftSDKGenerator: SwiftSDKGenerator {
17+
public actor LocalSwiftSDKGenerator: SwiftSDKGenerator {
1818
public let hostTriple: Triple
1919
public let targetTriple: Triple
2020
public let artifactID: String
@@ -146,7 +146,7 @@ public final class LocalSwiftSDKGenerator: SwiftSDKGenerator {
146146

147147
public func buildDockerImage(baseImage: String) async throws -> String {
148148
try await self.inTemporaryDirectory { generator, tmp in
149-
try generator.writeFile(
149+
try await generator.writeFile(
150150
at: tmp.appending("Dockerfile"),
151151
Data(
152152
"""
@@ -359,7 +359,7 @@ public final class LocalSwiftSDKGenerator: SwiftSDKGenerator {
359359
return buildDirectory
360360
}
361361

362-
public func inTemporaryDirectory<T>(
362+
public func inTemporaryDirectory<T: Sendable>(
363363
_ closure: @Sendable (LocalSwiftSDKGenerator, FilePath) async throws -> T
364364
) async throws -> T {
365365
let tmp = FilePath(NSTemporaryDirectory())
@@ -374,7 +374,3 @@ public final class LocalSwiftSDKGenerator: SwiftSDKGenerator {
374374
return result
375375
}
376376
}
377-
378-
// Explicitly marking `LocalSwiftSDKGenerator` as non-`Sendable` for safety.
379-
@available(*, unavailable)
380-
extension LocalSwiftSDKGenerator: Sendable {}

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ extension SwiftSDKGenerator {
2626
try await inTemporaryDirectory { generator, _ in
2727
let sdkUsrPath = pathsConfiguration.sdkDirPath.appending("usr")
2828
let sdkUsrLibPath = sdkUsrPath.appending("lib")
29-
try generator.createDirectoryIfNeeded(at: sdkUsrPath)
29+
try await generator.createDirectoryIfNeeded(at: sdkUsrPath)
3030
try await generator.copyFromDockerContainer(
3131
id: containerID,
3232
from: "/usr/include",
3333
to: sdkUsrPath.appending("include")
3434
)
3535

36-
if case .rhel = self.versionsConfiguration.linuxDistribution {
36+
if case .rhel = await self.versionsConfiguration.linuxDistribution {
3737
try await generator.runOnDockerContainer(
3838
id: containerID,
3939
command: #"""
@@ -58,15 +58,15 @@ extension SwiftSDKGenerator {
5858
to: sdkUsrLib64Path
5959
)
6060

61-
try createSymlink(at: pathsConfiguration.sdkDirPath.appending("lib64"), pointingTo: "./usr/lib64")
61+
try await createSymlink(at: pathsConfiguration.sdkDirPath.appending("lib64"), pointingTo: "./usr/lib64")
6262

6363
// `libc.so` is a linker script with absolute paths on RHEL, replace with a relative symlink
6464
let libcSO = sdkUsrLib64Path.appending("libc.so")
65-
try removeFile(at: libcSO)
66-
try createSymlink(at: libcSO, pointingTo: "libc.so.6")
65+
try await removeFile(at: libcSO)
66+
try await createSymlink(at: libcSO, pointingTo: "libc.await so.6")
6767
}
6868

69-
try generator.createDirectoryIfNeeded(at: sdkUsrLibPath)
69+
try await generator.createDirectoryIfNeeded(at: sdkUsrLibPath)
7070
for subpath in ["clang", "gcc", "swift", "swift_static"] {
7171
try await generator.copyFromDockerContainer(
7272
id: containerID,
@@ -76,10 +76,10 @@ extension SwiftSDKGenerator {
7676
}
7777

7878
// Python artifacts are redundant.
79-
try generator.removeRecursively(at: sdkUsrLibPath.appending("python3.10"))
79+
try await generator.removeRecursively(at: sdkUsrLibPath.appending("python3.10"))
8080

81-
try generator.createSymlink(at: pathsConfiguration.sdkDirPath.appending("lib"), pointingTo: "usr/lib")
82-
try generator.removeRecursively(at: sdkUsrLibPath.appending("ssl"))
81+
try await generator.createSymlink(at: pathsConfiguration.sdkDirPath.appending("lib"), pointingTo: "usr/lib")
82+
try await generator.removeRecursively(at: sdkUsrLibPath.appending("ssl"))
8383
try await generator.copyTargetSwift(from: sdkUsrLibPath)
8484
try await generator.stopDockerContainer(id: containerID)
8585
}

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Download.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ extension SwiftSDKGenerator {
7878
logGenerationStep("Parsing Ubuntu packages list...")
7979

8080
async let mainPackages = try await client.parseUbuntuPackagesList(
81-
ubuntuRelease: versionsConfiguration.linuxDistribution.release,
81+
ubuntuRelease: self.versionsConfiguration.linuxDistribution.release,
8282
repository: "main",
8383
targetTriple: self.targetTriple,
8484
isVerbose: self.isVerbose
8585
)
8686

8787
async let updatesPackages = try await client.parseUbuntuPackagesList(
88-
ubuntuRelease: versionsConfiguration.linuxDistribution.release,
88+
ubuntuRelease: self.versionsConfiguration.linuxDistribution.release,
8989
releaseSuffix: "-updates",
9090
repository: "main",
9191
targetTriple: self.targetTriple,

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Unpack.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ extension SwiftSDKGenerator {
3838
try await fileSystem.unpack(file: downloadableArtifacts.hostSwift.localPath, into: tmpDir)
3939
// Remove libraries for platforms we don't intend cross-compiling to
4040
for platform in unusedDarwinPlatforms {
41-
try fileSystem.removeRecursively(at: tmpDir.appending("usr/lib/swift/\(platform)"))
41+
try await fileSystem.removeRecursively(at: tmpDir.appending("usr/lib/swift/\(platform)"))
4242
}
43-
try fileSystem.removeRecursively(at: tmpDir.appending("usr/lib/sourcekitd.framework"))
43+
try await fileSystem.removeRecursively(at: tmpDir.appending("usr/lib/sourcekitd.framework"))
4444

4545
for binary in unusedHostBinaries {
46-
try fileSystem.removeRecursively(at: tmpDir.appending("usr/bin/\(binary)"))
46+
try await fileSystem.removeRecursively(at: tmpDir.appending("usr/bin/\(binary)"))
4747
}
4848

4949
try await fileSystem.rsync(from: tmpDir.appending("usr"), to: pathsConfiguration.toolchainDirPath)
@@ -95,10 +95,7 @@ extension SwiftSDKGenerator {
9595
fatalError()
9696
}
9797

98-
try fileSystem.copy(
99-
from: unpackedLLDPath,
100-
to: toolchainLLDPath
101-
)
98+
try await fileSystem.copy(from: unpackedLLDPath, to: toolchainLLDPath)
10299
}
103100
}
104101
}

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Foundation
1414
import SystemPackage
1515

1616
/// This protocol abstracts over possible generators, which allows creating a mock generator for testing purposes.
17-
public protocol SwiftSDKGenerator: AnyObject {
17+
public protocol SwiftSDKGenerator: Actor {
1818
// MARK: configuration
1919

2020
var hostTriple: Triple { get }

Sources/SwiftSDKGenerator/PlatformModels/Triple.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
public struct Triple: CustomStringConvertible {
13+
public struct Triple: Sendable, CustomStringConvertible {
1414
/// CPU architecture supported by the generator.
15-
public enum CPU: String, Decodable, CaseIterable {
15+
public enum CPU: String, Sendable, Decodable, CaseIterable {
1616
case x86_64
1717
case arm64
1818

Sources/SwiftSDKGenerator/SystemUtils/Shell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Foundation
1414
import struct SystemPackage.FilePath
1515

16-
public struct CommandInfo {
16+
public struct CommandInfo: Sendable {
1717
let command: String
1818
let currentDirectory: FilePath?
1919
let file: String

Tests/SwiftSDKGeneratorTests/ArchitectureMappingTests.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ final class ArchitectureMappingTests: XCTestCase {
6060
isVerbose: false
6161
)
6262

63-
XCTAssertEqual(sdk.artifactID, artifactID, "Unexpected artifactID")
63+
let sdkArtifactID = await sdk.artifactID
64+
XCTAssertEqual(sdkArtifactID, artifactID, "Unexpected artifactID")
6465

6566
// Verify download URLs
66-
let artifacts = sdk.downloadableArtifacts
67+
let artifacts = await sdk.downloadableArtifacts
6768

6869
// The build-time Swift SDK is a multiarch package and so is always the same
6970
XCTAssertEqual(
@@ -87,7 +88,7 @@ final class ArchitectureMappingTests: XCTestCase {
8788
)
8889

8990
// Verify paths within the bundle
90-
let paths = sdk.pathsConfiguration
91+
let paths = await sdk.pathsConfiguration
9192

9293
// The bundle path is not critical - it uses Swift's name
9394
// for the target architecture

0 commit comments

Comments
 (0)