Skip to content

Commit de69c45

Browse files
committed
Avoid computing toolchain twice when we're using host toolchain
<rdar://problem/59919455>
1 parent a1c897b commit de69c45

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

Sources/Commands/SwiftTool.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -797,15 +797,15 @@ public class SwiftTool<Options: ToolOptions> {
797797
/// Lazily compute the destination toolchain.
798798
private lazy var _destinationToolchain: Result<UserToolchain, Swift.Error> = {
799799
var destination: Destination
800+
let hostDestination: Destination
800801
do {
802+
hostDestination = try self._hostToolchain.get().destination
801803
// Create custom toolchain if present.
802804
if let customDestination = self.options.customCompileDestination {
803805
destination = try Destination(fromFile: customDestination)
804806
} else {
805807
// Otherwise use the host toolchain.
806-
destination = try Destination.hostDestination(
807-
originalWorkingDirectory: self.originalWorkingDirectory
808-
)
808+
destination = hostDestination
809809
}
810810
} catch {
811811
return .failure(error)
@@ -820,6 +820,12 @@ public class SwiftTool<Options: ToolOptions> {
820820
if let sdk = self.options.customCompileSDK {
821821
destination.sdk = sdk
822822
}
823+
824+
// Check if we ended up with the host toolchain.
825+
if hostDestination == destination {
826+
return self._hostToolchain
827+
}
828+
823829
return Result(catching: { try UserToolchain(destination: destination) })
824830
}()
825831

Sources/SPMBuildCore/Triple.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import TSCBasic
1818
/// @see Destination.target
1919
/// @see https://github.com/apple/swift-llvm/blob/stable/include/llvm/ADT/Triple.h
2020
///
21-
public struct Triple: Encodable {
21+
public struct Triple: Encodable, Equatable {
2222
public let tripleString: String
2323

2424
public let arch: Arch

Sources/Workspace/Destination.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension DestinationError: CustomStringConvertible {
2323
}
2424

2525
/// The compilation destination, has information about everything that's required for a certain destination.
26-
public struct Destination: Encodable {
26+
public struct Destination: Encodable, Equatable {
2727

2828
/// The clang/LLVM triple describing the target OS and architecture.
2929
///

0 commit comments

Comments
 (0)