Skip to content

Commit 0f2fc45

Browse files
committed
Add support for catalyst
C++ implementation: swiftlang/swift#29017 Also fixes test/Driver/print_target_info.swift
1 parent c835d02 commit 0f2fc45

13 files changed

+277
-41
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public struct Driver {
5959
/// The target triple.
6060
public let targetTriple: Triple
6161

62+
/// The variant target triple.
63+
public let targetVariantTriple: Triple?
64+
6265
/// The toolchain to use for resolution.
6366
public let toolchain: Toolchain
6467

@@ -220,6 +223,7 @@ public struct Driver {
220223
Triple($0, normalizing: true)
221224
}
222225
(self.toolchain, self.targetTriple) = try Self.computeToolchain(explicitTarget, diagnosticsEngine: diagnosticEngine, env: env)
226+
self.targetVariantTriple = self.parsedOptions.getLastArgument(.targetVariant).map { Triple($0.asSingle, normalizing: true) }
223227

224228
// Find the Swift compiler executable.
225229
if let frontendPath = self.parsedOptions.getLastArgument(.driverUseFrontendPath) {

Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ extension DarwinToolchain {
113113

114114
private func addDeploymentTargetArgs(
115115
to commandLine: inout [Job.ArgTemplate],
116-
targetTriple: Triple
116+
targetTriple: Triple,
117+
targetVariantTriple: Triple?
117118
) {
118119
// FIXME: Properly handle deployment targets.
119120

@@ -124,6 +125,8 @@ extension DarwinToolchain {
124125
flag = "-iphoneos_version_min"
125126
case .iOS(.simulator):
126127
flag = "-ios_simulator_version_min"
128+
case .iOS(.catalyst):
129+
flag = "-maccatalyst_version_min"
127130
case .macOS:
128131
flag = "-macosx_version_min"
129132
case .tvOS(.device):
@@ -138,6 +141,20 @@ extension DarwinToolchain {
138141

139142
commandLine.appendFlag(flag)
140143
commandLine.appendFlag(targetTriple.version().description)
144+
145+
if let variant = targetVariantTriple {
146+
if targetTriple.isiOS {
147+
assert(targetTriple.isValidForZipperingWithTriple(variant))
148+
assert(variant.isMacOSX)
149+
commandLine.appendFlag("-macosx_version_min")
150+
commandLine.appendFlag(variant.version().description)
151+
} else {
152+
assert(targetTriple.isValidForZipperingWithTriple(variant))
153+
assert(variant.isMacCatalyst)
154+
commandLine.appendFlag("-maccatalyst_version_min")
155+
commandLine.appendFlag(variant.version().description)
156+
}
157+
}
141158
}
142159

143160
private func addArgsToLinkARCLite(
@@ -178,7 +195,8 @@ extension DarwinToolchain {
178195
outputFile: VirtualPath,
179196
sdkPath: String?,
180197
sanitizers: Set<Sanitizer>,
181-
targetTriple: Triple
198+
targetTriple: Triple,
199+
targetVariantTriple: Triple?
182200
) throws -> AbsolutePath {
183201

184202
// FIXME: If we used Clang as a linker instead of going straight to ld,
@@ -262,7 +280,8 @@ extension DarwinToolchain {
262280
)
263281
addDeploymentTargetArgs(
264282
to: &commandLine,
265-
targetTriple: targetTriple
283+
targetTriple: targetTriple,
284+
targetVariantTriple: targetVariantTriple
266285
)
267286
try addProfileGenerationArgs(
268287
to: &commandLine,

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ extension Driver {
5454
}
5555
}
5656

57+
if let variant = parsedOptions.getLastArgument(.targetVariant)?.asSingle {
58+
commandLine.appendFlag(.targetVariant)
59+
commandLine.appendFlag(Triple(variant, normalizing: true).triple)
60+
}
61+
5762
// Enable address top-byte ignored in the ARM64 backend.
5863
if (targetTriple.arch == .aarch64) {
5964
commandLine.appendFlag(.Xllvm)

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ extension GenericUnixToolchain {
5050
outputFile: VirtualPath,
5151
sdkPath: String?,
5252
sanitizers: Set<Sanitizer>,
53-
targetTriple: Triple
53+
targetTriple: Triple,
54+
targetVariantTriple: Triple?
5455
) throws -> AbsolutePath {
5556
switch linkerOutputType {
5657
case .dynamicLibrary:

Sources/SwiftDriver/Jobs/LinkJob.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ extension Driver {
4848
outputFile: outputFile,
4949
sdkPath: sdkPath,
5050
sanitizers: enabledSanitizers,
51-
targetTriple: targetTriple
51+
targetTriple: targetTriple,
52+
targetVariantTriple: targetVariantTriple
5253
)
5354

5455
// TODO: some, but not all, linkers support response files.

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ extension Driver {
172172
var commandLine: [Job.ArgTemplate] = [.flag("-frontend"),
173173
.flag("-print-target-info")]
174174
try commandLine.appendLast(.target, from: &parsedOptions)
175+
try commandLine.appendLast(.targetVariant, from: &parsedOptions)
175176
try commandLine.appendLast(.sdk, from: &parsedOptions)
176177
try commandLine.appendLast(.resourceDir, from: &parsedOptions)
177178
return Job(kind: .printTargetInfo,

Sources/SwiftDriver/Jobs/Toolchain+LinkerSupport.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ extension Toolchain {
3737
return resourceDirBase.appending(components: triple.platformName() ?? "")
3838
}
3939

40+
func computeSecondaryResourceDirPath(for triple: Triple, primaryPath: AbsolutePath) -> AbsolutePath? {
41+
guard triple.isMacCatalyst else { return nil }
42+
return primaryPath.parentDirectory.appending(component: "macosx")
43+
}
44+
4045
func clangLibraryPath(
4146
for triple: Triple,
4247
parsedOptions: inout ParsedOptions
@@ -55,13 +60,25 @@ extension Toolchain {
5560
sdkPath: String?,
5661
isShared: Bool
5762
) throws -> [AbsolutePath] {
58-
var result = [try computeResourceDirPath(
63+
let resourceDirPath = try computeResourceDirPath(
5964
for: triple,
6065
parsedOptions: &parsedOptions,
61-
isShared: isShared)]
66+
isShared: isShared)
67+
var result = [resourceDirPath]
68+
69+
let secondaryResourceDir = computeSecondaryResourceDirPath(for: triple, primaryPath: resourceDirPath)
70+
if let path = secondaryResourceDir {
71+
result.append(path)
72+
}
6273

6374
if let path = sdkPath {
64-
result.append(AbsolutePath(path).appending(RelativePath("usr/lib/swift")))
75+
let sdkPath = AbsolutePath(path)
76+
// If we added the secondary resource dir, we also need the iOSSupport directory.
77+
if secondaryResourceDir != nil {
78+
result.append(sdkPath.appending(components: "System", "iOSSupport", "usr", "lib", "swift"))
79+
}
80+
81+
result.append(sdkPath.appending(RelativePath("usr/lib/swift")))
6582
}
6683

6784
return result

0 commit comments

Comments
 (0)