Skip to content
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

Add darwin_arm64 java_tools #16960

Closed
wants to merge 8 commits into from
5 changes: 5 additions & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -596,3 +596,8 @@ filegroup(
for version in ("17", "18")
],
)

exports_files(
["darwin_universal_binary.bzl"],
visibility = ["//third_party/ijar:__pkg__"],
)
55 changes: 55 additions & 0 deletions src/darwin_universal_binary.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
def _universal_split_transition_impl(ctx, attr):
return {
"x86_64" : {
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't support platformization, which we'll need to update when we turn it on.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please also set --platforms flag to match the cpu. This then won't cause problems when we flip --incompatible_enable_cc_toolchain_resolution

"//command_line_option:cpu": "darwin_x86_64",
},
"arm64" : {
"//command_line_option:cpu": "darwin_arm64",
}
}

_universal_split_transition = transition(
implementation = _universal_split_transition_impl,
inputs = [],
outputs = ["//command_line_option:cpu"],
)

def _impl(ctx):
binaries = [
attr.files.to_list()[0] for attr in ctx.split_attr.binary.values()
]
out = ctx.actions.declare_file(ctx.label.name + "/" + ctx.attr.output_name)
args = ctx.actions.args()
args.add("-create")
args.add_all(binaries)
args.add("-output", out)
apple_env = {}
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
apple_env.update(apple_common.apple_host_system_env(xcode_config))
apple_env.update(
apple_common.target_apple_env(
xcode_config,
ctx.fragments.apple.multi_arch_platform(apple_common.platform_type.macos),
),
)
ctx.actions.run(
executable = "/usr/bin/lipo",
arguments = [args],
inputs = binaries,
outputs = [out],
execution_requirements = xcode_config.execution_info(),
env = apple_env,
)
return DefaultInfo(executable = out)

darwin_universal_binary = rule(
hvadehra marked this conversation as resolved.
Show resolved Hide resolved
implementation = _impl,
attrs = {
"output_name" : attr.string(),
"binary": attr.label(cfg = _universal_split_transition),
"_xcode_config": attr.label(default = "@bazel_tools//tools/osx:current_xcode_config"),
"_allowlist_function_transition": attr.label(default = "@bazel_tools//tools/allowlists/function_transition_allowlist"),
},
fragments = ["apple"],
hvadehra marked this conversation as resolved.
Show resolved Hide resolved
exec_compatible_with = ["@platforms//os:macos"],
)
17 changes: 16 additions & 1 deletion src/tools/singlejar/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//src:release_archive.bzl", "release_archive")
load("//src:darwin_universal_binary.bzl", "darwin_universal_binary")

# Description:
# singlejar C++ implementation.
Expand Down Expand Up @@ -64,7 +65,7 @@ release_archive(

release_archive(
name = "singlejar_deploy_zip",
srcs = [":singlejar_local"],
srcs = [":singlejar_local_binary_for_deploy"],
package_dir = "java_tools/src/tools/singlejar",
visibility = ["//src:__pkg__"],
)
Expand All @@ -88,6 +89,20 @@ cc_binary(
],
)

alias(
name = "singlejar_local_binary_for_deploy",
actual = select({
"//src/conditions:darwin": ":singlejar_local_darwin",
"//conditions:default": ":singlejar_local",
})
)

darwin_universal_binary(
name = "singlejar_local_darwin",
binary = ":singlejar_local",
output_name = "singlejar_local",
)

cc_binary(
name = "singlejar_local",
srcs = [
Expand Down
23 changes: 19 additions & 4 deletions third_party/ijar/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("//src:darwin_universal_binary.bzl", "darwin_universal_binary")

package(
default_visibility = [
"//src:__subpackages__",
Expand Down Expand Up @@ -76,6 +78,12 @@ cc_binary(
deps = [":zip"],
)

darwin_universal_binary(
name = "zipper_darwin",
binary = ":zipper",
output_name = "zipper",
)

cc_binary(
name = "ijar",
srcs = [
Expand All @@ -86,6 +94,12 @@ cc_binary(
deps = [":zip"],
)

darwin_universal_binary(
name = "ijar_darwin",
binary = ":ijar",
output_name = "ijar",
)

filegroup(
name = "srcs",
srcs = glob(["**"]) + ["//third_party/ijar/test:srcs"],
Expand All @@ -105,6 +119,7 @@ filegroup(
"zlib_client.cc",
"zlib_client.h",
"BUILD",
"//src:darwin_universal_binary.bzl",
] + select({
"//src:windows": [
"mapped_file_windows.cc",
Expand Down Expand Up @@ -137,10 +152,10 @@ genrule(

genrule(
name = "ijar_deploy_zip",
srcs = [
":ijar",
":zipper",
],
srcs = select({
"//src/conditions:darwin": [":ijar_darwin", ":zipper_darwin"],
"//conditions:default": [":ijar",":zipper"],
}),
outs = ["ijar_deploy.zip"],
cmd = "$(location //src:zip_files) java_tools/ijar $@ $(SRCS)",
tools = ["//src:zip_files"],
Expand Down