Skip to content

Commit

Permalink
Add watchos_device_arm64(e) CPUs (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
keith authored Feb 22, 2024
1 parent cd38fb1 commit ae1341f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
14 changes: 14 additions & 0 deletions configs/platforms.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ APPLE_PLATFORMS_CONSTRAINTS = {
"@build_bazel_apple_support//constraints:apple",
"@build_bazel_apple_support//constraints:simulator",
],
"watchos_device_arm64": [
"@platforms//os:watchos",
"@platforms//cpu:arm64",
"@build_bazel_apple_support//constraints:apple",
"@build_bazel_apple_support//constraints:device",
],
"watchos_device_arm64e": [
"@platforms//os:watchos",
"@platforms//cpu:arm64e",
"@build_bazel_apple_support//constraints:apple",
"@build_bazel_apple_support//constraints:device",
],
"watchos_arm64_32": [
"@platforms//os:watchos",
"@platforms//cpu:arm64_32",
Expand Down Expand Up @@ -115,5 +127,7 @@ CPU_TO_DEFAULT_PLATFORM_NAME = {
"watchos_arm64": "watchos_arm64",
"watchos_arm64_32": "watchos_arm64_32",
"watchos_armv7k": "watchos_armv7k",
"watchos_device_arm64": "watchos_device_arm64",
"watchos_device_arm64e": "watchos_device_arm64e",
"watchos_x86_64": "watchos_x86_64",
}
12 changes: 11 additions & 1 deletion crosstool/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ please file an issue at https://github.com/bazelbuild/apple_support/issues/new
elif (ctx.attr.cpu == "watchos_arm64"):
target_system_name = "arm64-apple-watchos{}-simulator".format(target_os_version)
is_simulator = True
elif (ctx.attr.cpu == "watchos_device_arm64"):
target_system_name = "arm64-apple-watchos{}".format(target_os_version)
elif (ctx.attr.cpu == "watchos_device_arm64e"):
target_system_name = "arm64e-apple-watchos{}".format(target_os_version)
elif (ctx.attr.cpu == "darwin_x86_64"):
target_system_name = "x86_64-apple-macosx{}".format(target_os_version)
elif (ctx.attr.cpu == "darwin_arm64"):
Expand Down Expand Up @@ -168,8 +172,10 @@ please file an issue at https://github.com/bazelbuild/apple_support/issues/new
abi_version = "local"

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

all_link_actions = [
ACTION_NAMES.cpp_link_executable,
Expand Down Expand Up @@ -740,6 +746,8 @@ please file an issue at https://github.com/bazelbuild/apple_support/issues/new
ctx.attr.cpu == "ios_sim_arm64" or
ctx.attr.cpu == "ios_x86_64" or
ctx.attr.cpu == "watchos_arm64_32" or
ctx.attr.cpu == "watchos_device_arm64" or
ctx.attr.cpu == "watchos_device_arm64e" or
ctx.attr.cpu == "watchos_armv7k" or
ctx.attr.cpu == "watchos_x86_64" or
ctx.attr.cpu == "watchos_arm64"):
Expand Down Expand Up @@ -1487,6 +1495,8 @@ please file an issue at https://github.com/bazelbuild/apple_support/issues/new
ctx.attr.cpu == "visionos_arm64" or
ctx.attr.cpu == "visionos_sim_arm64" or
ctx.attr.cpu == "watchos_arm64_32" or
ctx.attr.cpu == "watchos_device_arm64" or
ctx.attr.cpu == "watchos_device_arm64e" or
ctx.attr.cpu == "watchos_armv7k" or
ctx.attr.cpu == "watchos_x86_64" or
ctx.attr.cpu == "watchos_arm64"):
Expand Down
15 changes: 15 additions & 0 deletions platform_mappings
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ platforms:
--apple_platform_type=watchos
--cpu=watchos_arm64_32

//platforms:watchos_device_arm64
--apple_platform_type=watchos
--cpu=watchos_device_arm64

//platforms:watchos_device_arm64e
--apple_platform_type=watchos
--cpu=watchos_device_arm64e
flags:
--cpu=darwin_x86_64
--apple_platform_type=macos
Expand Down Expand Up @@ -135,3 +142,11 @@ flags:
--cpu=watchos_arm64_32
--apple_platform_type=watchos
//platforms:watchos_arm64_32

--cpu=watchos_device_arm64
--apple_platform_type=watchos
//platforms:watchos_device_arm64

--cpu=watchos_device_arm64e
--apple_platform_type=watchos
//platforms:watchos_device_arm64e
20 changes: 20 additions & 0 deletions test/binary_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,26 @@ def binary_test_suite(name):
target_under_test = "//test/test_data:watch_binary",
)

apple_verification_test(
name = "{}_watchos_device_arm64_test".format(name),
tags = [name],
build_type = "device",
cpus = {"watchos_cpus": "device_arm64"},
expected_platform_type = "watchos",
verifier_script = "//test/shell:verify_binary.sh",
target_under_test = "//test/test_data:watch_binary",
)

apple_verification_test(
name = "{}_watchos_device_arm64e_test".format(name),
tags = [name],
build_type = "device",
cpus = {"watchos_cpus": "device_arm64e"},
expected_platform_type = "watchos",
verifier_script = "//test/shell:verify_binary.sh",
target_under_test = "//test/test_data:watch_binary",
)

apple_verification_test(
name = "{}_watchos_simulator_test".format(name),
tags = [name],
Expand Down
1 change: 1 addition & 0 deletions test/shell/verify_binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fi
lipo_output=$(lipo -info "$binary")
expected_cpus=${CPU//,/ }
expected_cpus=${expected_cpus//sim_/}
expected_cpus=${expected_cpus//device_/}
if ! echo "$lipo_output" | grep -q "$expected_cpus"; then
echo "error: binary $binary does not contain CPU $CPU, got: '$lipo_output"
exit 1
Expand Down

0 comments on commit ae1341f

Please sign in to comment.