Skip to content

Commit

Permalink
Add initial visionOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
keith committed Jul 11, 2023
1 parent fffb822 commit fa7fb2a
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Apple related [platforms](platforms/BUILD) and
[constraints](constraints/BUILD) definitions, and small helper functions
for rules authors targeting Apple platforms.

If you want to build iOS, tvOS, watchOS, or macOS apps, use
If you want to build iOS, tvOS, visionOS, watchOS, or macOS apps, use
[`rules_apple`][rules_apple].

If you want to build Swift use
Expand Down
15 changes: 15 additions & 0 deletions configs/platforms.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ APPLE_PLATFORMS_CONSTRAINTS = {
"@platforms//cpu:arm64",
"@build_bazel_apple_support//constraints:simulator",
],
"visionos_arm64": [
"@platforms//os:visionos",
"@platforms//cpu:arm64",
"@build_bazel_apple_support//constraints:device",
],
"visionos_sim_arm64": [
"@platforms//os:visionos",
"@platforms//cpu:arm64",
"@build_bazel_apple_support//constraints:simulator",
],
"visionos_x86_64": [
"@platforms//os:visionos",
"@platforms//cpu:x86_64",
"@build_bazel_apple_support//constraints:simulator",
],
"watchos_arm64": [
"@platforms//os:watchos",
"@platforms//cpu:arm64",
Expand Down
18 changes: 16 additions & 2 deletions crosstool/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def _impl(ctx):
target_system_name = "arm64-apple-ios{}".format(target_os_version)
elif (ctx.attr.cpu == "tvos_arm64"):
target_system_name = "arm64-apple-tvos{}".format(target_os_version)
elif (ctx.attr.cpu == "visionos_arm64"):
target_system_name = "arm64-apple-xros{}".format(target_os_version)
elif (ctx.attr.cpu == "watchos_arm64_32"):
target_system_name = "arm64_32-apple-watchos{}".format(target_os_version)
elif (ctx.attr.cpu == "ios_arm64e"):
Expand All @@ -73,6 +75,8 @@ def _impl(ctx):
target_system_name = "arm64-apple-ios{}-simulator".format(target_os_version)
elif (ctx.attr.cpu == "tvos_sim_arm64"):
target_system_name = "arm64-apple-tvos{}-simulator".format(target_os_version)
elif (ctx.attr.cpu == "visionos_sim_arm64"):
target_system_name = "arm64-apple-xros{}-simulator".format(target_os_version)
elif (ctx.attr.cpu == "watchos_arm64"):
target_system_name = "arm64-apple-watchos{}-simulator".format(target_os_version)
elif (ctx.attr.cpu == "darwin_x86_64"):
Expand All @@ -83,6 +87,8 @@ def _impl(ctx):
target_system_name = "arm64e-apple-macosx{}".format(target_os_version)
elif (ctx.attr.cpu == "tvos_x86_64"):
target_system_name = "x86_64-apple-tvos{}-simulator".format(target_os_version)
elif (ctx.attr.cpu == "visionos_x86_64"):
target_system_name = "x86_64-apple-xros{}-simulator".format(target_os_version)
elif (ctx.attr.cpu == "watchos_x86_64"):
target_system_name = "x86_64-apple-watchos{}-simulator".format(target_os_version)
else:
Expand All @@ -101,7 +107,7 @@ def _impl(ctx):
abi_version = "local"

arch = ctx.attr.cpu.split("_", 1)[-1]
if ctx.attr.cpu in ["ios_sim_arm64", "tvos_sim_arm64", "watchos_arm64"]:
if ctx.attr.cpu in ["ios_sim_arm64", "tvos_sim_arm64", "visionos_sim_arm64", "watchos_arm64"]:
arch = "arm64"

all_link_actions = [
Expand Down Expand Up @@ -678,8 +684,11 @@ def _impl(ctx):
ctx.attr.cpu == "ios_arm64e" or
ctx.attr.cpu == "ios_armv7" or
ctx.attr.cpu == "ios_i386" or
ctx.attr.cpu == "ios_x86_64" or
ctx.attr.cpu == "ios_sim_arm64" or
ctx.attr.cpu == "ios_x86_64" or
ctx.attr.cpu == "visionos_arm64" or
ctx.attr.cpu == "visionos_sim_arm64" or
ctx.attr.cpu == "visionos_x86_64" or
ctx.attr.cpu == "watchos_arm64_32" or
ctx.attr.cpu == "watchos_armv7k" or
ctx.attr.cpu == "watchos_i386" or
Expand Down Expand Up @@ -867,6 +876,8 @@ def _impl(ctx):
ctx.attr.cpu == "ios_sim_arm64" or
ctx.attr.cpu == "tvos_x86_64" or
ctx.attr.cpu == "tvos_sim_arm64" or
ctx.attr.cpu == "visionos_sim_arm64" or
ctx.attr.cpu == "visionos_x86_64" or
ctx.attr.cpu == "watchos_i386" or
ctx.attr.cpu == "watchos_x86_64" or
ctx.attr.cpu == "watchos_arm64"):
Expand Down Expand Up @@ -1416,6 +1427,9 @@ def _impl(ctx):
ctx.attr.cpu == "tvos_arm64" or
ctx.attr.cpu == "tvos_x86_64" or
ctx.attr.cpu == "tvos_sim_arm64" or
ctx.attr.cpu == "visionos_arm64" or
ctx.attr.cpu == "visionos_x86_64" or
ctx.attr.cpu == "visionos_sim_arm64" or
ctx.attr.cpu == "watchos_arm64_32" or
ctx.attr.cpu == "watchos_armv7k" or
ctx.attr.cpu == "watchos_i386" or
Expand Down
1 change: 1 addition & 0 deletions lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ objc_library(
"@platforms//os:ios": [],
"@platforms//os:macos": [],
"@platforms//os:tvos": [],
"@platforms//os:visionos": [],
"@platforms//os:watchos": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
Expand Down
30 changes: 30 additions & 0 deletions test/binary_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,33 @@ def binary_test_suite(name):
verifier_script = "//test/shell:verify_binary.sh",
target_under_test = "//test/test_data:apple_binary",
)

apple_verification_test(
name = "{}_visionos_device_test".format(name),
tags = [name],
build_type = "device",
cpus = {"visionos_cpus": "arm64"},
expected_platform_type = "visionos",
verifier_script = "//test/shell:verify_binary.sh",
target_under_test = "//test/test_data:visionos_binary",
)

apple_verification_test(
name = "{}_visionos_arm64_simulator_test".format(name),
tags = [name],
build_type = "simulator",
cpus = {"visionos_cpus": "sim_arm64"},
expected_platform_type = "visionos",
verifier_script = "//test/shell:verify_binary.sh",
target_under_test = "//test/test_data:visionos_binary",
)

apple_verification_test(
name = "{}_visionos_x86_64_simulator_test".format(name),
tags = [name],
build_type = "simulator",
cpus = {"visionos_cpus": "x86_64"},
expected_platform_type = "visionos",
verifier_script = "//test/shell:verify_binary.sh",
target_under_test = "//test/test_data:visionos_binary",
)
4 changes: 4 additions & 0 deletions test/shell/verify_binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ if [[ "$PLATFORM_TYPE" == "ios" && "$BUILD_TYPE" == "device" ]]; then
expected_platform="IPHONEOS"
elif [[ "$PLATFORM_TYPE" == "ios" && "$BUILD_TYPE" == "simulator" ]]; then
expected_platform="IPHONESIMULATOR"
elif [[ "$PLATFORM_TYPE" == "visionos" && "$BUILD_TYPE" == "device" ]]; then
expected_platform="XROS"
elif [[ "$PLATFORM_TYPE" == "visionos" && "$BUILD_TYPE" == "simulator" ]]; then
expected_platform="XROSSIMULATOR"
fi

otool_output=$(otool -lv "$binary")
Expand Down
27 changes: 27 additions & 0 deletions test/test_data/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,30 @@ starlark_apple_binary(
tags = TARGETS_UNDER_TEST_TAGS,
deps = [":cc_main"],
)

cc_library(
name = "cc_lib",
srcs = ["lib.cc"],
tags = TARGETS_UNDER_TEST_TAGS,
)

objc_library(
name = "objc_lib",
srcs = ["lib.m"],
tags = TARGETS_UNDER_TEST_TAGS,
deps = ["cc_lib"],
)

objc_library(
name = "objc_main",
srcs = ["main.m"],
tags = TARGETS_UNDER_TEST_TAGS,
deps = ["objc_lib"],
)

starlark_apple_binary(
name = "visionos_binary",
platform_type = "visionos",
tags = TARGETS_UNDER_TEST_TAGS,
deps = [":objc_main"],
)
3 changes: 3 additions & 0 deletions test/test_data/lib.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int cc_function() {
return 2;
}
3 changes: 3 additions & 0 deletions test/test_data/lib.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int objc_function() {
return 1;
}
3 changes: 3 additions & 0 deletions test/test_data/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main() {
return 42;
}

0 comments on commit fa7fb2a

Please sign in to comment.