forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build a fat universal binary for java_tools_prebuilt on darwin Work towards: bazelbuild/java_tools#57 and bazelbuild#13944 Closes bazelbuild#16960. PiperOrigin-RevId: 512683379 Change-Id: Ie9db26c729a301fbb22f17dd15065861f3198f57
- Loading branch information
1 parent
7793f7b
commit 570e25f
Showing
3 changed files
with
107 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
""" Defines a rule to package multi-arch binaries for darwin in a single fat binary | ||
Uses the lipo tool as described here: https://developer.apple.com/documentation/apple-silicon/building-a-universal-macos-binary#Update-the-Architecture-List-of-Custom-Makefiles | ||
""" | ||
|
||
def _universal_split_transition_impl(_ctx, _attr): | ||
return { | ||
"x86_64": { | ||
"//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( | ||
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"], | ||
exec_compatible_with = ["@platforms//os:macos"], | ||
) |