Skip to content

Commit 2159196

Browse files
committed
Only pass a versioned prebuilt-modules for Mac Catalyst if it exists.
Some clients still have unversioned prebuilt modules, but SwiftDriver assumed that the versioned path would always exist for macOS (at least for the purposes of passing it when compiling for Mac Catalyst). This change duplicates some logic from the Swift frontend to check for the existence of the versioned macOS prebuilt modules directory before passing it, optionally stripping off trailing `.0` version components. This addresses <rdar://problem/136047054>.
1 parent 0155ae0 commit 2159196

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Sources/SwiftDriver/Toolchains/DarwinToolchain.swift

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,30 @@ 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-
commandLine.appendFlag(.prebuiltModuleCachePath)
414-
commandLine.appendPath(try getToolPath(.swiftCompiler).parentDirectory/*bin*/
413+
let basePrebuiltModulesPath =
414+
try getToolPath(.swiftCompiler).parentDirectory/*bin*/
415415
.parentDirectory/*usr*/
416416
.appending(component: "lib").appending(component: "swift")
417417
.appending(component: "macosx").appending(component: "prebuilt-modules")
418-
.appending(component: sdkInfo.versionString))
418+
419+
// Ensure we pass a path that exists. This matches logic used in the Swift frontend.
420+
let prebuiltModulesPath: AbsolutePath = {
421+
var versionString = sdkInfo.versionString
422+
repeat {
423+
let versionedPrebuiltModulesPath =
424+
basePrebuiltModulesPath.appending(component: versionString)
425+
if (fileSystem.exists(versionedPrebuiltModulesPath)) {
426+
return versionedPrebuiltModulesPath
427+
} else if versionString.hasSuffix(".0") {
428+
versionString.removeLast(2)
429+
} else {
430+
return basePrebuiltModulesPath
431+
}
432+
} while true
433+
}()
434+
435+
commandLine.appendFlag(.prebuiltModuleCachePath)
436+
commandLine.appendPath(prebuiltModulesPath)
419437
}
420438

421439
// Pass down -clang-target.

0 commit comments

Comments
 (0)