Skip to content

Recognize visionOS and DriverKit triples correctly #8898

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
69 changes: 66 additions & 3 deletions Sources/Basics/Vendor/Triple+Platforms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public enum DarwinPlatform: Hashable {
/// watchOS, corresponding to the `watchos` OS name.
case watchOS(EnvironmentWithoutCatalyst)

/// visionOS, corresponding to the `xros` and `visionos` OS names.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The triple implementation is vendor over from SwiftDriver so it's probably best to try to keep the two in sync

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will take a look.

case visionOS(EnvironmentWithoutCatalyst)

/// DriverKit, corresponding to the `driverkit` OS name.
case driverKit

/// The most general form of environment information attached to a
/// `DarwinPlatform`.
///
Expand Down Expand Up @@ -87,6 +93,11 @@ 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)
case .driverKit:
return .driverKit
}
}

Expand All @@ -108,6 +119,12 @@ public enum DarwinPlatform: Hashable {
return "watchOS"
case .watchOS(.simulator):
return "watchOS Simulator"
case .visionOS(.device):
return "visionOS"
case .visionOS(.simulator):
return "visionOS Simulator"
case .driverKit:
return "DriverKit"
}
}

Expand All @@ -131,6 +148,12 @@ public enum DarwinPlatform: Hashable {
return "watchos"
case .watchOS(.simulator):
return "watchsimulator"
case .visionOS(.device):
return "xros"
case .visionOS(.simulator):
return "xrsimulator"
case .driverKit:
return "driverkit"
}
}

Expand All @@ -153,6 +176,12 @@ public enum DarwinPlatform: Hashable {
return "watchos"
case .watchOS(.simulator):
return "watchos-simulator"
case .visionOS(.device):
return "visionos"
case .visionOS(.simulator):
return "visionos-simulator"
case .driverKit:
return "driverkit"
}
}

Expand All @@ -176,6 +205,12 @@ public enum DarwinPlatform: Hashable {
return "watchos"
case .watchOS(.simulator):
return "watchossim"
case .visionOS(.device):
return "xros"
case .visionOS(.simulator):
return "xrossim"
case .driverKit:
return "driverkit"
}
}
}
Expand Down Expand Up @@ -208,6 +243,10 @@ extension Triple {
return _iOSVersion
case .watchOS:
return _watchOSVersion
case .visionOS:
return _visionOSVersion
case .driverKit:
return _driverKitOSVersion
}
}

Expand All @@ -234,6 +273,10 @@ extension Triple {
return .watchOS(makeEnvironment())
case .tvos:
return .tvOS(makeEnvironment())
case .visionos:
return .visionOS(makeEnvironment())
case .driverkit:
return .driverKit
default:
return nil
}
Expand Down Expand Up @@ -282,6 +325,13 @@ extension Triple {
return Version(7, 0, 0)
}

return osVersion
case .visionOS(_):
return osVersion
case .driverKit:
if osVersion.major < 19 {
return Version(19, 0, 0)
}
return osVersion
}
}
Expand All @@ -296,12 +346,13 @@ 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?")
}
return conflatingDarwin ? "darwin" : darwinPlatform.platformName

