Skip to content

Commit 955043f

Browse files
committed
Enable -clang-target on Darwin platforms set to the SDK version by-default
1 parent fc4753a commit 955043f

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,6 @@ extension Driver {
7272
break
7373
}
7474

75-
// Pass down -clang-target.
76-
// If not specified otherwise, we should use the same triple as -target
77-
// TODO: enable -clang-target for implicit module build as well.
78-
if !parsedOptions.hasArgument(.disableClangTarget) &&
79-
isFrontendArgSupported(.clangTarget) &&
80-
parsedOptions.contains(.driverExplicitModuleBuild) {
81-
let clangTriple = parsedOptions.getLastArgument(.clangTarget)?.asSingle ?? targetTriple.triple
82-
commandLine.appendFlag(.clangTarget)
83-
commandLine.appendFlag(clangTriple)
84-
}
85-
8675
// If in ExplicitModuleBuild mode and the dependency graph has been computed, add module
8776
// dependencies.
8877
// May also be used for generation of the dependency graph itself in ExplicitModuleBuild mode.
@@ -324,7 +313,7 @@ extension Driver {
324313
try toolchain.addPlatformSpecificCommonFrontendOptions(commandLine: &commandLine,
325314
inputs: &inputs,
326315
frontendTargetInfo: frontendTargetInfo,
327-
driver: self)
316+
driver: &self)
328317
}
329318

330319
mutating func addFrontendSupplementaryOutputArguments(commandLine: inout [Job.ArgTemplate],

Sources/SwiftDriver/Toolchains/DarwinToolchain.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public final class DarwinToolchain: Toolchain {
371371
commandLine: inout [Job.ArgTemplate],
372372
inputs: inout [TypedVirtualPath],
373373
frontendTargetInfo: FrontendTargetInfo,
374-
driver: Driver
374+
driver: inout Driver
375375
) throws {
376376
guard let sdkPath = frontendTargetInfo.sdkPath?.path,
377377
let sdkInfo = getTargetSDKInfo(sdkPath: sdkPath) else { return }
@@ -401,6 +401,29 @@ public final class DarwinToolchain: Toolchain {
401401
.appending(component: "macosx").appending(component: "prebuilt-modules")
402402
.appending(component: sdkInfo.versionString))
403403
}
404+
405+
// Pass down -clang-target.
406+
// If not specified otherwise, we should use the same triple as -target
407+
if !driver.parsedOptions.hasArgument(.disableClangTarget) &&
408+
driver.isFrontendArgSupported(.clangTarget) {
409+
// The common target triple for all Clang dependencies of this compilation,
410+
// both direct and transitive is computed as:
411+
// 1. An explicitly-specified `-clang-target` argument to this driver invocation
412+
// 2. (On Darwin) The target triple of the selected SDK
413+
let clangTargetTriple: String
414+
if let explicitClangTripleArg = driver.parsedOptions.getLastArgument(.clangTarget)?.asSingle {
415+
clangTargetTriple = explicitClangTripleArg
416+
} else if let sdkPathHandle = frontendTargetInfo.sdkPath?.path,
417+
let sdkPath = VirtualPath.lookup(sdkPathHandle).absolutePath,
418+
let sdkInfo = Self.readSDKInfo(fileSystem, VirtualPath.absolute(sdkPath).intern()) {
419+
clangTargetTriple = frontendTargetInfo.target.unversionedTriple.triple + sdkInfo.versionString
420+
} else {
421+
clangTargetTriple = frontendTargetInfo.target.triple.triple
422+
}
423+
424+
commandLine.appendFlag(.clangTarget)
425+
commandLine.appendFlag(clangTargetTriple)
426+
}
404427
}
405428
}
406429

Sources/SwiftDriver/Toolchains/Toolchain.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public protocol Toolchain {
151151
commandLine: inout [Job.ArgTemplate],
152152
inputs: inout [TypedVirtualPath],
153153
frontendTargetInfo: FrontendTargetInfo,
154-
driver: Driver
154+
driver: inout Driver
155155
) throws
156156

157157
var dummyForTestingObjectFormat: Triple.ObjectFormat {get}
@@ -306,7 +306,7 @@ extension Toolchain {
306306
commandLine: inout [Job.ArgTemplate],
307307
inputs: inout [TypedVirtualPath],
308308
frontendTargetInfo: FrontendTargetInfo,
309-
driver: Driver
309+
driver: inout Driver
310310
) throws {}
311311

312312
/// Resolves the path to the given tool and whether or not it supports response files so that it

0 commit comments

Comments
 (0)