Skip to content

Commit a9fab1d

Browse files
committed
Change Triple.isiOS to no longer match tvOS
This behavior is confusing and leads to wrong answers in a number of places. All usage sites of isiOS have been audited to ensure they're now correct. - unsupportedTargetVariant was showing an error message including -target-variant, which should have only matched iOS and not tvOS - getDefaultDwarfVersion checked isiOS in two places, but just so happened to always get the right answer anyways (tvOS's first version was 9, so checking for tvOS < 9 was nonsensical and didn't matter, and iOS and tvOS version numbers have always been aligned, so a < 18 check was right for both)
1 parent 08a17a9 commit a9fab1d

File tree

4 files changed

+85
-20
lines changed

4 files changed

+85
-20
lines changed

Sources/SwiftDriver/Toolchains/DarwinToolchain.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public final class DarwinToolchain: Toolchain {
232232
if (targetTriple.isMacOSX && targetTriple.version(for: .macOS) < Triple.Version(10, 11, 0)) ||
233233
(targetTriple.isiOS && targetTriple.version(
234234
for: .iOS(targetTriple._isSimulatorEnvironment ? .simulator : .device)) < Triple.Version(9, 0, 0)) {
235-
return 2;
235+
return 2
236236
}
237237
if (targetTriple.isMacOSX && targetTriple.version(for: .macOS) < Triple.Version(15, 0, 0)) ||
238238
(targetTriple.isiOS && targetTriple.version(

Sources/SwiftDriver/Utilities/Triple+Platforms.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,10 @@ extension Triple {
215215
switch compatibilityPlatform ?? darwinPlatform! {
216216
case .macOS:
217217
return _macOSVersion ?? osVersion
218-
case .iOS, .tvOS:
218+
case .iOS:
219219
return _iOSVersion
220+
case .tvOS:
221+
return _tvOSVersion
220222
case .watchOS:
221223
return _watchOSVersion
222224
case .visionOS:
@@ -282,22 +284,30 @@ extension Triple {
282284
}
283285

284286
return _iOSVersion
285-
case .iOS(.device), .iOS(.simulator), .tvOS(_):
286-
// The first deployment of arm64 simulators is iOS/tvOS 14.0;
287+
case .iOS(_):
288+
// The first deployment of arm64 simulators is iOS 14.0;
287289
// the linker doesn't want to see a deployment target before that.
288290
if _isSimulatorEnvironment && _iOSVersion.major < 14 && arch == .aarch64 {
289291
return Version(14, 0, 0)
290292
}
291293

292294
return _iOSVersion
295+
case .tvOS(_):
296+
// The first deployment of arm64 simulators is tvOS 14.0;
297+
// the linker doesn't want to see a deployment target before that.
298+
if _isSimulatorEnvironment && _tvOSVersion.major < 14 && arch == .aarch64 {
299+
return Version(14, 0, 0)
300+
}
301+
302+
return _tvOSVersion
293303
case .watchOS(_):
294304
// The first deployment of arm64 simulators is watchOS 7;
295305
// the linker doesn't want to see a deployment target before that.
296306
if _isSimulatorEnvironment && osVersion.major < 7 && arch == .aarch64 {
297307
return Version(7, 0, 0)
298308
}
299309

300-
return osVersion
310+
return _watchOSVersion
301311
case .visionOS(_):
302312
return _visionOSVersion
303313
}

Sources/SwiftDriver/Utilities/Triple.swift

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,19 +1473,16 @@ extension Triple.OS {
14731473
self == .aix
14741474
}
14751475

1476-
/// isMacOSX - Is this a Mac OS X triple. For legacy reasons, we support both
1477-
/// "darwin" and "osx" as OS X triples.
1476+
/// Is this an Apple macOS triple.
1477+
/// - note: For legacy reasons, we support both "darwin" and "macosx" as macOS triples.
14781478
public var isMacOSX: Bool {
14791479
self == .darwin || self == .macosx
14801480
}
14811481

1482-
/// Is this an iOS triple.
1483-
/// Note: This identifies tvOS as a variant of iOS. If that ever
1484-
/// changes, i.e., if the two operating systems diverge or their version
1485-
/// numbers get out of sync, that will need to be changed.
1486-
/// watchOS has completely different version numbers so it is not included.
1482+
/// Is this an Apple iOS triple.
1483+
/// - note: Contrary to historical behavior with regard to LLVM's Triple type, this does NOT match tvOS in order to avoid confusion moving forward.
14871484
public var isiOS: Bool {
1488-
self == .ios || isTvOS
1485+
self == .ios
14891486
}
14901487

14911488
/// Is this an Apple tvOS triple.
@@ -1498,14 +1495,15 @@ extension Triple.OS {
14981495
self == .watchos
14991496
}
15001497

1498+
/// Is this an Apple visionOS triple.
15011499
public var isVisionOS: Bool {
15021500
self == .visionos
15031501
}
15041502

15051503

1506-
/// isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
1504+
/// isOSDarwin - Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, or visionOS).
15071505
public var isDarwin: Bool {
1508-
isMacOSX || isiOS || isWatchOS || isVisionOS
1506+
isMacOSX || isiOS || isTvOS || isWatchOS || isVisionOS
15091507
}
15101508
}
15111509

@@ -1640,13 +1638,15 @@ extension Triple {
16401638
// toolchain that wants to know the iOS version number even when targeting
16411639
// OS X.
16421640
return Version(5, 0, 0)
1643-
case .ios, .tvos:
1641+
case .ios:
16441642
var version = self.osVersion
16451643
// Default to 5.0 (or 7.0 for arm64).
16461644
if version.major == 0 {
16471645
version.major = arch == .aarch64 ? 7 : 5
16481646
}
16491647
return version
1648+
case .tvos:
1649+
return osVersion
16501650
case .visionos:
16511651
return Version(15, 0, 0)
16521652
case .watchos:
@@ -1656,6 +1656,33 @@ extension Triple {
16561656
}
16571657
}
16581658

1659+
/// Parse the version number as with getOSVersion. This should
1660+
/// only be called with tvOS or generic triples.
1661+
///
1662+
/// This accessor is semi-private; it's typically better to use `version(for:)` or
1663+
/// `Triple.FeatureAvailability`.
1664+
public var _tvOSVersion: Version {
1665+
switch os {
1666+
case .darwin, .macosx:
1667+
// Ignore the version from the triple. This is only handled because the
1668+
// the clang driver combines OS X and iOS support into a common Darwin
1669+
// toolchain that wants to know the iOS version number even when targeting
1670+
// OS X.
1671+
return Version(9, 0, 0)
1672+
case .ios, .tvos:
1673+
var version = self.osVersion
1674+
// Default to 9.0, which was the first version of tvOS.
1675+
if version.major == 0 {
1676+
version.major = 9
1677+
}
1678+
return version
1679+
case .watchos:
1680+
fatalError("conflicting triple info")
1681+
default:
1682+
fatalError("unexpected OS for Darwin triple")
1683+
}
1684+
}
1685+
16591686
/// Parse the version number as with getOSVersion. This should only be
16601687
/// called with WatchOS or generic triples.
16611688
///
@@ -1671,11 +1698,12 @@ extension Triple {
16711698
return Version(2, 0, 0)
16721699
case .watchos:
16731700
var version = self.osVersion
1701+
// Default to 2.0, which was the first version of watchOS.
16741702
if version.major == 0 {
16751703
version.major = 2
16761704
}
16771705
return version
1678-
case .ios:
1706+
case .ios, .tvos, .visionos:
16791707
fatalError("conflicting triple info")
16801708
default:
16811709
fatalError("unexpected OS for Darwin triple")
@@ -1705,7 +1733,7 @@ extension Triple {
17051733

17061734
extension Triple {
17071735
@_spi(Testing) public var isMacCatalyst: Bool {
1708-
return self.isiOS && !self.isTvOS && environment == .macabi
1736+
return self.isiOS && environment == .macabi
17091737
}
17101738

17111739
func isValidForZipperingWithTriple(_ variant: Triple) -> Bool {

Tests/SwiftDriverTests/TripleTests.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,12 +1054,23 @@ final class TripleTests: XCTestCase {
10541054

10551055
T = Triple("x86_64-apple-ios12.0")
10561056
XCTAssertTrue(T.os?.isiOS)
1057+
XCTAssertFalse(T.os?.isTvOS)
10571058
V = T._iOSVersion
10581059
XCTAssertEqual(V?.major, 12)
10591060
XCTAssertEqual(V?.minor, 0)
10601061
XCTAssertEqual(V?.micro, 0)
10611062
XCTAssertFalse(T._isSimulatorEnvironment)
10621063
XCTAssertFalse(T.isMacCatalyst)
1064+
1065+
T = Triple("x86_64-apple-tvos12.0")
1066+
XCTAssertTrue(T.os?.isTvOS)
1067+
XCTAssertFalse(T.os?.isiOS)
1068+
V = T._tvOSVersion
1069+
XCTAssertEqual(V?.major, 12)
1070+
XCTAssertEqual(V?.minor, 0)
1071+
XCTAssertEqual(V?.micro, 0)
1072+
XCTAssertFalse(T._isSimulatorEnvironment)
1073+
XCTAssertFalse(T.isMacCatalyst)
10631074
}
10641075

10651076
func testFileFormat() {
@@ -1143,6 +1154,7 @@ final class TripleTests: XCTestCase {
11431154
environment: T,
11441155
macOSVersion: Triple.Version?,
11451156
iOSVersion: Triple.Version?,
1157+
tvOSVersion: Triple.Version?,
11461158
watchOSVersion: Triple.Version?,
11471159
shouldHaveJetPacks: Bool,
11481160
file: StaticString = #file, line: UInt = #line
@@ -1170,9 +1182,11 @@ final class TripleTests: XCTestCase {
11701182
"iOS device version", file: file, line: line)
11711183
XCTAssertEqual(triple.version(for: .iOS(.simulator)), iOSVersion,
11721184
"iOS simulator version", file: file, line: line)
1173-
XCTAssertEqual(triple.version(for: .tvOS(.device)), iOSVersion,
1185+
}
1186+
if let tvOSVersion = tvOSVersion {
1187+
XCTAssertEqual(triple.version(for: .tvOS(.device)), tvOSVersion,
11741188
"tvOS device version", file: file, line: line)
1175-
XCTAssertEqual(triple.version(for: .tvOS(.simulator)), iOSVersion,
1189+
XCTAssertEqual(triple.version(for: .tvOS(.simulator)), tvOSVersion,
11761190
"tvOS simulator version", file: file, line: line)
11771191
}
11781192
if let watchOSVersion = watchOSVersion {
@@ -1214,27 +1228,31 @@ final class TripleTests: XCTestCase {
12141228
environment: .device,
12151229
macOSVersion: .init(10, 12, 0),
12161230
iOSVersion: .init(5, 0, 0),
1231+
tvOSVersion: .init(9, 0, 0),
12171232
watchOSVersion: .init(2, 0, 0),
12181233
shouldHaveJetPacks: false)
12191234
assertDarwinPlatformCorrect(macOS2,
12201235
case: macOS,
12211236
environment: .device,
12221237
macOSVersion: .init(10, 50, 0),
12231238
iOSVersion: .init(5, 0, 0),
1239+
tvOSVersion: .init(9, 0, 0),
12241240
watchOSVersion: .init(2, 0, 0),
12251241
shouldHaveJetPacks: true)
12261242
assertDarwinPlatformCorrect(macOS3,
12271243
case: macOS,
12281244
environment: .device,
12291245
macOSVersion: .init(10, 60, 9),
12301246
iOSVersion: .init(5, 0, 0),
1247+
tvOSVersion: .init(9, 0, 0),
12311248
watchOSVersion: .init(2, 0, 0),
12321249
shouldHaveJetPacks: true)
12331250
assertDarwinPlatformCorrect(macOS4,
12341251
case: macOS,
12351252
environment: .device,
12361253
macOSVersion: .init(10, 15, 0),
12371254
iOSVersion: .init(5, 0, 0),
1255+
tvOSVersion: .init(9, 0, 0),
12381256
watchOSVersion: .init(2, 0, 0),
12391257
shouldHaveJetPacks: false)
12401258

@@ -1247,20 +1265,23 @@ final class TripleTests: XCTestCase {
12471265
environment: .simulator,
12481266
macOSVersion: .init(10, 4, 0),
12491267
iOSVersion: .init(13, 0, 0),
1268+
tvOSVersion: nil,
12501269
watchOSVersion: nil,
12511270
shouldHaveJetPacks: false)
12521271
assertDarwinPlatformCorrect(iOS2,
12531272
case: iOS,
12541273
environment: .device,
12551274
macOSVersion: .init(10, 4, 0),
12561275
iOSVersion: .init(50, 0, 0),
1276+
tvOSVersion: nil,
12571277
watchOSVersion: nil,
12581278
shouldHaveJetPacks: true)
12591279
assertDarwinPlatformCorrect(iOS3,
12601280
case: iOS,
12611281
environment: .catalyst,
12621282
macOSVersion: .init(10, 4, 0),
12631283
iOSVersion: .init(60, 0, 0),
1284+
tvOSVersion: nil,
12641285
watchOSVersion: nil,
12651286
shouldHaveJetPacks: true)
12661287

@@ -1273,20 +1294,23 @@ final class TripleTests: XCTestCase {
12731294
environment: .simulator,
12741295
macOSVersion: .init(10, 4, 0),
12751296
iOSVersion: .init(13, 0, 0),
1297+
tvOSVersion: .init(13, 0, 0),
12761298
watchOSVersion: nil,
12771299
shouldHaveJetPacks: false)
12781300
assertDarwinPlatformCorrect(tvOS2,
12791301
case: tvOS,
12801302
environment: .device,
12811303
macOSVersion: .init(10, 4, 0),
12821304
iOSVersion: .init(50, 0, 0),
1305+
tvOSVersion: .init(50, 0, 0),
12831306
watchOSVersion: nil,
12841307
shouldHaveJetPacks: true)
12851308
assertDarwinPlatformCorrect(tvOS3,
12861309
case: tvOS,
12871310
environment: .simulator,
12881311
macOSVersion: .init(10, 4, 0),
12891312
iOSVersion: .init(60, 0, 0),
1313+
tvOSVersion: .init(60, 0, 0),
12901314
watchOSVersion: nil,
12911315
shouldHaveJetPacks: true)
12921316

@@ -1299,20 +1323,23 @@ final class TripleTests: XCTestCase {
12991323
environment: .simulator,
13001324
macOSVersion: .init(10, 4, 0),
13011325
iOSVersion: nil,
1326+
tvOSVersion: nil,
13021327
watchOSVersion: .init(6, 0, 0),
13031328
shouldHaveJetPacks: false)
13041329
assertDarwinPlatformCorrect(watchOS2,
13051330
case: watchOS,
13061331
environment: .device,
13071332
macOSVersion: .init(10, 4, 0),
13081333
iOSVersion: nil,
1334+
tvOSVersion: nil,
13091335
watchOSVersion: .init(50, 0, 0),
13101336
shouldHaveJetPacks: true)
13111337
assertDarwinPlatformCorrect(watchOS3,
13121338
case: watchOS,
13131339
environment: .simulator,
13141340
macOSVersion: .init(10, 4, 0),
13151341
iOSVersion: nil,
1342+
tvOSVersion: nil,
13161343
watchOSVersion: .init(60, 0, 0),
13171344
shouldHaveJetPacks: true)
13181345
}

0 commit comments

Comments
 (0)