@@ -27,6 +27,8 @@ public struct Triple: Encodable, Equatable {
2727 public let vendor : Vendor
2828 public let os : OS
2929 public let abi : ABI
30+ public let osVersion : String ?
31+ public let abiVersion : String ?
3032
3133 public enum Error : Swift . Error {
3234 case badFormat
@@ -85,13 +87,18 @@ public struct Triple: Encodable, Equatable {
8587 throw Error . unknownOS
8688 }
8789
90+ let osVersion = Triple . parseVersion ( components [ 2 ] )
91+
8892 let abi = components. count > 3 ? Triple . parseABI ( components [ 3 ] ) : nil
93+ let abiVersion = components. count > 3 ? Triple . parseVersion ( components [ 3 ] ) : nil
8994
9095 self . tripleString = string
9196 self . arch = arch
9297 self . vendor = vendor
9398 self . os = os
99+ self . osVersion = osVersion
94100 self . abi = abi ?? . unknown
101+ self . abiVersion = abiVersion
95102 }
96103
97104 fileprivate static func parseOS( _ string: String ) -> OS ? {
@@ -102,6 +109,15 @@ public struct Triple: Encodable, Equatable {
102109 return nil
103110 }
104111
112+ fileprivate static func parseVersion( _ string: String ) -> String ? {
113+ let candidate = String ( string. drop ( while: { $0. isLetter } ) )
114+ if candidate != string && !candidate. isEmpty {
115+ return candidate
116+ }
117+
118+ return nil
119+ }
120+
105121 fileprivate static func parseABI( _ string: String ) -> ABI ? {
106122 if string. hasPrefix ( ABI . android. rawValue) {
107123 return ABI . android
@@ -138,18 +154,18 @@ public struct Triple: Encodable, Equatable {
138154 /// This is currently meant for Apple platforms only.
139155 public func tripleString( forPlatformVersion version: String ) -> String {
140156 precondition ( isDarwin ( ) )
141- return self . tripleString + version
157+ return String ( self . tripleString. dropLast ( self . osVersion ? . count ?? 0 ) ) + version
142158 }
143159
144160 public static let macOS = try ! Triple ( " x86_64-apple-macosx " )
145161
146- /// Determine the host triple using the Swift compiler.
162+ /// Determine the versioned host triple using the Swift compiler.
147163 public static func getHostTriple( usingSwiftCompiler swiftCompiler: AbsolutePath ) -> Triple {
148164 do {
149165 let result = try Process . popen ( args: swiftCompiler. pathString, " -print-target-info " )
150166 let output = try result. utf8Output ( ) . spm_chomp ( )
151167 let targetInfo = try JSON ( string: output)
152- let tripleString : String = try targetInfo. get ( " target " ) . get ( " unversionedTriple " )
168+ let tripleString : String = try targetInfo. get ( " target " ) . get ( " triple " )
153169 return try Triple ( tripleString)
154170 } catch {
155171 // FIXME: Remove the macOS special-casing once the latest version of Xcode comes with
0 commit comments