@@ -77,14 +77,19 @@ public struct Driver {
77
77
/// The executor the driver uses to run jobs.
78
78
public let executor : DriverExecutor
79
79
80
+ /// The toolchain to use for resolution.
81
+ public let toolchain : Toolchain
82
+
83
+ /// Information about the target, as reported by the Swift frontend.
84
+ let frontendTargetInfo : FrontendTargetInfo
85
+
80
86
/// The target triple.
81
- public let targetTriple : Triple
87
+ public var targetTriple : Triple { frontendTargetInfo . target . triple }
82
88
83
89
/// The variant target triple.
84
- public let targetVariantTriple : Triple ?
85
-
86
- /// The toolchain to use for resolution.
87
- public let toolchain : Toolchain
90
+ public var targetVariantTriple : Triple ? {
91
+ frontendTargetInfo. targetVariant? . triple
92
+ }
88
93
89
94
/// The kind of driver.
90
95
public let driverKind : DriverKind
@@ -246,12 +251,13 @@ public struct Driver {
246
251
self . optionTable = OptionTable ( )
247
252
self . parsedOptions = try optionTable. parse ( Array ( args) , for: self . driverKind)
248
253
249
- let explicitTarget = ( self . parsedOptions. getLastArgument ( . target) ? . asSingle)
250
- . map {
251
- Triple ( $0, normalizing: true )
252
- }
253
- ( self . toolchain, self . targetTriple) = try Self . computeToolchain ( explicitTarget, diagnosticsEngine: diagnosticEngine, env: env, executor: self . executor, fileSystem: fileSystem)
254
- self . targetVariantTriple = self . parsedOptions. getLastArgument ( . targetVariant) . map { Triple ( $0. asSingle, normalizing: true ) }
254
+ ( self . toolchain, self . frontendTargetInfo) = try Self . computeToolchain (
255
+ & self . parsedOptions, diagnosticsEngine: diagnosticEngine, env: env,
256
+ executor: self . executor, fileSystem: fileSystem)
257
+
258
+ // Local variable to alias the target triple, because self.targetTriple
259
+ // is not available until the end of this initializer.
260
+ let targetTriple = self . frontendTargetInfo. target. triple
255
261
256
262
// Find the Swift compiler executable.
257
263
if let frontendPath = self . parsedOptions. getLastArgument ( . driverUseFrontendPath) {
@@ -342,7 +348,8 @@ public struct Driver {
342
348
actualSwiftVersion: try ? toolchain. swiftCompilerVersion ( )
343
349
)
344
350
345
- self . sdkPath = Self . computeSDKPath ( & parsedOptions, compilerMode: compilerMode, toolchain: toolchain, fileSystem: fileSystem, diagnosticsEngine: diagnosticEngine, env: env)
351
+ self . sdkPath = Self . computeSDKPath ( & parsedOptions, compilerMode: compilerMode, toolchain: toolchain, targetTriple: targetTriple,
352
+ fileSystem: fileSystem, diagnosticsEngine: diagnosticEngine, env: env)
346
353
347
354
self . importedObjCHeader = try Self . computeImportedObjCHeader ( & parsedOptions, compilerMode: compilerMode, diagnosticEngine: diagnosticEngine)
348
355
self . bridgingPrecompiledHeader = try Self . computeBridgingPrecompiledHeader ( & parsedOptions,
@@ -664,7 +671,7 @@ extension Driver {
664
671
665
672
if parsedOptions. contains ( . driverPrintBindings) {
666
673
for job in jobs {
667
- try printBindings ( job)
674
+ printBindings ( job)
668
675
}
669
676
return
670
677
}
@@ -728,8 +735,8 @@ extension Driver {
728
735
print ( result)
729
736
}
730
737
731
- private func printBindings( _ job: Job ) throws {
732
- try stdoutStream <<< #"# ""# <<< toolchain . hostTargetTriple ( ) . triple
738
+ private func printBindings( _ job: Job ) {
739
+ stdoutStream <<< #"# ""# <<< targetTriple . triple
733
740
stdoutStream <<< #"" - ""# <<< job. tool. basename
734
741
stdoutStream <<< #"", inputs: ["#
735
742
stdoutStream <<< job. inputs. map { " \" " + $0. file. name + " \" " } . joined ( separator: " , " )
@@ -1416,6 +1423,7 @@ extension Driver {
1416
1423
_ parsedOptions: inout ParsedOptions ,
1417
1424
compilerMode: CompilerMode ,
1418
1425
toolchain: Toolchain ,
1426
+ targetTriple: Triple ,
1419
1427
fileSystem: FileSystem ,
1420
1428
diagnosticsEngine: DiagnosticsEngine ,
1421
1429
env: [ String : String ]
@@ -1427,8 +1435,7 @@ extension Driver {
1427
1435
} else if let SDKROOT = env [ " SDKROOT " ] {
1428
1436
sdkPath = SDKROOT
1429
1437
} else if compilerMode == . immediate || compilerMode == . repl {
1430
- let triple = try ? toolchain. hostTargetTriple ( )
1431
- if triple? . isMacOSX == true {
1438
+ if targetTriple. isMacOSX == true {
1432
1439
// In immediate modes, use the SDK provided by xcrun.
1433
1440
// This will prefer the SDK alongside the Swift found by "xcrun swift".
1434
1441
// We don't do this in compilation modes because defaulting to the
@@ -1573,16 +1580,53 @@ extension Driver {
1573
1580
#endif
1574
1581
1575
1582
static func computeToolchain(
1576
- _ explicitTarget : Triple ? ,
1583
+ _ parsedOptions : inout ParsedOptions ,
1577
1584
diagnosticsEngine: DiagnosticsEngine ,
1578
1585
env: [ String : String ] ,
1579
1586
executor: DriverExecutor ,
1580
1587
fileSystem: FileSystem
1581
- ) throws -> ( Toolchain , Triple ) {
1588
+ ) throws -> ( Toolchain , FrontendTargetInfo ) {
1589
+ let explicitTarget = ( parsedOptions. getLastArgument ( . target) ? . asSingle)
1590
+ . map {
1591
+ Triple ( $0, normalizing: true )
1592
+ }
1593
+ let explicitTargetVariant = ( parsedOptions. getLastArgument ( . targetVariant) ? . asSingle)
1594
+ . map {
1595
+ Triple ( $0, normalizing: true )
1596
+ }
1597
+
1598
+ // FIXME: Compute these.
1599
+ let sdkPath : VirtualPath ? = nil
1600
+ let resourceDirPath : VirtualPath ? = nil
1601
+
1582
1602
let toolchainType = try explicitTarget? . toolchainType ( diagnosticsEngine) ??
1583
1603
defaultToolchainType
1584
1604
let toolchain = toolchainType. init ( env: env, executor: executor, fileSystem: fileSystem)
1585
- return ( toolchain, try explicitTarget ?? toolchain. hostTargetTriple ( ) )
1605
+
1606
+ var info = try executor. execute (
1607
+ job: toolchain. printTargetInfoJob (
1608
+ target: explicitTarget, targetVariant: explicitTargetVariant,
1609
+ sdkPath: sdkPath, resourceDirPath: resourceDirPath
1610
+ ) ,
1611
+ capturingJSONOutputAs: FrontendTargetInfo . self,
1612
+ forceResponseFiles: false ,
1613
+ recordedInputModificationDates: [ : ] )
1614
+
1615
+ // Parse the runtime compatibility version. If present, it will override
1616
+ // what is reported by the frontend.
1617
+ if let versionString =
1618
+ parsedOptions. getLastArgument ( . runtimeCompatibilityVersion) ? . asSingle {
1619
+ if let version = SwiftVersion ( string: versionString) {
1620
+ info. target. swiftRuntimeCompatibilityVersion = version
1621
+ info. targetVariant? . swiftRuntimeCompatibilityVersion = version
1622
+ } else {
1623
+ diagnosticsEngine. emit (
1624
+ . error_invalid_arg_value(
1625
+ arg: . runtimeCompatibilityVersion, value: versionString) )
1626
+ }
1627
+ }
1628
+
1629
+ return ( toolchain, info)
1586
1630
}
1587
1631
}
1588
1632
0 commit comments