Skip to content

Commit bcfdacf

Browse files
committed
Use the (versioned) triple from swiftc instead.
Here, swiftc is invoked to get the textual unversioned triple from the compiler. However, TSC wants to use this unversioned triple for the target flag, which causes breakage on the compiler side on platforms with versioned triples, because the compiler can't find the stdlib with the unversioned triple. Instead, default to getting versioned triples. When clients of TSC want to do funky things with unversioned triples, we lop the version numbers off versioned triples to get an unversioned triple. This is somewhat crude, but the alternative is to get both versioned _and_ unversioned triples from swiftc, which is similarly awkward.
1 parent 21a7918 commit bcfdacf

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Sources/TSCUtility/Triple.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public struct Triple: Encodable, Equatable {
2727
public let vendor: Vendor
2828
public let os: OS
2929
public let abi: ABI
30+
public let version: String?
3031

3132
public enum Error: Swift.Error {
3233
case badFormat
@@ -83,12 +84,15 @@ public struct Triple: Encodable, Equatable {
8384
throw Error.unknownOS
8485
}
8586

87+
let version = Triple.parseVersion(components[2])
88+
8689
let abi = components.count > 3 ? Triple.parseABI(components[3]) : nil
8790

8891
self.tripleString = string
8992
self.arch = arch
9093
self.vendor = vendor
9194
self.os = os
95+
self.version = version
9296
self.abi = abi ?? .unknown
9397
}
9498

@@ -100,6 +104,15 @@ public struct Triple: Encodable, Equatable {
100104
return nil
101105
}
102106

107+
fileprivate static func parseVersion(_ string: String) -> String? {
108+
let candidate = String(string.drop(while: { $0.isLetter }))
109+
if candidate != string {
110+
return candidate
111+
}
112+
113+
return nil
114+
}
115+
103116
fileprivate static func parseABI(_ string: String) -> ABI? {
104117
if string.hasPrefix(ABI.android.rawValue) {
105118
return ABI.android
@@ -132,18 +145,18 @@ public struct Triple: Encodable, Equatable {
132145
/// This is currently meant for Apple platforms only.
133146
public func tripleString(forPlatformVersion version: String) -> String {
134147
precondition(isDarwin())
135-
return self.tripleString + version
148+
return String(self.tripleString.dropLast(self.version?.count ?? 0)) + version
136149
}
137150

138151
public static let macOS = try! Triple("x86_64-apple-macosx")
139152

140-
/// Determine the host triple using the Swift compiler.
153+
/// Determine the versioned host triple using the Swift compiler.
141154
public static func getHostTriple(usingSwiftCompiler swiftCompiler: AbsolutePath) -> Triple {
142155
do {
143156
let result = try Process.popen(args: swiftCompiler.pathString, "-print-target-info")
144157
let output = try result.utf8Output().spm_chomp()
145158
let targetInfo = try JSON(string: output)
146-
let tripleString: String = try targetInfo.get("target").get("unversionedTriple")
159+
let tripleString: String = try targetInfo.get("target").get("triple")
147160
return try Triple(tripleString)
148161
} catch {
149162
// FIXME: Remove the macOS special-casing once the latest version of Xcode comes with

0 commit comments

Comments
 (0)