forked from facebook/buck2-prelude
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apple_universal_binaries.bzl
66 lines (56 loc) · 3.02 KB
/
apple_universal_binaries.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
load("@prelude//:artifact_tset.bzl", "make_artifact_tset")
load("@prelude//apple:apple_toolchain_types.bzl", "AppleToolchainInfo")
load(":apple_bundle_types.bzl", "AppleBundleBinaryOutput")
load(":apple_toolchain_types.bzl", "AppleToolsInfo")
load(":debug.bzl", "AppleDebuggableInfo")
def create_universal_binary(
ctx: AnalysisContext,
binary_deps: dict[str, Dependency],
binary_name: [str, None],
dsym_bundle_name: [str, None],
split_arch_dsym: bool) -> AppleBundleBinaryOutput:
binary_output = ctx.actions.declare_output("UniversalBinary" if binary_name == None else binary_name, dir = False)
lipo_cmd = [ctx.attrs._apple_toolchain[AppleToolchainInfo].lipo]
for (_, binary) in binary_deps.items():
lipo_cmd.append(cmd_args(binary[DefaultInfo].default_outputs[0]))
lipo_cmd.extend(["-create", "-output", binary_output.as_output()])
ctx.actions.run(cmd_args(lipo_cmd), category = "lipo")
# Universal binaries can be created out of plain `cxx_binary()` / `cxx_library()`
# which lack the `AppleDebuggableInfo` provider.
# TODO(T174234334): Uniformly support debuggable info for apple_*/cxx_*
contains_full_debuggable_info = _all_binaries_have_apple_debuggable_info(binary_deps)
dsym_output = None
if split_arch_dsym and contains_full_debuggable_info:
dsym_output = ctx.actions.declare_output("UniversalBinary.dSYM" if dsym_bundle_name == None else dsym_bundle_name, dir = True)
dsym_combine_cmd = [ctx.attrs._apple_tools[AppleToolsInfo].split_arch_combine_dsym_bundles_tool]
for (arch, binary) in binary_deps.items():
dsym_combine_cmd.extend(["--dsym-bundle", cmd_args(binary.get(AppleDebuggableInfo).dsyms[0]), "--arch", arch])
dsym_combine_cmd.extend(["--output", dsym_output.as_output()])
ctx.actions.run(cmd_args(dsym_combine_cmd), category = "universal_binaries_dsym")
all_debug_info_tsets = []
if contains_full_debuggable_info:
all_debug_info_tsets = [binary.get(AppleDebuggableInfo).debug_info_tset for binary in binary_deps.values()]
return AppleBundleBinaryOutput(
binary = binary_output,
debuggable_info =
AppleDebuggableInfo(
dsyms = [dsym_output] if dsym_output != None else [],
debug_info_tset = make_artifact_tset(
actions = ctx.actions,
label = ctx.label,
children = filter(None, all_debug_info_tsets),
),
),
)
def _all_binaries_have_apple_debuggable_info(binary_deps: dict[str, Dependency]) -> bool:
for binary in binary_deps.values():
info = binary.get(AppleDebuggableInfo)
if info == None:
return False
return True