Skip to content

Commit

Permalink
Add initial visionOS support (#1076)
Browse files Browse the repository at this point in the history
  • Loading branch information
keith committed Sep 7, 2023
1 parent fc01b10 commit d48482e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion swift/internal/target_triples.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"

Expand Down
11 changes: 11 additions & 0 deletions swift/internal/xcode_swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d48482e

Please sign in to comment.