Skip to content

Commit 88017a0

Browse files
committed
Introduce VisionOS Platform
1 parent 9cdabfc commit 88017a0

File tree

7 files changed

+89
-6
lines changed

7 files changed

+89
-6
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3164,7 +3164,7 @@ extension Driver {
31643164
extension Triple {
31653165
@_spi(Testing) public func toolchainType(_ diagnosticsEngine: DiagnosticsEngine) throws -> Toolchain.Type {
31663166
switch os {
3167-
case .darwin, .macosx, .ios, .tvos, .watchos:
3167+
case .darwin, .macosx, .ios, .tvos, .watchos, .visionos:
31683168
return DarwinToolchain.self
31693169
case .linux:
31703170
return GenericUnixToolchain.self

Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ private extension DarwinPlatform {
293293
return ["watchos"]
294294
case .watchOS(.simulator):
295295
return ["watchossim", "watchos"]
296+
case .visionOS(.device):
297+
return ["xros"]
298+
case .visionOS(.simulator):
299+
return ["xrossim", "xros"]
296300
}
297301
}
298302
}

Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,10 @@ public struct SDKPrebuiltModuleInputsCollector {
479479
return "arm64-apple-tvos\(version)"
480480
case .appletvsimulator:
481481
return "arm64-apple-tvos\(version)-simulator"
482+
case .visionos:
483+
return "arm64-apple-xros\(version)"
484+
case .visionsimulator:
485+
return "arm64-apple-xros\(version)-simulator"
482486
case .unknown:
483487
fatalError("unknown platform kind")
484488
}

Sources/SwiftDriver/Toolchains/DarwinToolchain.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ public final class DarwinToolchain: Toolchain {
239239
.macosx: (.macOS, Triple.Version(10, 9, 0)),
240240
.ios: (.iOS(targetTriple._isSimulatorEnvironment ? .simulator : .device), Triple.Version(7, 0, 0)),
241241
.tvos: (.tvOS(targetTriple._isSimulatorEnvironment ? .simulator : .device), Triple.Version(9, 0, 0)),
242-
.watchos: (.watchOS(targetTriple._isSimulatorEnvironment ? .simulator : .device), Triple.Version(2, 0, 0))
242+
.watchos: (.watchOS(targetTriple._isSimulatorEnvironment ? .simulator : .device), Triple.Version(2, 0, 0)),
243+
.visionos: (.visionOS(targetTriple._isSimulatorEnvironment ? .simulator : .device), Triple.Version(1, 0, 0))
243244
]
244245
if let (platform, minVersion) = minVersions[os], targetTriple.version(for: platform) < minVersion {
245246
throw ToolchainValidationError.osVersionBelowMinimumDeploymentTarget(platform: platform, version: minVersion)
@@ -288,6 +289,8 @@ public final class DarwinToolchain: Toolchain {
288289
case watchsimulator
289290
case appletvos
290291
case appletvsimulator
292+
case visionos
293+
case visionsimulator
291294
case unknown
292295
}
293296

Sources/SwiftDriver/Utilities/Triple+Platforms.swift

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public enum DarwinPlatform: Hashable {
3232
/// watchOS, corresponding to the `watchos` OS name.
3333
case watchOS(EnvironmentWithoutCatalyst)
3434

35+
/// visionOS, corresponding to the `visionos` OS name.
36+
case visionOS(EnvironmentWithoutCatalyst)
37+
3538
/// The most general form of environment information attached to a
3639
/// `DarwinPlatform`.
3740
///
@@ -76,6 +79,9 @@ public enum DarwinPlatform: Hashable {
7679
case .watchOS:
7780
guard let withoutCatalyst = environment.withoutCatalyst else { return nil }
7881
return .watchOS(withoutCatalyst)
82+
case .visionOS:
83+
guard let withoutCatalyst = environment.withoutCatalyst else { return nil }
84+
return .visionOS(withoutCatalyst)
7985
}
8086
}
8187

@@ -97,6 +103,10 @@ public enum DarwinPlatform: Hashable {
97103
return "watchOS"
98104
case .watchOS(.simulator):
99105
return "watchOS Simulator"
106+
case .visionOS(.device):
107+
return "visionOS"
108+
case .visionOS(.simulator):
109+
return "visionOS Simulator"
100110
}
101111
}
102112

@@ -120,6 +130,10 @@ public enum DarwinPlatform: Hashable {
120130
return "watchos"
121131
case .watchOS(.simulator):
122132
return "watchsimulator"
133+
case .visionOS(.device):
134+
return "xros"
135+
case .visionOS(.simulator):
136+
return "xrsimulator"
123137
}
124138
}
125139

@@ -142,6 +156,10 @@ public enum DarwinPlatform: Hashable {
142156
return "watchos"
143157
case .watchOS(.simulator):
144158
return "watchos-simulator"
159+
case .visionOS(.device):
160+
return "xros"
161+
case .visionOS(.simulator):
162+
return "xros-simulator"
145163
}
146164
}
147165

@@ -165,6 +183,10 @@ public enum DarwinPlatform: Hashable {
165183
return "watchos"
166184
case .watchOS(.simulator):
167185
return "watchossim"
186+
case .visionOS(.device):
187+
return "xros"
188+
case .visionOS(.simulator):
189+
return "xrossim"
168190
}
169191
}
170192
}
@@ -197,6 +219,8 @@ extension Triple {
197219
return _iOSVersion
198220
case .watchOS:
199221
return _watchOSVersion
222+
case .visionOS:
223+
return _visionOSVersion
200224
}
201225
}
202226

