Skip to content

Introduce visionOS Platform #1577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3164,7 +3164,7 @@ extension Driver {
extension Triple {
@_spi(Testing) public func toolchainType(_ diagnosticsEngine: DiagnosticsEngine) throws -> Toolchain.Type {
switch os {
case .darwin, .macosx, .ios, .tvos, .watchos:
case .darwin, .macosx, .ios, .tvos, .watchos, .visionos:
return DarwinToolchain.self
case .linux:
return GenericUnixToolchain.self
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ private extension DarwinPlatform {
return ["watchos"]
case .watchOS(.simulator):
return ["watchossim", "watchos"]
case .visionOS(.device):
return ["xros"]
case .visionOS(.simulator):
return ["xrossim", "xros"]
}
}
}
4 changes: 4 additions & 0 deletions Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ public struct SDKPrebuiltModuleInputsCollector {
return "arm64-apple-tvos\(version)"
case .appletvsimulator:
return "arm64-apple-tvos\(version)-simulator"
case .visionos:
return "arm64-apple-xros\(version)"
case .visionsimulator:
return "arm64-apple-xros\(version)-simulator"
case .unknown:
fatalError("unknown platform kind")
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/SwiftDriver/Toolchains/DarwinToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ public final class DarwinToolchain: Toolchain {
.macosx: (.macOS, Triple.Version(10, 9, 0)),
.ios: (.iOS(targetTriple._isSimulatorEnvironment ? .simulator : .device), Triple.Version(7, 0, 0)),
.tvos: (.tvOS(targetTriple._isSimulatorEnvironment ? .simulator : .device), Triple.Version(9, 0, 0)),
.watchos: (.watchOS(targetTriple._isSimulatorEnvironment ? .simulator : .device), Triple.Version(2, 0, 0))
.watchos: (.watchOS(targetTriple._isSimulatorEnvironment ? .simulator : .device), Triple.Version(2, 0, 0)),
.visionos: (.visionOS(targetTriple._isSimulatorEnvironment ? .simulator : .device), Triple.Version(1, 0, 0))
]
if let (platform, minVersion) = minVersions[os], targetTriple.version(for: platform) < minVersion {
throw ToolchainValidationError.osVersionBelowMinimumDeploymentTarget(platform: platform, version: minVersion)
Expand Down Expand Up @@ -288,6 +289,8 @@ public final class DarwinToolchain: Toolchain {
case watchsimulator
case appletvos
case appletvsimulator
case visionos
case visionsimulator
case unknown
}

Expand Down
39 changes: 38 additions & 1 deletion Sources/SwiftDriver/Utilities/Triple+Platforms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public enum DarwinPlatform: Hashable {
/// watchOS, corresponding to the `watchos` OS name.
case watchOS(EnvironmentWithoutCatalyst)

/// visionOS, corresponding to the `visionos` OS name.
case visionOS(EnvironmentWithoutCatalyst)

/// The most general form of environment information attached to a
/// `DarwinPlatform`.
///
Expand Down Expand Up @@ -76,6 +79,9 @@ public enum DarwinPlatform: Hashable {
case .watchOS:
guard let withoutCatalyst = environment.withoutCatalyst else { return nil }
return .watchOS(withoutCatalyst)
case .visionOS:
guard let withoutCatalyst = environment.withoutCatalyst else { return nil }
return .visionOS(withoutCatalyst)
}
}

Expand All @@ -97,6 +103,10 @@ public enum DarwinPlatform: Hashable {
return "watchOS"
case .watchOS(.simulator):
return "watchOS Simulator"
case .visionOS(.device):
return "visionOS"
case .visionOS(.simulator):
return "visionOS Simulator"
}
}

Expand All @@ -120,6 +130,10 @@ public enum DarwinPlatform: Hashable {
return "watchos"
case .watchOS(.simulator):
return "watchsimulator"
case .visionOS(.device):
return "xros"
case .visionOS(.simulator):
return "xrsimulator"
}
}

Expand All @@ -142,6 +156,10 @@ public enum DarwinPlatform: Hashable {
return "watchos"
case .watchOS(.simulator):
return "watchos-simulator"
case .visionOS(.device):
return "xros"
case .visionOS(.simulator):
return "xros-simulator"
}
}

Expand All @@ -165,6 +183,10 @@ public enum DarwinPlatform: Hashable {
return "watchos"
case .watchOS(.simulator):
return "watchossim"
case .visionOS(.device):
return "xros"
case .visionOS(.simulator):
return "xrossim"
}
}
}
Expand Down Expand Up @@ -197,6 +219,8 @@ extension Triple {
return _iOSVersion
case .watchOS:
return _watchOSVersion
case .visionOS:
return _visionOSVersion
}
}

