Skip to content

Commit 6db9761

Browse files
authored
[5.9] Add visionOS as a platform alongside iOS, tvOS, watchOS, and the others (#6663)
Add new enum constants for visionOS in all the places where it is appropriate. This includes the `platforms` parameter in the manifest, whose purpose is to list the minimum deployment targets that a package requires. Since there is initially only visionOS 1.0, and because absence of a platform in the `platforms` parameter means that the default version is supported (not that the platform is unsupported), all packages implicitly support visionOS 1.0 whether or not they list it in the `platforms` parameter. But having the enum constant alongside those for the other Apple platforms makes everything consistent, and will become important for any future versions. This change also makes the `visionOS` platform available for use in conditional target dependencies. rdar://107064954 (cherry picked from commit 809cb15)
1 parent 803c360 commit 6db9761

File tree

14 files changed

+88
-4
lines changed

14 files changed

+88
-4
lines changed

Sources/PackageCollections/Providers/JSONPackageCollectionProvider.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ extension PackageModel.Platform {
480480
self = PackageModel.Platform.tvOS
481481
case let name where name.contains("watchos"):
482482
self = PackageModel.Platform.watchOS
483+
case let name where name.contains("visionos"):
484+
self = PackageModel.Platform.visionOS
483485
case let name where name.contains("driverkit"):
484486
self = PackageModel.Platform.driverKit
485487
case let name where name.contains("linux"):

Sources/PackageDescription/PackageDescription.docc/Curation/SupportedPlatforms.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
- <doc:/documentation/PackageDescription/Platform/watchOS>
2424
- ``WatchOSVersion``
2525

26+
### Supporting visionOS
27+
28+
- ``visionOS(_:)-3ip0z``
29+
- ``visionOS(_:)-6ur2u``
30+
- <doc:/documentation/PackageDescription/Platform/visionOS>
31+
- ``VisionOSVersion``
32+
2633
### Supporting tvOS
2734

2835
- ``tvOS(_:)-6931l``

Sources/PackageDescription/SupportedPlatforms.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public struct Platform: Equatable {
4545
/// The watchOS platform.
4646
public static let watchOS: Platform = Platform(name: "watchos")
4747

48+
/// The visionOS platform.
49+
public static let visionOS: Platform = Platform(name: "visionos")
50+
4851
/// The DriverKit platform
4952
public static let driverKit: Platform = Platform(name: "driverkit")
5053

@@ -224,6 +227,33 @@ public struct SupportedPlatform: Equatable {
224227
return SupportedPlatform(platform: .watchOS, version: SupportedPlatform.WatchOSVersion(string: versionString).version)
225228
}
226229

230+
/// Configure the minimum deployment target version for the visionOS
231+
/// platform.
232+
///
233+
/// - Since: First available in PackageDescription 5.9
234+
///
235+
/// - Parameter version: The minimum deployment target that the package supports.
236+
/// - Returns: A `SupportedPlatform` instance.
237+
@available(_PackageDescription, introduced: 5.9)
238+
public static func visionOS(_ version: SupportedPlatform.VisionOSVersion) -> SupportedPlatform {
239+
return SupportedPlatform(platform: .visionOS, version: version.version)
240+
}
241+
242+
/// Configure the minimum deployment target version for the visionOS
243+
/// platform using a custom version string.
244+
///
245+
/// The version string must be a series of two or three dot-separated integers, such as `1.0` or `1.0.0`.
246+
///
247+
/// - Since: First available in PackageDescription 5.9
248+
///
249+
/// - Parameter versionString: The minimum deployment target as a string
250+
/// representation of two or three dot-separated integers, such as `1.0.0`.
251+
/// - Returns: A `SupportedPlatform` instance.
252+
@available(_PackageDescription, introduced: 5.9)
253+
public static func visionOS(_ versionString: String) -> SupportedPlatform {
254+
return SupportedPlatform(platform: .visionOS, version: SupportedPlatform.VisionOSVersion(string: versionString).version)
255+
}
256+
227257
/// Configures the minimum deployment target version for the DriverKit platform.
228258
///
229259
/// - Parameter version: The minimum deployment target that the package supports.
@@ -594,6 +624,25 @@ extension SupportedPlatform {
594624
public static let v10: WatchOSVersion = .init(string: "10.0")
595625
}
596626

627+
/// The supported visionOS version.
628+
public struct VisionOSVersion: AppleOSVersion {
629+
fileprivate static let name = "visionOS"
630+
fileprivate static let minimumMajorVersion = 1
631+
632+
/// The underlying version representation.
633+
let version: String
634+
635+
fileprivate init(uncheckedVersion version: String) {
636+
self.version = version
637+
}
638+
639+
/// The value that represents visionOS 1.0.
640+
///
641+
/// - Since: First available in PackageDescription 5.9.
642+
@available(_PackageDescription, introduced: 5.9)
643+
public static let v1: VisionOSVersion = .init(string: "1.0")
644+
}
645+
597646
/// The supported DriverKit version.
598647
public struct DriverKitVersion: AppleOSVersion {
599648
fileprivate static let name = "DriverKit"

Sources/PackageModel/ManifestSourceGeneration.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ fileprivate extension SourceCodeFragment {
142142
self.init(enum: "tvOS", string: platform.version)
143143
case "watchos":
144144
self.init(enum: "watchOS", string: platform.version)
145+
case "visionos":
146+
self.init(enum: "visionOS", string: platform.version)
145147
case "driverkit":
146148
self.init(enum: "driverKit", string: platform.version)
147149
default:
@@ -367,6 +369,7 @@ fileprivate extension SourceCodeFragment {
367369
case "ios": return SourceCodeFragment(enum: "iOS")
368370
case "tvos": return SourceCodeFragment(enum: "tvOS")
369371
case "watchos": return SourceCodeFragment(enum: "watchOS")
372+
case "visionos": return SourceCodeFragment(enum: "visionOS")
370373
case "driverkit": return SourceCodeFragment(enum: "driverKit")
371374
default: return SourceCodeFragment(enum: platformName)
372375
}

Sources/PackageModel/MinimumDeploymentTarget.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ private extension PackageModel.Platform {
8181
return ("appletvos", "TVOS")
8282
case .watchOS:
8383
return ("watchos", "WATCHOS")
84+
case .visionOS:
85+
return ("xros", "XROS")
8486
case .driverKit:
8587
return nil // DriverKit does not support XCTest.
8688
default:

Sources/PackageModel/Platform.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public struct Platform: Equatable, Hashable, Codable {
3838
public static let iOS: Platform = Platform(name: "ios", oldestSupportedVersion: "11.0")
3939
public static let tvOS: Platform = Platform(name: "tvos", oldestSupportedVersion: "11.0")
4040
public static let watchOS: Platform = Platform(name: "watchos", oldestSupportedVersion: "4.0")
41+
public static let visionOS: Platform = Platform(name: "visionos", oldestSupportedVersion: "1.0")
4142
public static let driverKit: Platform = Platform(name: "driverkit", oldestSupportedVersion: "19.0")
4243
public static let linux: Platform = Platform(name: "linux", oldestSupportedVersion: .unknown)
4344
public static let android: Platform = Platform(name: "android", oldestSupportedVersion: .unknown)

Sources/PackageModel/PlatformRegistry.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ public final class PlatformRegistry {
3131

3232
/// The static list of known platforms.
3333
private static var _knownPlatforms: [Platform] {
34-
return [.macOS, .macCatalyst, .iOS, .tvOS, .watchOS, .linux, .windows, .android, .wasi, .driverKit, .openbsd]
34+
return [.macOS, .macCatalyst, .iOS, .tvOS, .watchOS, .visionOS, .linux, .windows, .android, .wasi, .driverKit, .openbsd]
3535
}
3636
}

Sources/Workspace/InitPackage.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,8 @@ extension PackageModel.Platform {
781781
return "tvOS"
782782
case .watchOS:
783783
return "watchOS"
784+
case .visionOS:
785+
return "visionOS"
784786
case .driverKit:
785787
return "DriverKit"
786788
default:
@@ -816,6 +818,8 @@ extension SupportedPlatform {
816818
return (9...14).contains(version.major)
817819
case .watchOS:
818820
return (2...7).contains(version.major)
821+
case .visionOS:
822+
return (1...1).contains(version.major)
819823
case .driverKit:
820824
return (19...20).contains(version.major)
821825

Sources/XCBuildSupport/PIF.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ public enum PIF {
953953
case USE_HEADERMAP
954954
case USES_SWIFTPM_UNSAFE_FLAGS
955955
case WATCHOS_DEPLOYMENT_TARGET
956+
case XROS_DEPLOYMENT_TARGET
956957
case MARKETING_VERSION
957958
case CURRENT_PROJECT_VERSION
958959
case SWIFT_EMIT_MODULE_INTERFACE

Sources/XCBuildSupport/PIFBuilder.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
273273
settings[.IPHONEOS_DEPLOYMENT_TARGET, for: .macCatalyst] = package.platforms.deploymentTarget(for: .macCatalyst)
274274
settings[.TVOS_DEPLOYMENT_TARGET] = package.platforms.deploymentTarget(for: .tvOS)
275275
settings[.WATCHOS_DEPLOYMENT_TARGET] = package.platforms.deploymentTarget(for: .watchOS)
276+
settings[.XROS_DEPLOYMENT_TARGET] = package.platforms.deploymentTarget(for: .visionOS)
276277
settings[.DRIVERKIT_DEPLOYMENT_TARGET] = package.platforms.deploymentTarget(for: .driverKit)
277278
settings[.DYLIB_INSTALL_NAME_BASE] = "@rpath"
278279
settings[.USE_HEADERMAP] = "NO"
@@ -430,6 +431,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
430431
settings[.IPHONEOS_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .iOS)
431432
settings[.TVOS_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .tvOS)
432433
settings[.WATCHOS_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .watchOS)
434+
settings[.XROS_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .visionOS)
433435
}
434436

435437
if product.type == .executable {

Tests/PackageGraphTests/PackageGraphTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,7 @@ class PackageGraphTests: XCTestCase {
21532153
"tvos": "11.0",
21542154
"driverkit": "19.0",
21552155
"watchos": "4.0",
2156+
"visionos": "1.0",
21562157
"android": "0.0",
21572158
"windows": "0.0",
21582159
"wasi": "0.0",
@@ -2164,6 +2165,7 @@ class PackageGraphTests: XCTestCase {
21642165
PackageModel.Platform.iOS: PlatformVersion("11.0"),
21652166
PackageModel.Platform.tvOS: PlatformVersion("10.0"),
21662167
PackageModel.Platform.watchOS: PlatformVersion("4.0"),
2168+
PackageModel.Platform.visionOS: PlatformVersion("1.0"),
21672169
]
21682170

21692171
let expectedPlatformsForTests = customXCTestMinimumDeploymentTargets.reduce(into: [Platform : PlatformVersion]()) { partialResult, entry in
@@ -2402,6 +2404,7 @@ class PackageGraphTests: XCTestCase {
24022404
"tvos": "11.0",
24032405
"driverkit": "19.0",
24042406
"watchos": "4.0",
2407+
"visionos": "1.0",
24052408
"android": "0.0",
24062409
"windows": "0.0",
24072410
"wasi": "0.0",

Tests/PackageLoadingTests/PD_5_9_LoadingTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class PackageDescription5_9LoadingTests: PackageDescriptionLoadingTests {
2828
name: "Foo",
2929
platforms: [
3030
.macOS(.v14), .iOS(.v17),
31-
.tvOS(.v17), .watchOS(.v10),
31+
.tvOS(.v17), .watchOS(.v10), .visionOS(.v1),
3232
.macCatalyst(.v17), .driverKit(.v23),
3333
]
3434
)
@@ -44,6 +44,7 @@ class PackageDescription5_9LoadingTests: PackageDescriptionLoadingTests {
4444
PlatformDescription(name: "ios", version: "17.0"),
4545
PlatformDescription(name: "tvos", version: "17.0"),
4646
PlatformDescription(name: "watchos", version: "10.0"),
47+
PlatformDescription(name: "visionos", version: "1.0"),
4748
PlatformDescription(name: "maccatalyst", version: "17.0"),
4849
PlatformDescription(name: "driverkit", version: "23.0"),
4950
])

Tests/WorkspaceTests/ManifestSourceGenerationTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ class ManifestSourceGenerationTests: XCTestCase {
437437
.iOS(.v17),
438438
.tvOS(.v17),
439439
.watchOS(.v10),
440+
.visionOS(.v1),
440441
.macCatalyst(.v17),
441442
.driverKit(.v23)
442443
],
@@ -461,8 +462,8 @@ class ManifestSourceGenerationTests: XCTestCase {
461462
name: "MyExe",
462463
dependencies: [
463464
.target(name: "MyLib", condition: .when(platforms: [
464-
.macOS, .macCatalyst, .iOS, .tvOS, .watchOS, .driverKit,
465-
.linux, .windows, .android, .wasi, .openbsd
465+
.macOS, .macCatalyst, .iOS, .tvOS, .watchOS, .visionOS,
466+
.driverKit, .linux, .windows, .android, .wasi, .openbsd
466467
]))
467468
]
468469
),

Tests/XCBuildSupportTests/PIFBuilderTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ class PIFBuilderTests: XCTestCase {
204204
XCTAssertEqual(settings[.TVOS_DEPLOYMENT_TARGET], "11.0")
205205
XCTAssertEqual(settings[.USE_HEADERMAP], "NO")
206206
XCTAssertEqual(settings[.WATCHOS_DEPLOYMENT_TARGET], "4.0")
207+
XCTAssertEqual(settings[.XROS_DEPLOYMENT_TARGET], "1.0")
207208

208209
let frameworksSearchPaths = ["$(inherited)", "$(PLATFORM_DIR)/Developer/Library/Frameworks"]
209210
for platform in [PIF.BuildSettings.Platform.macOS, .iOS, .tvOS] {
@@ -249,6 +250,7 @@ class PIFBuilderTests: XCTestCase {
249250
XCTAssertEqual(settings[.TVOS_DEPLOYMENT_TARGET], "11.0")
250251
XCTAssertEqual(settings[.USE_HEADERMAP], "NO")
251252
XCTAssertEqual(settings[.WATCHOS_DEPLOYMENT_TARGET], "4.0")
253+
XCTAssertEqual(settings[.XROS_DEPLOYMENT_TARGET], "1.0")
252254

253255
let frameworksSearchPaths = ["$(inherited)", "$(PLATFORM_DIR)/Developer/Library/Frameworks"]
254256
for platform in [PIF.BuildSettings.Platform.macOS, .iOS, .tvOS] {
@@ -306,6 +308,7 @@ class PIFBuilderTests: XCTestCase {
306308
XCTAssertEqual(settings[.TVOS_DEPLOYMENT_TARGET], "11.0")
307309
XCTAssertEqual(settings[.USE_HEADERMAP], "NO")
308310
XCTAssertEqual(settings[.WATCHOS_DEPLOYMENT_TARGET], "6.0")
311+
XCTAssertEqual(settings[.XROS_DEPLOYMENT_TARGET], "1.0")
309312

310313
let frameworksSearchPaths = ["$(inherited)", "$(PLATFORM_DIR)/Developer/Library/Frameworks"]
311314
for platform in [PIF.BuildSettings.Platform.macOS, .iOS, .tvOS] {
@@ -351,6 +354,7 @@ class PIFBuilderTests: XCTestCase {
351354
XCTAssertEqual(settings[.TVOS_DEPLOYMENT_TARGET], "11.0")
352355
XCTAssertEqual(settings[.USE_HEADERMAP], "NO")
353356
XCTAssertEqual(settings[.WATCHOS_DEPLOYMENT_TARGET], "6.0")
357+
XCTAssertEqual(settings[.XROS_DEPLOYMENT_TARGET], "1.0")
354358

355359
let frameworksSearchPaths = ["$(inherited)", "$(PLATFORM_DIR)/Developer/Library/Frameworks"]
356360
for platform in [PIF.BuildSettings.Platform.macOS, .iOS, .tvOS] {
@@ -836,6 +840,7 @@ class PIFBuilderTests: XCTestCase {
836840
XCTAssertEqual(settings[.IPHONEOS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .iOS).versionString)
837841
XCTAssertEqual(settings[.TVOS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .tvOS).versionString)
838842
XCTAssertEqual(settings[.MACOSX_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .macOS).versionString)
843+
XCTAssertEqual(settings[.XROS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .visionOS).versionString)
839844
}
840845
}
841846

@@ -868,6 +873,7 @@ class PIFBuilderTests: XCTestCase {
868873
XCTAssertEqual(settings[.IPHONEOS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .iOS).versionString)
869874
XCTAssertEqual(settings[.TVOS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .tvOS).versionString)
870875
XCTAssertEqual(settings[.MACOSX_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .macOS).versionString)
876+
XCTAssertEqual(settings[.XROS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .visionOS).versionString)
871877
}
872878
}
873879

@@ -914,6 +920,7 @@ class PIFBuilderTests: XCTestCase {
914920
XCTAssertEqual(settings[.IPHONEOS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .iOS).versionString)
915921
XCTAssertEqual(settings[.TVOS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .tvOS).versionString)
916922
XCTAssertEqual(settings[.MACOSX_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .macOS).versionString)
923+
XCTAssertEqual(settings[.XROS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .visionOS).versionString)
917924
}
918925
}
919926

@@ -949,6 +956,7 @@ class PIFBuilderTests: XCTestCase {
949956
XCTAssertEqual(settings[.IPHONEOS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .iOS).versionString)
950957
XCTAssertEqual(settings[.TVOS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .tvOS).versionString)
951958
XCTAssertEqual(settings[.MACOSX_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .macOS).versionString)
959+
XCTAssertEqual(settings[.XROS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .visionOS).versionString)
952960
}
953961
}
954962

0 commit comments

Comments
 (0)