@@ -223,6 +247,8 @@ extension Triple {
223247
return .watchOS(makeEnvironment())
224248
case .tvos:
225249
return .tvOS(makeEnvironment())
250+
case .visionos:
251+
return .visionOS(makeEnvironment())
226252
default:
227253
return nil
228254
}
@@ -272,6 +298,8 @@ extension Triple {
272298
}
273299

274300
return osVersion
301+
case .visionOS(_):
302+
return _visionOSVersion
275303
}
276304
}
277305

@@ -285,7 +313,7 @@ extension Triple {
285313
switch os {
286314
case nil:
287315
fatalError("unknown OS")
288-
case .darwin, .macosx, .ios, .tvos, .watchos:
316+
case .darwin, .macosx, .ios, .tvos, .watchos, .visionos:
289317
guard let darwinPlatform = darwinPlatform else {
290318
fatalError("unsupported darwin platform kind?")
291319
}
@@ -361,6 +389,7 @@ extension Triple {
361389
public let iOS: Availability
362390
public let tvOS: Availability
363391
public let watchOS: Availability
392+
public var visionOS: Availability
364393

365394
// TODO: We should have linux, windows, etc.
366395
public let nonDarwin: Bool
@@ -379,8 +408,14 @@ extension Triple {
379408
self.tvOS = tvOS
380409
self.watchOS = watchOS
381410
self.nonDarwin = nonDarwin
411+
self.visionOS = iOS
382412
}
383413

414+
public func withVisionOS(_ visionOS: Availability) -> FeatureAvailability {
415+
var res = self
416+
res.visionOS = visionOS
417+
return res
418+
}
384419
/// Returns the version when the feature was introduced on the specified Darwin
385420
/// platform, or `.unavailable` if the feature has not been introduced there.
386421
public subscript(darwinPlatform: DarwinPlatform) -> Availability {
@@ -393,6 +428,8 @@ extension Triple {
393428
return tvOS
394429
case .watchOS:
395430
return watchOS
431+
case .visionOS:
432+
return visionOS
396433
}
397434
}
398435
}

Sources/SwiftDriver/Utilities/Triple.swift

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,7 @@ extension Triple {
11161116
case hurd
11171117
case wasi
11181118
case emscripten
1119+
case visionos = "xros"
11191120
case noneOS // 'OS' suffix purely to avoid name clash with Optional.none
11201121

11211122
var name: String {
@@ -1198,6 +1199,8 @@ extension Triple {
11981199
return .emscripten
11991200
case _ where os.hasPrefix("none"):
12001201
return .noneOS
1202+
case _ where os.hasPrefix("xros"):
1203+
return .visionos
12011204
default:
12021205
return nil
12031206
}
@@ -1490,9 +1493,14 @@ extension Triple.OS {
14901493
self == .watchos
14911494
}
14921495

1496+
public var isVisionOS: Bool {
1497+
self == .visionos
1498+
}
1499+
1500+
14931501
/// isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
14941502
public var isDarwin: Bool {
1495-
isMacOSX || isiOS || isWatchOS
1503+
isMacOSX || isiOS || isWatchOS || isVisionOS
14961504
}
14971505
}
14981506

@@ -1601,8 +1609,7 @@ extension Triple {
16011609
if version.major < 10 {
16021610
return nil
16031611
}
1604-
1605-
case .ios, .tvos, .watchos:
1612+
case .ios, .tvos, .watchos, .visionos:
16061613
// Ignore the version from the triple. This is only handled because the
16071614
// the clang driver combines OS X and IOS support into a common Darwin
16081615
// toolchain that wants to know the OS X version number even when targeting
@@ -1635,6 +1642,8 @@ extension Triple {
16351642
version.major = arch == .aarch64 ? 7 : 5
16361643
}
16371644
return version
1645+
case .visionos:
1646+
return Version(15, 0, 0)
16381647
case .watchos:
16391648
fatalError("conflicting triple info")
16401649
default:
@@ -1667,6 +1676,24 @@ extension Triple {
16671676
fatalError("unexpected OS for Darwin triple")
16681677
}
16691678
}
1679+
1680+
public var _visionOSVersion: Version {
1681+
switch os {
1682+
case .darwin, .macosx:
1683+
return Version(1, 0, 0)
1684+
case .visionos, .ios:
1685+
var version = self.osVersion
1686+
// Default to 1.0
1687+
if version.major == 0 {
1688+
version.major = 1
1689+
}
1690+
return version
1691+
case .watchos:
1692+
fatalError("conflicting triple info")
1693+
default:
1694+
fatalError("unexpected OS for Darwin triple")
1695+
}
1696+
}
16701697
}
16711698

16721699
// MARK: - Catalyst

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,14 @@ final class SwiftDriverTests: XCTestCase {
668668
let jobs = try driver.planBuild()
669669
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-dwarf-version=4")))
670670
}
671+
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-g", "-c", "-target", "arm64-apple-xros1.0-simulator") { driver in
672+
let jobs = try driver.planBuild()
673+
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-dwarf-version=4")))
674+
}
675+
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-g", "-c", "-target", "arm64-apple-xros1.0") { driver in
676+
let jobs = try driver.planBuild()
677+
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-dwarf-version=4")))
678+
}
671679
}
672680

673681
func testCoverageSettings() throws {

0 commit comments

Comments
 (0)