Skip to content

Commit

Permalink
Add visionOS as a platform alongside iOS, tvOS, watchOS, and …
Browse files Browse the repository at this point in the history
…the others (swiftlang#6662)

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
  • Loading branch information
abertelrud authored Jun 21, 2023
1 parent 4e6501b commit 809cb15
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ extension PackageModel.Platform {
self = PackageModel.Platform.tvOS
case let name where name.contains("watchos"):
self = PackageModel.Platform.watchOS
case let name where name.contains("visionos"):
self = PackageModel.Platform.visionOS
case let name where name.contains("driverkit"):
self = PackageModel.Platform.driverKit
case let name where name.contains("linux"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
- <doc:/documentation/PackageDescription/Platform/watchOS>
- ``WatchOSVersion``

### Supporting visionOS

- ``visionOS(_:)-3ip0z``
- ``visionOS(_:)-6ur2u``
- <doc:/documentation/PackageDescription/Platform/visionOS>
- ``VisionOSVersion``

### Supporting tvOS

- ``tvOS(_:)-6931l``
Expand Down
49 changes: 49 additions & 0 deletions Sources/PackageDescription/SupportedPlatforms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public struct Platform: Equatable {
/// The watchOS platform.
public static let watchOS: Platform = Platform(name: "watchos")

/// The visionOS platform.
public static let visionOS: Platform = Platform(name: "visionos")

/// The DriverKit platform
public static let driverKit: Platform = Platform(name: "driverkit")

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

/// Configure the minimum deployment target version for the visionOS
/// platform.
///
/// - Since: First available in PackageDescription 5.9
///
/// - Parameter version: The minimum deployment target that the package supports.
/// - Returns: A `SupportedPlatform` instance.
@available(_PackageDescription, introduced: 5.9)
public static func visionOS(_ version: SupportedPlatform.VisionOSVersion) -> SupportedPlatform {
return SupportedPlatform(platform: .visionOS, version: version.version)
}

/// Configure the minimum deployment target version for the visionOS
/// platform using a custom version string.
///
/// The version string must be a series of two or three dot-separated integers, such as `1.0` or `1.0.0`.
///
/// - Since: First available in PackageDescription 5.9
///
/// - Parameter versionString: The minimum deployment target as a string
/// representation of two or three dot-separated integers, such as `1.0.0`.
/// - Returns: A `SupportedPlatform` instance.
@available(_PackageDescription, introduced: 5.9)
public static func visionOS(_ versionString: String) -> SupportedPlatform {
return SupportedPlatform(platform: .visionOS, version: SupportedPlatform.VisionOSVersion(string: versionString).version)
}

/// Configures the minimum deployment target version for the DriverKit platform.
///
/// - Parameter version: The minimum deployment target that the package supports.
Expand Down Expand Up @@ -594,6 +624,25 @@ extension SupportedPlatform {
public static let v10: WatchOSVersion = .init(string: "10.0")
}

/// The supported visionOS version.
public struct VisionOSVersion: AppleOSVersion {
fileprivate static let name = "visionOS"
fileprivate static let minimumMajorVersion = 1

/// The underlying version representation.
let version: String

fileprivate init(uncheckedVersion version: String) {
self.version = version
}

/// The value that represents visionOS 1.0.
///
/// - Since: First available in PackageDescription 5.9.
@available(_PackageDescription, introduced: 5.9)
public static let v1: VisionOSVersion = .init(string: "1.0")
}

/// The supported DriverKit version.
public struct DriverKitVersion: AppleOSVersion {
fileprivate static let name = "DriverKit"
Expand Down
3 changes: 3 additions & 0 deletions Sources/PackageModel/ManifestSourceGeneration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ fileprivate extension SourceCodeFragment {
self.init(enum: "tvOS", string: platform.version)
case "watchos":
self.init(enum: "watchOS", string: platform.version)
case "visionos":
self.init(enum: "visionOS", string: platform.version)
case "driverkit":
self.init(enum: "driverKit", string: platform.version)
default:
Expand Down Expand Up @@ -366,6 +368,7 @@ fileprivate extension SourceCodeFragment {
case "ios": return SourceCodeFragment(enum: "iOS")
case "tvos": return SourceCodeFragment(enum: "tvOS")
case "watchos": return SourceCodeFragment(enum: "watchOS")
case "visionos": return SourceCodeFragment(enum: "visionOS")
case "driverkit": return SourceCodeFragment(enum: "driverKit")
default: return SourceCodeFragment(enum: platformName)
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/PackageModel/MinimumDeploymentTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ private extension PackageModel.Platform {
return ("appletvos", "TVOS")
case .watchOS:
return ("watchos", "WATCHOS")
case .visionOS:
return ("xros", "XROS")
case .driverKit:
return nil // DriverKit does not support XCTest.
default:
Expand Down
1 change: 1 addition & 0 deletions Sources/PackageModel/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public struct Platform: Equatable, Hashable, Codable {
public static let iOS: Platform = Platform(name: "ios", oldestSupportedVersion: "11.0")
public static let tvOS: Platform = Platform(name: "tvos", oldestSupportedVersion: "11.0")
public static let watchOS: Platform = Platform(name: "watchos", oldestSupportedVersion: "4.0")
public static let visionOS: Platform = Platform(name: "visionos", oldestSupportedVersion: "1.0")
public static let driverKit: Platform = Platform(name: "driverkit", oldestSupportedVersion: "19.0")
public static let linux: Platform = Platform(name: "linux", oldestSupportedVersion: .unknown)
public static let android: Platform = Platform(name: "android", oldestSupportedVersion: .unknown)
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageModel/PlatformRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public final class PlatformRegistry {

/// The static list of known platforms.
private static var _knownPlatforms: [Platform] {
return [.macOS, .macCatalyst, .iOS, .tvOS, .watchOS, .linux, .windows, .android, .wasi, .driverKit, .openbsd]
return [.macOS, .macCatalyst, .iOS, .tvOS, .watchOS, .visionOS, .linux, .windows, .android, .wasi, .driverKit, .openbsd]
}
}
4 changes: 4 additions & 0 deletions Sources/Workspace/InitPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,8 @@ extension PackageModel.Platform {
return "tvOS"
case .watchOS:
return "watchOS"
case .visionOS:
return "visionOS"
case .driverKit:
return "DriverKit"
default:
Expand Down Expand Up @@ -834,6 +836,8 @@ extension SupportedPlatform {
return (9...14).contains(version.major)
case .watchOS:
return (2...7).contains(version.major)
case .visionOS:
return (1...1).contains(version.major)
case .driverKit:
return (19...20).contains(version.major)

Expand Down
1 change: 1 addition & 0 deletions Sources/XCBuildSupport/PIF.swift
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@ public enum PIF {
case USE_HEADERMAP
case USES_SWIFTPM_UNSAFE_FLAGS
case WATCHOS_DEPLOYMENT_TARGET
case XROS_DEPLOYMENT_TARGET
case MARKETING_VERSION
case CURRENT_PROJECT_VERSION
case SWIFT_EMIT_MODULE_INTERFACE
Expand Down
2 changes: 2 additions & 0 deletions Sources/XCBuildSupport/PIFBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
settings[.IPHONEOS_DEPLOYMENT_TARGET, for: .macCatalyst] = package.platforms.deploymentTarget(for: .macCatalyst)
settings[.TVOS_DEPLOYMENT_TARGET] = package.platforms.deploymentTarget(for: .tvOS)
settings[.WATCHOS_DEPLOYMENT_TARGET] = package.platforms.deploymentTarget(for: .watchOS)
settings[.XROS_DEPLOYMENT_TARGET] = package.platforms.deploymentTarget(for: .visionOS)
settings[.DRIVERKIT_DEPLOYMENT_TARGET] = package.platforms.deploymentTarget(for: .driverKit)
settings[.DYLIB_INSTALL_NAME_BASE] = "@rpath"
settings[.USE_HEADERMAP] = "NO"
Expand Down Expand Up @@ -430,6 +431,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
settings[.IPHONEOS_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .iOS)
settings[.TVOS_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .tvOS)
settings[.WATCHOS_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .watchOS)
settings[.XROS_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .visionOS)
}

if product.type == .executable {
Expand Down
3 changes: 3 additions & 0 deletions Tests/PackageGraphTests/PackageGraphTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2155,6 +2155,7 @@ class PackageGraphTests: XCTestCase {
"tvos": "11.0",
"driverkit": "19.0",
"watchos": "4.0",
"visionos": "1.0",
"android": "0.0",
"windows": "0.0",
"wasi": "0.0",
Expand All @@ -2166,6 +2167,7 @@ class PackageGraphTests: XCTestCase {
PackageModel.Platform.iOS: PlatformVersion("11.0"),
PackageModel.Platform.tvOS: PlatformVersion("10.0"),
PackageModel.Platform.watchOS: PlatformVersion("4.0"),
PackageModel.Platform.visionOS: PlatformVersion("1.0"),
]

let expectedPlatformsForTests = customXCTestMinimumDeploymentTargets.reduce(into: [Platform : PlatformVersion]()) { partialResult, entry in
Expand Down Expand Up @@ -2404,6 +2406,7 @@ class PackageGraphTests: XCTestCase {
"tvos": "11.0",
"driverkit": "19.0",
"watchos": "4.0",
"visionos": "1.0",
"android": "0.0",
"windows": "0.0",
"wasi": "0.0",
Expand Down
3 changes: 2 additions & 1 deletion Tests/PackageLoadingTests/PD_5_9_LoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PackageDescription5_9LoadingTests: PackageDescriptionLoadingTests {
name: "Foo",
platforms: [
.macOS(.v14), .iOS(.v17),
.tvOS(.v17), .watchOS(.v10),
.tvOS(.v17), .watchOS(.v10), .visionOS(.v1),
.macCatalyst(.v17), .driverKit(.v23),
]
)
Expand All @@ -44,6 +44,7 @@ class PackageDescription5_9LoadingTests: PackageDescriptionLoadingTests {
PlatformDescription(name: "ios", version: "17.0"),
PlatformDescription(name: "tvos", version: "17.0"),
PlatformDescription(name: "watchos", version: "10.0"),
PlatformDescription(name: "visionos", version: "1.0"),
PlatformDescription(name: "maccatalyst", version: "17.0"),
PlatformDescription(name: "driverkit", version: "23.0"),
])
Expand Down
5 changes: 3 additions & 2 deletions Tests/WorkspaceTests/ManifestSourceGenerationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ class ManifestSourceGenerationTests: XCTestCase {
.iOS(.v17),
.tvOS(.v17),
.watchOS(.v10),
.visionOS(.v1),
.macCatalyst(.v17),
.driverKit(.v23)
],
Expand All @@ -460,8 +461,8 @@ class ManifestSourceGenerationTests: XCTestCase {
name: "MyExe",
dependencies: [
.target(name: "MyLib", condition: .when(platforms: [
.macOS, .macCatalyst, .iOS, .tvOS, .watchOS, .driverKit,
.linux, .windows, .android, .wasi, .openbsd
.macOS, .macCatalyst, .iOS, .tvOS, .watchOS, .visionOS,
.driverKit, .linux, .windows, .android, .wasi, .openbsd
]))
]
),
Expand Down
8 changes: 8 additions & 0 deletions Tests/XCBuildSupportTests/PIFBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class PIFBuilderTests: XCTestCase {
XCTAssertEqual(settings[.TVOS_DEPLOYMENT_TARGET], "11.0")
XCTAssertEqual(settings[.USE_HEADERMAP], "NO")
XCTAssertEqual(settings[.WATCHOS_DEPLOYMENT_TARGET], "4.0")
XCTAssertEqual(settings[.XROS_DEPLOYMENT_TARGET], "1.0")

let frameworksSearchPaths = ["$(inherited)", "$(PLATFORM_DIR)/Developer/Library/Frameworks"]
for platform in [PIF.BuildSettings.Platform.macOS, .iOS, .tvOS] {
Expand Down Expand Up @@ -252,6 +253,7 @@ class PIFBuilderTests: XCTestCase {
XCTAssertEqual(settings[.TVOS_DEPLOYMENT_TARGET], "11.0")
XCTAssertEqual(settings[.USE_HEADERMAP], "NO")
XCTAssertEqual(settings[.WATCHOS_DEPLOYMENT_TARGET], "4.0")
XCTAssertEqual(settings[.XROS_DEPLOYMENT_TARGET], "1.0")

let frameworksSearchPaths = ["$(inherited)", "$(PLATFORM_DIR)/Developer/Library/Frameworks"]
for platform in [PIF.BuildSettings.Platform.macOS, .iOS, .tvOS] {
Expand Down Expand Up @@ -309,6 +311,7 @@ class PIFBuilderTests: XCTestCase {
XCTAssertEqual(settings[.TVOS_DEPLOYMENT_TARGET], "11.0")
XCTAssertEqual(settings[.USE_HEADERMAP], "NO")
XCTAssertEqual(settings[.WATCHOS_DEPLOYMENT_TARGET], "6.0")
XCTAssertEqual(settings[.XROS_DEPLOYMENT_TARGET], "1.0")

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

let frameworksSearchPaths = ["$(inherited)", "$(PLATFORM_DIR)/Developer/Library/Frameworks"]
for platform in [PIF.BuildSettings.Platform.macOS, .iOS, .tvOS] {
Expand Down Expand Up @@ -839,6 +843,7 @@ class PIFBuilderTests: XCTestCase {
XCTAssertEqual(settings[.IPHONEOS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .iOS).versionString)
XCTAssertEqual(settings[.TVOS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .tvOS).versionString)
XCTAssertEqual(settings[.MACOSX_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .macOS).versionString)
XCTAssertEqual(settings[.XROS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .visionOS).versionString)
}
}

Expand Down Expand Up @@ -871,6 +876,7 @@ class PIFBuilderTests: XCTestCase {
XCTAssertEqual(settings[.IPHONEOS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .iOS).versionString)
XCTAssertEqual(settings[.TVOS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .tvOS).versionString)
XCTAssertEqual(settings[.MACOSX_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .macOS).versionString)
XCTAssertEqual(settings[.XROS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .visionOS).versionString)
}
}

Expand Down Expand Up @@ -917,6 +923,7 @@ class PIFBuilderTests: XCTestCase {
XCTAssertEqual(settings[.IPHONEOS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .iOS).versionString)
XCTAssertEqual(settings[.TVOS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .tvOS).versionString)
XCTAssertEqual(settings[.MACOSX_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .macOS).versionString)
XCTAssertEqual(settings[.XROS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .visionOS).versionString)
}
}

Expand Down Expand Up @@ -952,6 +959,7 @@ class PIFBuilderTests: XCTestCase {
XCTAssertEqual(settings[.IPHONEOS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .iOS).versionString)
XCTAssertEqual(settings[.TVOS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .tvOS).versionString)
XCTAssertEqual(settings[.MACOSX_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .macOS).versionString)
XCTAssertEqual(settings[.XROS_DEPLOYMENT_TARGET], MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .visionOS).versionString)
}
}

Expand Down

0 comments on commit 809cb15

Please sign in to comment.