Expand All @@ -223,6 +247,8 @@ extension Triple {
return .watchOS(makeEnvironment())
case .tvos:
return .tvOS(makeEnvironment())
case .visionos:
return .visionOS(makeEnvironment())
default:
return nil
}
Expand Down Expand Up @@ -272,6 +298,8 @@ extension Triple {
}

return osVersion
case .visionOS(_):
return _visionOSVersion
}
}

Expand All @@ -285,7 +313,7 @@ extension Triple {
switch os {
case nil:
fatalError("unknown OS")
case .darwin, .macosx, .ios, .tvos, .watchos:
case .darwin, .macosx, .ios, .tvos, .watchos, .visionos:
guard let darwinPlatform = darwinPlatform else {
fatalError("unsupported darwin platform kind?")
}
Expand Down Expand Up @@ -361,6 +389,7 @@ extension Triple {
public let iOS: Availability
public let tvOS: Availability
public let watchOS: Availability
public var visionOS: Availability

// TODO: We should have linux, windows, etc.
public let nonDarwin: Bool
Expand All @@ -379,8 +408,14 @@ extension Triple {
self.tvOS = tvOS
self.watchOS = watchOS
self.nonDarwin = nonDarwin
self.visionOS = iOS
}

public func withVisionOS(_ visionOS: Availability) -> FeatureAvailability {
var res = self
res.visionOS = visionOS
return res
}
/// Returns the version when the feature was introduced on the specified Darwin
/// platform, or `.unavailable` if the feature has not been introduced there.
public subscript(darwinPlatform: DarwinPlatform) -> Availability {
Expand All @@ -393,6 +428,8 @@ extension Triple {
return tvOS
case .watchOS:
return watchOS
case .visionOS:
return visionOS
}
}
}
Expand Down
33 changes: 30 additions & 3 deletions Sources/SwiftDriver/Utilities/Triple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ extension Triple {
case hurd
case wasi
case emscripten
case visionos = "xros"
case noneOS // 'OS' suffix purely to avoid name clash with Optional.none

var name: String {
Expand Down Expand Up @@ -1198,6 +1199,8 @@ extension Triple {
return .emscripten
case _ where os.hasPrefix("none"):
return .noneOS
case _ where os.hasPrefix("xros"):
return .visionos
default:
return nil
}
Expand Down Expand Up @@ -1490,9 +1493,14 @@ extension Triple.OS {
self == .watchos
}

public var isVisionOS: Bool {
self == .visionos
}


/// isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
public var isDarwin: Bool {
isMacOSX || isiOS || isWatchOS
isMacOSX || isiOS || isWatchOS || isVisionOS
}
}

Expand Down Expand Up @@ -1601,8 +1609,7 @@ extension Triple {
if version.major < 10 {
return nil
}

case .ios, .tvos, .watchos:
case .ios, .tvos, .watchos, .visionos:
// Ignore the version from the triple. This is only handled because the
// the clang driver combines OS X and IOS support into a common Darwin
// toolchain that wants to know the OS X version number even when targeting
Expand Down Expand Up @@ -1635,6 +1642,8 @@ extension Triple {
version.major = arch == .aarch64 ? 7 : 5
}
return version
case .visionos:
return Version(15, 0, 0)
case .watchos:
fatalError("conflicting triple info")
default:
Expand Down Expand Up @@ -1667,6 +1676,24 @@ extension Triple {
fatalError("unexpected OS for Darwin triple")
}
}

public var _visionOSVersion: Version {
switch os {
case .darwin, .macosx:
return Version(1, 0, 0)
case .visionos, .ios:
var version = self.osVersion
// Default to 1.0
if version.major == 0 {
version.major = 1
}
return version
case .watchos:
fatalError("conflicting triple info")
default:
fatalError("unexpected OS for Darwin triple")
}
}
}

// MARK: - Catalyst
Expand Down
10 changes: 10 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,16 @@ final class SwiftDriverTests: XCTestCase {
let jobs = try driver.planBuild()
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-dwarf-version=4")))
}

// TODO: Enable once compiler support lands
// try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-g", "-c", "-target", "arm64-apple-xros1.0-simulator") { driver in
// let jobs = try driver.planBuild()
// XCTAssertTrue(jobs[0].commandLine.contains(.flag("-dwarf-version=4")))
// }
// try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-g", "-c", "-target", "arm64-apple-xros1.0") { driver in
// let jobs = try driver.planBuild()
// XCTAssertTrue(jobs[0].commandLine.contains(.flag("-dwarf-version=4")))
// }
}

func testCoverageSettings() throws {
Expand Down