@@ -27,6 +27,8 @@ public struct Triple: Encodable, Equatable {
27
27
public let vendor : Vendor
28
28
public let os : OS
29
29
public let abi : ABI
30
+ public let osVersion : String ?
31
+ public let abiVersion : String ?
30
32
31
33
public enum Error : Swift . Error {
32
34
case badFormat
@@ -85,13 +87,18 @@ public struct Triple: Encodable, Equatable {
85
87
throw Error . unknownOS
86
88
}
87
89
90
+ let osVersion = Triple . parseVersion ( components [ 2 ] )
91
+
88
92
let abi = components. count > 3 ? Triple . parseABI ( components [ 3 ] ) : nil
93
+ let abiVersion = components. count > 3 ? Triple . parseVersion ( components [ 3 ] ) : nil
89
94
90
95
self . tripleString = string
91
96
self . arch = arch
92
97
self . vendor = vendor
93
98
self . os = os
99
+ self . osVersion = osVersion
94
100
self . abi = abi ?? . unknown
101
+ self . abiVersion = abiVersion
95
102
}
96
103
97
104
fileprivate static func parseOS( _ string: String ) -> OS ? {
@@ -102,6 +109,15 @@ public struct Triple: Encodable, Equatable {
102
109
return nil
103
110
}
104
111
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
+
105
121
fileprivate static func parseABI( _ string: String ) -> ABI ? {
106
122
if string. hasPrefix ( ABI . android. rawValue) {
107
123
return ABI . android
@@ -138,18 +154,18 @@ public struct Triple: Encodable, Equatable {
138
154
/// This is currently meant for Apple platforms only.
139
155
public func tripleString( forPlatformVersion version: String ) -> String {
140
156
precondition ( isDarwin ( ) )
141
- return self . tripleString + version
157
+ return String ( self . tripleString. dropLast ( self . osVersion ? . count ?? 0 ) ) + version
142
158
}
143
159
144
160
public static let macOS = try ! Triple ( " x86_64-apple-macosx " )
145
161
146
- /// Determine the host triple using the Swift compiler.
162
+ /// Determine the versioned host triple using the Swift compiler.
147
163
public static func getHostTriple( usingSwiftCompiler swiftCompiler: AbsolutePath ) -> Triple {
148
164
do {
149
165
let result = try Process . popen ( args: swiftCompiler. pathString, " -print-target-info " )
150
166
let output = try result. utf8Output ( ) . spm_chomp ( )
151
167
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 " )
153
169
return try Triple ( tripleString)
154
170
} catch {
155
171
// FIXME: Remove the macOS special-casing once the latest version of Xcode comes with
0 commit comments