Skip to content

Commit 4796e03

Browse files
committed
Pass-down -clang-target to all frontend jobs
1 parent d93db4a commit 4796e03

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ extension Driver {
6666
}
6767
}
6868

69+
// Pass down -clang-target.
70+
// If not specified otherwise, we should use the same triple as -target
71+
if !parsedOptions.hasArgument(.disableClangTarget) &&
72+
isFrontendArgSupported(.clangTarget) {
73+
let clangTriple = parsedOptions.getLastArgument(.clangTarget)?.asSingle ?? targetTriple.triple
74+
commandLine.appendFlag(.clangTarget)
75+
commandLine.appendFlag(clangTriple)
76+
}
77+
6978
// If in ExplicitModuleBuild mode and the dependency graph has been computed, add module
7079
// dependencies.
7180
// May also be used for generation of the dependency graph itself in ExplicitModuleBuild mode.

Sources/SwiftOptions/Options.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ extension Option {
107107
public static let disableBatchMode: Option = Option("-disable-batch-mode", .flag, attributes: [.helpHidden, .frontend, .noInteractive], helpText: "Disable combining frontend jobs into batches")
108108
public static let disableBridgingPch: Option = Option("-disable-bridging-pch", .flag, attributes: [.helpHidden], helpText: "Disable automatic generation of bridging PCH files")
109109
public static let disableBuildingInterface: Option = Option("-disable-building-interface", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disallow building binary module from textual interface")
110+
public static let disableClangTarget: Option = Option("-disable-clang-target", .flag, attributes: [], helpText: "Disable a separately specified target triple for Clang instance to use")
110111
public static let disableClangimporterSourceImport: Option = Option("-disable-clangimporter-source-import", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disable ClangImporter and forward all requests straight the DWARF importer.")
111112
public static let disableConcreteTypeMetadataMangledNameAccessors: Option = Option("-disable-concrete-type-metadata-mangled-name-accessors", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disable concrete type metadata access by mangled name")
112113
public static let disableConformanceAvailabilityErrors: Option = Option("-disable-conformance-availability-errors", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Diagnose conformance availability violations as warnings")
@@ -354,6 +355,7 @@ extension Option {
354355
public static let importPrescan: Option = Option("-import-prescan", .flag, attributes: [.frontend, .noDriver], helpText: "When performing a dependency scan, only dentify all imports of the main Swift module sources")
355356
public static let importUnderlyingModule: Option = Option("-import-underlying-module", .flag, attributes: [.frontend, .noInteractive], helpText: "Implicitly imports the Objective-C half of a module")
356357
public static let inPlace: Option = Option("-in-place", .flag, attributes: [.noInteractive, .noBatch, .indent], helpText: "Overwrite input file with formatted file.", group: .codeFormatting)
358+
public static let includeSpiSymbols: Option = Option("-include-spi-symbols", .flag, attributes: [.helpHidden, .frontend, .noInteractive, .supplementaryOutput], helpText: "Add symbols with SPI information to the symbol graph")
357359
public static let incremental: Option = Option("-incremental", .flag, attributes: [.helpHidden, .noInteractive, .doesNotAffectIncrementalBuild], helpText: "Perform an incremental build if possible")
358360
public static let indentSwitchCase: Option = Option("-indent-switch-case", .flag, attributes: [.noInteractive, .noBatch, .indent], helpText: "Indent cases in switch statements.", group: .codeFormatting)
359361
public static let indentWidth: Option = Option("-indent-width", .separate, attributes: [.noInteractive, .noBatch, .indent], metaVar: "<n>", helpText: "Number of characters to indent.", group: .codeFormatting)
@@ -510,7 +512,6 @@ extension Option {
510512
public static let silVerifyAll: Option = Option("-sil-verify-all", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Verify SIL after each transform")
511513
public static let silVerifyNone: Option = Option("-sil-verify-none", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Completely disable SIL verification")
512514
public static let skipInheritedDocs: Option = Option("-skip-inherited-docs", .flag, attributes: [.helpHidden, .frontend, .noInteractive, .supplementaryOutput], helpText: "Skip emitting doc comments for members inherited through classes or default implementations")
513-
public static let skipSwifttailccMusttailCheck: Option = Option("-skip-swifttailcc-musttail-check", .flag, attributes: [.helpHidden, .doesNotAffectIncrementalBuild], helpText: "Skip additional LLVM verification that all tail calls from swifttailcc->swifttailcc are marked musttail.")
514515
public static let skipSynthesizedMembers: Option = Option("-skip-synthesized-members", .flag, attributes: [.noDriver], helpText: "Skip members inherited through classes or default implementations")
515516
public static let solverDisableShrink: Option = Option("-solver-disable-shrink", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disable the shrink phase of expression type checking")
516517
public static let solverExpressionTimeThresholdEQ: Option = Option("-solver-expression-time-threshold=", .joined, attributes: [.helpHidden, .frontend, .noDriver])
@@ -589,6 +590,7 @@ extension Option {
589590
public static let warnLongExpressionTypeChecking: Option = Option("-warn-long-expression-type-checking", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<n>", helpText: "Warns when type-checking a function takes longer than <n> ms")
590591
public static let warnLongFunctionBodiesEQ: Option = Option("-warn-long-function-bodies=", .joined, alias: Option.warnLongFunctionBodies, attributes: [.helpHidden, .frontend, .noDriver])
591592
public static let warnLongFunctionBodies: Option = Option("-warn-long-function-bodies", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<n>", helpText: "Warns when type-checking a function takes longer than <n> ms")
593+
public static let warnOnPotentiallyUnavailableEnumCase: Option = Option("-warn-on-potentially-unavailable-enum-case", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Downgrade potential unavailability of enum case to a warning")
592594
public static let warnSwift3ObjcInferenceComplete: Option = Option("-warn-swift3-objc-inference-complete", .flag, attributes: [.frontend, .doesNotAffectIncrementalBuild], helpText: "Warn about deprecated @objc inference in Swift 3 for every declaration that will no longer be inferred as @objc in Swift 4")
593595
public static let warnSwift3ObjcInferenceMinimal: Option = Option("-warn-swift3-objc-inference-minimal", .flag, attributes: [.frontend, .doesNotAffectIncrementalBuild], helpText: "Warn about deprecated @objc inference in Swift 3 based on direct uses of the Objective-C entrypoint")
594596
public static let warnSwift3ObjcInference: Option = Option("-warn-swift3-objc-inference", .flag, alias: Option.warnSwift3ObjcInferenceComplete, attributes: [.helpHidden, .frontend, .doesNotAffectIncrementalBuild])
@@ -704,6 +706,7 @@ extension Option {
704706
Option.disableBatchMode,
705707
Option.disableBridgingPch,
706708
Option.disableBuildingInterface,
709+
Option.disableClangTarget,
707710
Option.disableClangimporterSourceImport,
708711
Option.disableConcreteTypeMetadataMangledNameAccessors,
709712
Option.disableConformanceAvailabilityErrors,
@@ -951,6 +954,7 @@ extension Option {
951954
Option.importPrescan,
952955
Option.importUnderlyingModule,
953956
Option.inPlace,
957+
Option.includeSpiSymbols,
954958
Option.incremental,
955959
Option.indentSwitchCase,
956960
Option.indentWidth,
@@ -1107,7 +1111,6 @@ extension Option {
11071111
Option.silVerifyAll,
11081112
Option.silVerifyNone,
11091113
Option.skipInheritedDocs,
1110-
Option.skipSwifttailccMusttailCheck,
11111114
Option.skipSynthesizedMembers,
11121115
Option.solverDisableShrink,
11131116
Option.solverExpressionTimeThresholdEQ,
@@ -1186,6 +1189,7 @@ extension Option {
11861189
Option.warnLongExpressionTypeChecking,
11871190
Option.warnLongFunctionBodiesEQ,
11881191
Option.warnLongFunctionBodies,
1192+
Option.warnOnPotentiallyUnavailableEnumCase,
11891193
Option.warnSwift3ObjcInferenceComplete,
11901194
Option.warnSwift3ObjcInferenceMinimal,
11911195
Option.warnSwift3ObjcInference,

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,6 +2439,25 @@ final class SwiftDriverTests: XCTestCase {
24392439
}
24402440
}
24412441

2442+
func testClangTarget() throws {
2443+
var driver = try Driver(args: ["swiftc", "-target",
2444+
"x86_64-apple-macosx10.14", "foo.swift", "bar.swift"])
2445+
let plannedJobs = try driver.planBuild()
2446+
XCTAssertEqual(plannedJobs.count, 3)
2447+
XCTAssert(plannedJobs[0].commandLine.contains(.flag("-target")))
2448+
XCTAssert(plannedJobs[0].commandLine.contains(.flag("-clang-target")))
2449+
XCTAssert(plannedJobs[1].commandLine.contains(.flag("-target")))
2450+
XCTAssert(plannedJobs[1].commandLine.contains(.flag("-clang-target")))
2451+
}
2452+
2453+
func testDisableClangTarget() throws {
2454+
var driver = try Driver(args: ["swiftc", "-target",
2455+
"x86_64-apple-macosx10.14", "foo.swift", "-disable-clang-target"])
2456+
let plannedJobs = try driver.planBuild()
2457+
XCTAssertEqual(plannedJobs.count, 2)
2458+
XCTAssert(plannedJobs[0].commandLine.contains(.flag("-target")))
2459+
XCTAssertFalse(plannedJobs[0].commandLine.contains(.flag("-clang-target")))
2460+
}
24422461

24432462
func testPCHasCompileInput() throws {
24442463
var driver = try Driver(args: ["swiftc", "-target", "x86_64-apple-macosx10.14", "-enable-bridging-pch", "-import-objc-header", "TestInputHeader.h", "foo.swift"])

0 commit comments

Comments
 (0)