case .driverkit:
return "driverkit"
case .linux:
return environment == .android ? "android" : "linux"
case .freebsd:
Expand Down Expand Up @@ -362,6 +413,8 @@ public struct FeatureAvailability: Sendable {
public let iOS: Availability
public let tvOS: Availability
public let watchOS: Availability
public let visionOS: Availability
public let driverKit: Availability

// TODO: We should have linux, windows, etc.
public let nonDarwin: Bool
Expand All @@ -373,12 +426,16 @@ public struct FeatureAvailability: Sendable {
iOS: Availability,
tvOS: Availability,
watchOS: Availability,
visionOS: Availability,
driverKit: Availability,
nonDarwin: Bool = false
) {
self.macOS = macOS
self.iOS = iOS
self.tvOS = tvOS
self.watchOS = watchOS
self.visionOS = visionOS
self.driverKit = driverKit
self.nonDarwin = nonDarwin
}

Expand All @@ -394,6 +451,10 @@ public struct FeatureAvailability: Sendable {
return tvOS
case .watchOS:
return watchOS
case .visionOS:
return visionOS
case .driverKit:
return driverKit
}
}
}
Expand Down Expand Up @@ -429,7 +490,9 @@ extension Triple.FeatureAvailability {
macOS: .available(since: Triple.Version(10, 11, 0)),
iOS: .available(since: Triple.Version(9, 0, 0)),
tvOS: .available(since: Triple.Version(9, 0, 0)),
watchOS: .availableInAllVersions
watchOS: .availableInAllVersions,
visionOS: .availableInAllVersions,
driverKit: .availableInAllVersions // no Objective-C in DriverKit, but ARClite shouldn't be linked
)
// When updating the versions listed here, please record the most recent
// feature being depended on and when it was introduced:
Expand Down
57 changes: 52 additions & 5 deletions Sources/Basics/Vendor/Triple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,7 @@ extension Triple {
case cloudABI = "cloudabi"
case darwin
case dragonFly = "dragonfly"
case driverkit
case freebsd = "freebsd"
case fuchsia
case ios
Expand All @@ -1113,6 +1114,7 @@ extension Triple {
case elfiamcu
case tvos
case watchos
case visionos = "xros"
case mesa3d
case contiki
case amdpal
Expand All @@ -1136,6 +1138,8 @@ extension Triple {
return .darwin
case _ where os.hasPrefix("dragonfly"):
return .dragonFly
case _ where os.hasPrefix("driverkit"):
return .driverkit
case _ where os.hasPrefix("freebsd"):
return .freebsd
case _ where os.hasPrefix("fuchsia"):
Expand Down Expand Up @@ -1186,6 +1190,8 @@ extension Triple {
return .tvos
case _ where os.hasPrefix("watchos"):
return .watchos
case _ where os.hasPrefix("xros") || os.hasPrefix("visionos"):
return .visionos
case _ where os.hasPrefix("mesa3d"):
return .mesa3d
case _ where os.hasPrefix("contiki"):
Expand Down Expand Up @@ -1479,6 +1485,7 @@ extension Triple.OS {
/// changes, i.e., if the two operating systems diverge or their version
/// numbers get out of sync, that will need to be changed.
/// watchOS has completely different version numbers so it is not included.
@available(*, unavailable, message: "Do not use - this confusingly named property indicates either iOS or tvOS due to LLVM history. Compare directly with .ios or .tvos as needed.")
public var isiOS: Bool {
self == .ios || isTvOS
}
Expand All @@ -1493,9 +1500,9 @@ extension Triple.OS {
self == .watchos
}

/// isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
/// isOSDarwin - Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, visionOS, or DriverKit).
public var isDarwin: Bool {
isMacOSX || isiOS || isWatchOS
[.darwin, .macosx, .ios, .tvos, .watchos, .visionos, .driverkit].contains(self)
}
}

Expand Down Expand Up @@ -1605,7 +1612,7 @@ extension Triple {
return nil
}

case .ios, .tvos, .watchos:
case .ios, .tvos, .watchos, .visionos, .driverkit:
// 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 @@ -1638,7 +1645,7 @@ extension Triple {
version.major = arch == .aarch64 ? 7 : 5
}
return version
case .watchos:
case .watchos, .visionos, .driverkit:
fatalError("conflicting triple info")
default:
fatalError("unexpected OS for Darwin triple")
Expand Down Expand Up @@ -1670,13 +1677,53 @@ extension Triple {
fatalError("unexpected OS for Darwin triple")
}
}

/// Parse the version number as with getOSVersion. This should only be
/// called with visionOS or generic triples.
///
/// This accessor is semi-private; it's typically better to use `version(for:)` or
/// `Triple.FeatureAvailability`.
public var _visionOSVersion: Version {
switch os {
case .visionos:
var version = self.osVersion
if version.major == 0 {
version.major = 1
}
return version
case .darwin, .macosx, .ios, .tvos, .watchos:
fatalError("conflicting triple info")
default:
fatalError("unexpected OS for Darwin triple")
}
}

/// Parse the version number as with getOSVersion. This should only be
/// called with DriverKit or generic triples.
///
/// This accessor is semi-private; it's typically better to use `version(for:)` or
/// `Triple.FeatureAvailability`.
public var _driverKitOSVersion: Version {
switch os {
case .driverkit:
var version = self.osVersion
if version.major == 0 {
version.major = 1
}
return version
case .darwin, .macosx, .ios, .tvos, .watchos, .visionos:
fatalError("conflicting triple info")
default:
fatalError("unexpected OS for Darwin triple")
}
}
}

// MARK: - Catalyst

extension Triple {
@_spi(Testing) public var isMacCatalyst: Bool {
return self.isiOS && !self.isTvOS && environment == .macabi
return os == .ios && environment == .macabi
}

func isValidForZipperingWithTriple(_ variant: Triple) -> Bool {
Expand Down
4 changes: 4 additions & 0 deletions Sources/SPMBuildCore/BinaryTarget+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ extension Triple.OS {
return "tvos"
case .watchos:
return "watchos"
case .visionos:
return "xros"
case .driverkit:
return "driverkit"
default:
return nil // XCFrameworks do not support any of these platforms today.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public struct BuildParameters: Encodable {
var currentPlatform: PackageModel.Platform {
if self.triple.isDarwin() {
switch self.triple.darwinPlatform {
case .driverKit:
return .driverKit
case .iOS(.catalyst):
return .macCatalyst
case .iOS(.device), .iOS(.simulator):
Expand All @@ -105,6 +107,8 @@ public struct BuildParameters: Encodable {
return .tvOS
case .watchOS:
return .watchOS
case .visionOS:
return .visionOS
case .macOS, nil:
return .macOS
}
Expand All @@ -118,8 +122,10 @@ public struct BuildParameters: Encodable {
return .openbsd
} else if self.triple.isFreeBSD() {
return .freebsd
} else {
} else if self.triple.isLinux() {
return .linux
} else {
return .custom(name: "unknown", oldestSupportedVersion: .unknown)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftBuildSupport/PackagePIFProjectBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ struct PackagePIFProjectBuilder {
.iOS: moduleDeploymentTargets?[.iOS],
.tvOS: moduleDeploymentTargets?[.tvOS],
.watchOS: moduleDeploymentTargets?[.watchOS],
.visionOS: moduleDeploymentTargets?[.visionOS],
.driverKit: moduleDeploymentTargets?[.driverKit],
]
deploymentTargets[.visionOS] = moduleDeploymentTargets?[.visionOS]
let declaredPlatforms = firstModule?.declaredPlatforms

// Compute the names of all explicitly dynamic library products, we need to avoid
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftBuildSupport/SwiftBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,10 @@ fileprivate extension Triple {
return "TVOS_DEPLOYMENT_TARGET"
case (.watchos, _):
return "WATCHOS_DEPLOYMENT_TARGET"
case (.visionos, _):
return "XROS_DEPLOYMENT_TARGET"
case (.driverkit, _):
return "DRIVERKIT_DEPLOYMENT_TARGET"
case (_, .android):
return "ANDROID_DEPLOYMENT_TARGET"
default:
Expand Down
2 changes: 2 additions & 0 deletions Sources/XCBuildSupport/PIF.swift
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,7 @@ public enum PIF {
case iOS = "ios"
case tvOS = "tvos"
case watchOS = "watchos"
case visionOS = "visionos"
case driverKit = "driverkit"
case linux

Expand All @@ -995,6 +996,7 @@ public enum PIF {
case .iOS: return .iOS
case .tvOS: return .tvOS
case .watchOS: return .watchOS
case .visionOS: return .visionOS
case .driverKit: return .driverKit
case .linux: return .linux
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/XCBuildSupport/PIFBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
settings[.ENABLE_TESTING_SEARCH_PATHS] = "YES"

// XCTest search paths should only be specified for certain platforms (watchOS doesn't have XCTest).
for platform: PIF.BuildSettings.Platform in [.macOS, .iOS, .tvOS] {
for platform: PIF.BuildSettings.Platform in [.macOS, .iOS, .tvOS, .visionOS] {
settings[.FRAMEWORK_SEARCH_PATHS, for: platform, default: ["$(inherited)"]]
.append("$(PLATFORM_DIR)/Developer/Library/Frameworks")
}
Expand Down Expand Up @@ -1949,6 +1949,7 @@ extension PIF.BuildSettings.Platform {
case .macOS: .macOS
case .tvOS: .tvOS
case .watchOS: .watchOS
case .visionOS: .visionOS
case .driverKit: .driverKit
default: nil
}
Expand Down
Loading