Skip to content

Commit 3176929

Browse files
authored
Merge pull request #1695 from swiftlang/dev/check-for-existence-before-passing-Catalyst-prebuilt-modules
Only pass a versioned prebuilt-modules for Mac Catalyst if it exists.
2 parents c0289c4 + b1573ef commit 3176929

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

Sources/SwiftDriver/Toolchains/DarwinToolchain.swift

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,27 @@ public final class DarwinToolchain: Toolchain {
410410
// doesn't always match the macosx sdk version so the compiler may fail to find
411411
// the prebuilt module in the versioned sub-dir.
412412
if frontendTargetInfo.target.triple.isMacCatalyst {
413+
let resourceDirPath = VirtualPath.lookup(frontendTargetInfo.runtimeResourcePath.path)
414+
let basePrebuiltModulesPath = resourceDirPath.appending(components: "macosx", "prebuilt-modules")
415+
416+
// Ensure we pass a path that exists. This matches logic used in the Swift frontend.
417+
let prebuiltModulesPath: VirtualPath = try {
418+
var versionString = sdkInfo.versionString
419+
repeat {
420+
let versionedPrebuiltModulesPath =
421+
basePrebuiltModulesPath.appending(component: versionString)
422+
if try fileSystem.exists(versionedPrebuiltModulesPath) {
423+
return versionedPrebuiltModulesPath
424+
} else if versionString.hasSuffix(".0") {
425+
versionString.removeLast(2)
426+
} else {
427+
return basePrebuiltModulesPath
428+
}
429+
} while true
430+
}()
431+
413432
commandLine.appendFlag(.prebuiltModuleCachePath)
414-
commandLine.appendPath(try getToolPath(.swiftCompiler).parentDirectory/*bin*/
415-
.parentDirectory/*usr*/
416-
.appending(component: "lib").appending(component: "swift")
417-
.appending(component: "macosx").appending(component: "prebuilt-modules")
418-
.appending(component: sdkInfo.versionString))
433+
commandLine.appendPath(prebuiltModulesPath)
419434
}
420435

421436
// Pass down -clang-target.

TestInputs/PrebuiltModules-macOS10.15.xctoolchain/usr/lib/swift/macosx/prebuilt-modules/10.15/.empty-file

Whitespace-only changes.

TestInputs/PrebuiltModules-macOSUnversioned.xctoolchain/usr/lib/swift/macosx/prebuilt-modules/.empty-file

Whitespace-only changes.

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7188,14 +7188,34 @@ final class SwiftDriverTests: XCTestCase {
71887188
try testInputsPath.appending(component: "mock-sdk.sdk").nativePathString(escaped: false)
71897189

71907190
do {
7191-
var driver = try Driver(args: ["swiftc", "-target", "x86_64-apple-ios13.1-macabi", "foo.swift", "-sdk", mockSDKPath],
7191+
let resourceDirPath: String = try testInputsPath.appending(components: "PrebuiltModules-macOS10.15.xctoolchain", "usr", "lib", "swift").nativePathString(escaped: false)
7192+
7193+
var driver = try Driver(args: ["swiftc", "-target", "x86_64-apple-ios13.1-macabi", "foo.swift", "-sdk", mockSDKPath, "-resource-dir", resourceDirPath],
7194+
env: envVars)
7195+
let plannedJobs = try driver.planBuild()
7196+
let job = plannedJobs[0]
7197+
XCTAssertTrue(job.commandLine.contains(.flag("-prebuilt-module-cache-path")))
7198+
XCTAssertTrue(job.commandLine.contains { arg in
7199+
if case .path(let curPath) = arg {
7200+
if curPath.basename == "10.15" && curPath.parentDirectory.basename == "prebuilt-modules" && curPath.parentDirectory.parentDirectory.basename == "macosx" {
7201+
return true
7202+
}
7203+
}
7204+
return false
7205+
})
7206+
}
7207+
7208+
do {
7209+
let resourceDirPath: String = try testInputsPath.appending(components: "PrebuiltModules-macOSUnversioned.xctoolchain", "usr", "lib", "swift").nativePathString(escaped: false)
7210+
7211+
var driver = try Driver(args: ["swiftc", "-target", "x86_64-apple-ios13.1-macabi", "foo.swift", "-sdk", mockSDKPath, "-resource-dir", resourceDirPath],
71927212
env: envVars)
71937213
let plannedJobs = try driver.planBuild()
71947214
let job = plannedJobs[0]
71957215
XCTAssertTrue(job.commandLine.contains(.flag("-prebuilt-module-cache-path")))
71967216
XCTAssertTrue(job.commandLine.contains { arg in
71977217
if case .path(let curPath) = arg {
7198-
if curPath.basename == "10.15" && curPath.parentDirectory.basename == "prebuilt-modules" {
7218+
if curPath.basename == "prebuilt-modules" && curPath.parentDirectory.basename == "macosx" {
71997219
return true
72007220
}
72017221
}

0 commit comments

Comments
 (0)