Skip to content

[6.0.2] Only pass a versioned prebuilt-modules for Mac Catalyst if it exists. #1698

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

Closed
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
25 changes: 20 additions & 5 deletions Sources/SwiftDriver/Toolchains/DarwinToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,27 @@ public final class DarwinToolchain: Toolchain {
// doesn't always match the macosx sdk version so the compiler may fail to find
// the prebuilt module in the versioned sub-dir.
if frontendTargetInfo.target.triple.isMacCatalyst {
let resourceDirPath = VirtualPath.lookup(frontendTargetInfo.runtimeResourcePath.path)
let basePrebuiltModulesPath = resourceDirPath.appending(components: "macosx", "prebuilt-modules")

// Ensure we pass a path that exists. This matches logic used in the Swift frontend.
let prebuiltModulesPath: VirtualPath = try {
var versionString = sdkInfo.versionString
repeat {
let versionedPrebuiltModulesPath =
basePrebuiltModulesPath.appending(component: versionString)
if try fileSystem.exists(versionedPrebuiltModulesPath) {
return versionedPrebuiltModulesPath
} else if versionString.hasSuffix(".0") {
versionString.removeLast(2)
} else {
return basePrebuiltModulesPath
}
} while true
}()

commandLine.appendFlag(.prebuiltModuleCachePath)
commandLine.appendPath(try getToolPath(.swiftCompiler).parentDirectory/*bin*/
.parentDirectory/*usr*/
.appending(component: "lib").appending(component: "swift")
.appending(component: "macosx").appending(component: "prebuilt-modules")
.appending(component: sdkInfo.versionString))
commandLine.appendPath(prebuiltModulesPath)
}

// Pass down -clang-target.
Expand Down
24 changes: 22 additions & 2 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7029,14 +7029,34 @@ final class SwiftDriverTests: XCTestCase {
try testInputsPath.appending(component: "mock-sdk.sdk").nativePathString(escaped: false)

do {
var driver = try Driver(args: ["swiftc", "-target", "x86_64-apple-ios13.1-macabi", "foo.swift", "-sdk", mockSDKPath],
let resourceDirPath: String = try testInputsPath.appending(components: "PrebuiltModules-macOS10.15.xctoolchain", "usr", "lib", "swift").nativePathString(escaped: false)

var driver = try Driver(args: ["swiftc", "-target", "x86_64-apple-ios13.1-macabi", "foo.swift", "-sdk", mockSDKPath, "-resource-dir", resourceDirPath],
env: envVars)
let plannedJobs = try driver.planBuild()
let job = plannedJobs[0]
XCTAssertTrue(job.commandLine.contains(.flag("-prebuilt-module-cache-path")))
XCTAssertTrue(job.commandLine.contains { arg in
if case .path(let curPath) = arg {
if curPath.basename == "10.15" && curPath.parentDirectory.basename == "prebuilt-modules" && curPath.parentDirectory.parentDirectory.basename == "macosx" {
return true
}
}
return false
})
}

do {
let resourceDirPath: String = try testInputsPath.appending(components: "PrebuiltModules-macOSUnversioned.xctoolchain", "usr", "lib", "swift").nativePathString(escaped: false)

var driver = try Driver(args: ["swiftc", "-target", "x86_64-apple-ios13.1-macabi", "foo.swift", "-sdk", mockSDKPath, "-resource-dir", resourceDirPath],
env: envVars)
let plannedJobs = try driver.planBuild()
let job = plannedJobs[0]
XCTAssertTrue(job.commandLine.contains(.flag("-prebuilt-module-cache-path")))
XCTAssertTrue(job.commandLine.contains { arg in
if case .path(let curPath) = arg {
if curPath.basename == "10.15" && curPath.parentDirectory.basename == "prebuilt-modules" {
if curPath.basename == "prebuilt-modules" && curPath.parentDirectory.basename == "macosx" {
return true
}
}
Expand Down