diff --git a/README.md b/README.md index 0b2c05629..768db246a 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ This repository contains rules for [Bazel](https://bazel.build) that can be used to build Swift libraries, tests, and executables for macOS and Linux. -To build applications for all of Apple's platforms (macOS, iOS, tvOS, and -watchOS), they can be combined with the +To build applications for all of Apple's platforms (macOS, iOS, tvOS, +visionOS, and watchOS), they can be combined with the [Apple Rules](https://github.com/bazelbuild/rules_apple). If you run into any problems with these rules, please diff --git a/swift/internal/target_triples.bzl b/swift/internal/target_triples.bzl index 6b53d1c4d..78d39c412 100644 --- a/swift/internal/target_triples.bzl +++ b/swift/internal/target_triples.bzl @@ -102,7 +102,7 @@ def _normalize_for_swift(triple, *, unversioned = False): A target triple struct containing the normalized triple. """ os = _normalize_apple_os(triple.os, unversioned = unversioned) - if os.startswith(("ios", "macos", "tvos", "watchos")): + if os.startswith(("ios", "macos", "tvos", "visionos", "watchos")): return _make( cpu = _normalize_apple_cpu(triple.cpu), vendor = "apple", @@ -163,6 +163,8 @@ def _platform_name_for_swift(triple): return "iphonesimulator" if is_simulator else "iphoneos" if os == "tvos": return "appletvsimulator" if is_simulator else "appletvos" + if os == "visionos": + return "visionossimulator" if is_simulator else "visionos" if os == "watchos": return "watchsimulator" if is_simulator else "watchos" diff --git a/swift/internal/xcode_swift_toolchain.bzl b/swift/internal/xcode_swift_toolchain.bzl index 39c1d5921..e97be0c6b 100644 --- a/swift/internal/xcode_swift_toolchain.bzl +++ b/swift/internal/xcode_swift_toolchain.bzl @@ -75,12 +75,23 @@ _TRIPLE_OS_TO_PLATFORM = { ("macos", None): apple_common.platform.macos, ("tvos", None): apple_common.platform.tvos_device, ("tvos", "simulator"): apple_common.platform.tvos_simulator, + # TODO: Remove getattr use once we no longer support 6.x + ("xros", None): getattr(apple_common.platform, "visionos_device", None), + ("xros", "simulator"): getattr(apple_common.platform, "visionos_simulator", None), ("watchos", None): apple_common.platform.watchos_device, ("watchos", "simulator"): apple_common.platform.watchos_simulator, } def _bazel_apple_platform(target_triple): """Returns the `apple_common.platform` value for the given target triple.""" + + # TODO: Remove once we no longer support 6.x + if target_triples.unversioned_os(target_triple) == "xros" and not hasattr( + apple_common.platform, + "visionos_device", + ): + fail("visionOS requested but your version of bazel doesn't support it") + return _TRIPLE_OS_TO_PLATFORM[( target_triples.unversioned_os(target_triple), target_triple.environment,