Skip to content

Commit 2e0f445

Browse files
authored
Merge pull request #159 from owenv/version-cleanup
Make SwiftVersion struct Comparable
2 parents 0b9feb3 + 88c5875 commit 2e0f445

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

Sources/SwiftDriver/Jobs/PrintTargetInfoJob.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ struct SwiftVersion {
2424
self.major = components[0]
2525
self.minor = components[1]
2626
}
27+
28+
init(major: Int, minor: Int) {
29+
self.major = major
30+
self.minor = minor
31+
}
32+
}
33+
34+
extension SwiftVersion {
35+
static let v5_0 = SwiftVersion(major: 5, minor: 0)
36+
static let v5_1 = SwiftVersion(major: 5, minor: 1)
37+
}
38+
39+
extension SwiftVersion: Comparable {
40+
static func < (lhs: SwiftVersion, rhs: SwiftVersion) -> Bool {
41+
(lhs.major, lhs.minor) < (rhs.major, rhs.minor)
42+
}
2743
}
2844

2945
extension SwiftVersion: CustomStringConvertible {

Sources/SwiftDriver/Jobs/Toolchain+LinkerSupport.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,6 @@ extension DarwinToolchain {
133133

134134
// Link compatibility libraries, if we're deploying back to OSes that
135135
// have an older Swift runtime.
136-
let runtimeCompatibilityVersion: (Int, Int)? =
137-
targetInfo.target.swiftRuntimeCompatibilityVersion.map {
138-
($0.major, $0.minor)
139-
}
140-
141136
let resourceDirPath = try computeResourceDirPath(for: targetTriple,
142137
parsedOptions: &parsedOptions,
143138
isShared: true)
@@ -149,18 +144,18 @@ extension DarwinToolchain {
149144
}
150145
}
151146

152-
if let compatibilityVersion = runtimeCompatibilityVersion {
153-
if compatibilityVersion <= (5, 0) {
147+
if let compatibilityVersion = targetInfo.target.swiftRuntimeCompatibilityVersion {
148+
if compatibilityVersion <= .v5_0 {
154149
// Swift 5.0 compatibility library
155150
addArgsForBackDeployLib("libswiftCompatibility50.a")
156151
}
157152

158-
if compatibilityVersion <= (5, 1) {
153+
if compatibilityVersion <= .v5_1 {
159154
// Swift 5.1 compatibility library
160155
addArgsForBackDeployLib("libswiftCompatibility51.a")
161156
}
162157

163-
if linkerOutputType == .executable && compatibilityVersion <= (5, 0) {
158+
if linkerOutputType == .executable && compatibilityVersion <= .v5_0 {
164159
// Swift 5.0 dynamic replacement compatibility library.
165160
addArgsForBackDeployLib("libswiftCompatibilityDynamicReplacements.a")
166161
}

0 commit comments

Comments
 (0)