Skip to content

Use swiftCompilerTag for the swift compiler version #8959

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 2 commits into from
Jul 22, 2025
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
7 changes: 6 additions & 1 deletion Sources/PackageModel/UserToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,12 @@ public final class UserToolchain: Toolchain {
}

private static func computeSwiftCompilerVersion(targetInfo: JSON) -> String? {
// Get the compiler version from the target info
// Use the new swiftCompilerTag if it's there
if let swiftCompilerTag: String = targetInfo.get("swiftCompilerTag") {
return swiftCompilerTag
}

// Default to the swift portion of the compilerVersion
let compilerVersion: String
do {
compilerVersion = try targetInfo.get("compilerVersion")
Expand Down
5 changes: 5 additions & 0 deletions Sources/Workspace/Workspace+Prebuilts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ extension Workspace {
identity: .plain("swift-syntax"),
kind: .remoteSourceControl("https://github.com/swiftlang/swift-syntax.git")
),
// The old site that's being redirected but still in use.
.init(
identity: .plain("swift-syntax"),
kind: .remoteSourceControl("https://github.com/apple/swift-syntax.git")
),
.init(
identity: .plain("swift-syntax"),
kind: .remoteSourceControl("[email protected]:swiftlang/swift-syntax.git")
Expand Down
61 changes: 61 additions & 0 deletions Tests/WorkspaceTests/PrebuiltsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,67 @@ final class PrebuiltsTests: XCTestCase {
}
}

func testRedirectURL() async throws {
let sandbox = AbsolutePath("/tmp/ws")
let fs = InMemoryFileSystem()
let artifact = Data()

try await with(fileSystem: fs, artifact: artifact, swiftSyntaxVersion: "600.0.1", swiftSyntaxURL: "https://github.com/apple/swift-syntax.git") {
manifest, rootCertPath, rootPackage, swiftSyntax in

let manifestData = try JSONEncoder().encode(manifest)

let httpClient = HTTPClient { request, progressHandler in
guard case .download(let fileSystem, let destination) = request.kind else {
throw StringError("invalid request \(request.kind)")
}

if request.url == "https://download.swift.org/prebuilts/swift-syntax/600.0.1/\(self.swiftVersion)-manifest.json" {
try fileSystem.writeFileContents(destination, data: manifestData)
return .okay()
} else if request.url == "https://download.swift.org/prebuilts/swift-syntax/600.0.1/\(self.swiftVersion)-MacroSupport-macos_aarch64.zip" {
try fileSystem.writeFileContents(destination, data: artifact)
return .okay()
} else {
XCTFail("Unexpected URL \(request.url)")
return .notFound()
}
}

let archiver = MockArchiver(handler: { _, archivePath, destination, completion in
XCTAssertEqual(archivePath, sandbox.appending(components: ".build", "prebuilts", "swift-syntax", "600.0.1", "\(self.swiftVersion)-MacroSupport-macos_aarch64.zip"))
XCTAssertEqual(destination, sandbox.appending(components: ".build", "prebuilts", "swift-syntax", "600.0.1", "\(self.swiftVersion)-MacroSupport-macos_aarch64"))
completion(.success(()))
})

let workspace = try await MockWorkspace(
sandbox: sandbox,
fileSystem: fs,
roots: [
rootPackage
],
packages: [
swiftSyntax
],
prebuiltsManager: .init(
swiftVersion: swiftVersion,
httpClient: httpClient,
archiver: archiver,
hostPlatform: .macos_aarch64,
rootCertPath: rootCertPath
)
)

try await workspace.checkPackageGraph(roots: ["Foo"]) { modulesGraph, diagnostics in
XCTAssertTrue(diagnostics.filter({ $0.severity == .error }).isEmpty)
let rootPackage = try XCTUnwrap(modulesGraph.rootPackages.first)
try checkSettings(rootPackage, "FooMacros", usePrebuilt: true)
try checkSettings(rootPackage, "FooTests", usePrebuilt: true)
try checkSettings(rootPackage, "Foo", usePrebuilt: false)
try checkSettings(rootPackage, "FooClient", usePrebuilt: false)
}
}
}
func testCachedArtifact() async throws {
let sandbox = AbsolutePath("/tmp/ws")
let fs = InMemoryFileSystem()
Expand Down