@@ -371,7 +371,7 @@ public final class DarwinToolchain: Toolchain {
371
371
commandLine: inout [ Job . ArgTemplate ] ,
372
372
inputs: inout [ TypedVirtualPath ] ,
373
373
frontendTargetInfo: FrontendTargetInfo ,
374
- driver: Driver
374
+ driver: inout Driver
375
375
) throws {
376
376
guard let sdkPath = frontendTargetInfo. sdkPath? . path,
377
377
let sdkInfo = getTargetSDKInfo ( sdkPath: sdkPath) else { return }
@@ -401,6 +401,29 @@ public final class DarwinToolchain: Toolchain {
401
401
. appending ( component: " macosx " ) . appending ( component: " prebuilt-modules " )
402
402
. appending ( component: sdkInfo. versionString) )
403
403
}
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
+ }
404
427
}
405
428
}
406
429
0 commit comments