Skip to content

Commit b87b011

Browse files
committed
TSCUtility: support additional spellings for ARM
ARM uses `armv[4-9]-?[arm]` as the arch field to encode the ISA version and the core type for ARMv7. Use the custom parsing logic similar to the other fields to accommodate the spelling.
1 parent 71dcf5a commit b87b011

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Sources/TSCUtility/Triple.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public struct Triple: Encodable, Equatable {
3636
case unknownOS(os: String)
3737
}
3838

39-
public enum Arch: String, Encodable {
39+
public enum Arch: String, Encodable, CaseIterable {
4040
case x86_64
4141
case x86_64h
4242
case i686
@@ -135,6 +135,11 @@ public struct Triple: Encodable, Equatable {
135135
self.abiVersion = abiVersion
136136
}
137137

138+
fileprivate static func parseArch(_ string: String) -> Arch? {
139+
var candidates = Arch.allCases.map { (name: $0.rawValue, value: $0) }
140+
return candidates.first(where: { string.hasPrefix($0.name) })?.value
141+
}
142+
138143
fileprivate static func parseOS(_ string: String) -> OS? {
139144
var candidates = OS.allCases.map{ (name: $0.rawValue, value: $0) }
140145
// LLVM target triples support this alternate spelling as well.
@@ -201,6 +206,7 @@ public struct Triple: Encodable, Equatable {
201206
fatalError("Failed to get target info (\(error))")
202207
#endif
203208
}
209+
204210
// Parse the compiler's JSON output.
205211
let parsedTargetInfo: JSON
206212
do {

Tests/TSCUtilityTests/TripleTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class TripleTests : XCTestCase {
4040
let linuxWithABIVersion = try? Triple("x86_64-unknown-linux-gnu42")
4141
XCTAssertEqual(linuxWithABIVersion!.abi, .other(name: "gnu"))
4242
XCTAssertEqual(linuxWithABIVersion!.abiVersion, "42")
43+
44+
let androidArm = try? Triple("armv7a-unknown-linux-androideabi")
45+
XCTAssertEqual(androidArm!.arch, .armv7)
4346
}
4447

4548
func testEquality() throws {

0 commit comments

Comments
 (0)