Skip to content

Enable complete concurrency checking, fix warnings #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ let package = Package(
dependencies: [
"SwiftSDKGenerator",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency=complete"),
]
),
.target(
Expand All @@ -43,12 +46,18 @@ let package = Package(
.product(name: "AsyncHTTPClient", package: "async-http-client"),
.product(name: "SystemPackage", package: "swift-system"),
],
exclude: ["Dockerfiles"]
exclude: ["Dockerfiles"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency=complete"),
]
),
.testTarget(
name: "SwiftSDKGeneratorTests",
dependencies: [
.target(name: "SwiftSDKGenerator"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency=complete"),
]
),
.target(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Foundation
import SystemPackage

/// Implementation of ``SwiftSDKGenerator`` for the local file system.
public final class LocalSwiftSDKGenerator: SwiftSDKGenerator {
public actor LocalSwiftSDKGenerator: SwiftSDKGenerator {
public let hostTriple: Triple
public let targetTriple: Triple
public let artifactID: String
Expand Down Expand Up @@ -146,7 +146,7 @@ public final class LocalSwiftSDKGenerator: SwiftSDKGenerator {

public func buildDockerImage(baseImage: String) async throws -> String {
try await self.inTemporaryDirectory { generator, tmp in
try generator.writeFile(
try await generator.writeFile(
at: tmp.appending("Dockerfile"),
Data(
"""
Expand Down Expand Up @@ -359,7 +359,7 @@ public final class LocalSwiftSDKGenerator: SwiftSDKGenerator {
return buildDirectory
}

public func inTemporaryDirectory<T>(
public func inTemporaryDirectory<T: Sendable>(
_ closure: @Sendable (LocalSwiftSDKGenerator, FilePath) async throws -> T
) async throws -> T {
let tmp = FilePath(NSTemporaryDirectory())
Expand All @@ -374,7 +374,3 @@ public final class LocalSwiftSDKGenerator: SwiftSDKGenerator {
return result
}
}

// Explicitly marking `LocalSwiftSDKGenerator` as non-`Sendable` for safety.
@available(*, unavailable)
extension LocalSwiftSDKGenerator: Sendable {}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ extension SwiftSDKGenerator {
try await inTemporaryDirectory { generator, _ in
let sdkUsrPath = pathsConfiguration.sdkDirPath.appending("usr")
let sdkUsrLibPath = sdkUsrPath.appending("lib")
try generator.createDirectoryIfNeeded(at: sdkUsrPath)
try await generator.createDirectoryIfNeeded(at: sdkUsrPath)
try await generator.copyFromDockerContainer(
id: containerID,
from: "/usr/include",
to: sdkUsrPath.appending("include")
)

if case .rhel = self.versionsConfiguration.linuxDistribution {
if case .rhel = await self.versionsConfiguration.linuxDistribution {
try await generator.runOnDockerContainer(
id: containerID,
command: #"""
Expand All @@ -58,15 +58,15 @@ extension SwiftSDKGenerator {
to: sdkUsrLib64Path
)

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

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

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

// Python artifacts are redundant.
try generator.removeRecursively(at: sdkUsrLibPath.appending("python3.10"))
try await generator.removeRecursively(at: sdkUsrLibPath.appending("python3.10"))

try generator.createSymlink(at: pathsConfiguration.sdkDirPath.appending("lib"), pointingTo: "usr/lib")
try generator.removeRecursively(at: sdkUsrLibPath.appending("ssl"))
try await generator.createSymlink(at: pathsConfiguration.sdkDirPath.appending("lib"), pointingTo: "usr/lib")
try await generator.removeRecursively(at: sdkUsrLibPath.appending("ssl"))
try await generator.copyTargetSwift(from: sdkUsrLibPath)
try await generator.stopDockerContainer(id: containerID)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ extension SwiftSDKGenerator {
logGenerationStep("Parsing Ubuntu packages list...")

async let mainPackages = try await client.parseUbuntuPackagesList(
ubuntuRelease: versionsConfiguration.linuxDistribution.release,
ubuntuRelease: self.versionsConfiguration.linuxDistribution.release,
repository: "main",
targetTriple: self.targetTriple,
isVerbose: self.isVerbose
)

async let updatesPackages = try await client.parseUbuntuPackagesList(
ubuntuRelease: versionsConfiguration.linuxDistribution.release,
ubuntuRelease: self.versionsConfiguration.linuxDistribution.release,
releaseSuffix: "-updates",
repository: "main",
targetTriple: self.targetTriple,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ extension SwiftSDKGenerator {
try await fileSystem.unpack(file: downloadableArtifacts.hostSwift.localPath, into: tmpDir)
// Remove libraries for platforms we don't intend cross-compiling to
for platform in unusedDarwinPlatforms {
try fileSystem.removeRecursively(at: tmpDir.appending("usr/lib/swift/\(platform)"))
try await fileSystem.removeRecursively(at: tmpDir.appending("usr/lib/swift/\(platform)"))
}
try fileSystem.removeRecursively(at: tmpDir.appending("usr/lib/sourcekitd.framework"))
try await fileSystem.removeRecursively(at: tmpDir.appending("usr/lib/sourcekitd.framework"))

for binary in unusedHostBinaries {
try fileSystem.removeRecursively(at: tmpDir.appending("usr/bin/\(binary)"))
try await fileSystem.removeRecursively(at: tmpDir.appending("usr/bin/\(binary)"))
}

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

try fileSystem.copy(
from: unpackedLLDPath,
to: toolchainLLDPath
)
try await fileSystem.copy(from: unpackedLLDPath, to: toolchainLLDPath)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Foundation
import SystemPackage

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

var hostTriple: Triple { get }
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftSDKGenerator/PlatformModels/Triple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
//
//===----------------------------------------------------------------------===//

public struct Triple: CustomStringConvertible {
public struct Triple: Sendable, CustomStringConvertible {
/// CPU architecture supported by the generator.
public enum CPU: String, Decodable, CaseIterable {
public enum CPU: String, Sendable, Decodable, CaseIterable {
case x86_64
case arm64

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSDKGenerator/SystemUtils/Shell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import Foundation
import struct SystemPackage.FilePath

public struct CommandInfo {
public struct CommandInfo: Sendable {
let command: String
let currentDirectory: FilePath?
let file: String
Expand Down
7 changes: 4 additions & 3 deletions Tests/SwiftSDKGeneratorTests/ArchitectureMappingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ final class ArchitectureMappingTests: XCTestCase {
isVerbose: false
)

XCTAssertEqual(sdk.artifactID, artifactID, "Unexpected artifactID")
let sdkArtifactID = await sdk.artifactID
XCTAssertEqual(sdkArtifactID, artifactID, "Unexpected artifactID")

// Verify download URLs
let artifacts = sdk.downloadableArtifacts
let artifacts = await sdk.downloadableArtifacts

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

// Verify paths within the bundle
let paths = sdk.pathsConfiguration
let paths = await sdk.pathsConfiguration

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