-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bazel: Add custom rule to produce android debug info (#2047)
When building the jni dylib for android, we previously stripped all debug info to decrease the artifact size. With this change we now produce the same stripped binary as before, but before stripping it we create a dump of the debug info suitable for crash reporting. This is made overly difficult for a few reasons: 1. Bazel doesn't support fission for Android bazelbuild/bazel#14765 2. Extra outputs from rules are not propagated up the dependency tree, so just building `android_dist` at the top level, isn't enough to get the extra outputs built as well 3. Building the library manually alongside the android artifact on the command line results in 2 separate builds, one for android as a transitive dependency of `android_dist` and one for the host platform This change avoids #1 fission for now, but the same approach could be used once that change makes its way to a bazel release. This change fixes #2 by using a separate output group that can be depended on by the genrule that writes to dist while avoiding #3 because the custom rule producing these uses the android transition. Signed-off-by: Keith Smiley <keithbsmiley@gmail.com> Signed-off-by: JP Simard <jp@jpsim.com>
- Loading branch information
Showing
7 changed files
with
81 additions
and
3 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
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 @@ | ||
""" | ||
Rule to create objdump debug info from a native dynamic library built for | ||
Android. | ||
This is a workaround for generally not being able to produce dwp files for | ||
Android https://github.com/bazelbuild/bazel/pull/14765 | ||
But even if we could create those we'd need to get them out of the build | ||
somehow, this rule provides a separate --output_group for this | ||
""" | ||
|
||
def _impl(ctx): | ||
library_outputs = [] | ||
objdump_outputs = [] | ||
for platform, dep in ctx.split_attr.dep.items(): | ||
# When --fat_apk_cpu isn't set, the platform is None | ||
if len(dep.files.to_list()) != 1: | ||
fail("Expected exactly one file in the library") | ||
|
||
cc_toolchain = ctx.split_attr._cc_toolchain[platform][cc_common.CcToolchainInfo] | ||
lib = dep.files.to_list()[0] | ||
platform_name = platform or ctx.fragments.android.android_cpu | ||
objdump_output = ctx.actions.declare_file(platform_name + "/" + platform_name + ".objdump") | ||
|
||
ctx.actions.run_shell( | ||
inputs = [lib], | ||
outputs = [objdump_output], | ||
command = cc_toolchain.objdump_executable + " --dwarf=info --dwarf=rawline " + lib.path + ">" + objdump_output.path, | ||
tools = [cc_toolchain.all_files], | ||
) | ||
|
||
strip_output = ctx.actions.declare_file(platform_name + "/" + lib.basename) | ||
ctx.actions.run_shell( | ||
inputs = [lib], | ||
outputs = [strip_output], | ||
command = cc_toolchain.strip_executable + " --strip-debug " + lib.path + " -o " + strip_output.path, | ||
tools = [cc_toolchain.all_files], | ||
) | ||
|
||
library_outputs.append(strip_output) | ||
objdump_outputs.append(objdump_output) | ||
|
||
return [ | ||
DefaultInfo(files = depset(library_outputs)), | ||
OutputGroupInfo(objdump = objdump_outputs), | ||
] | ||
|
||
android_debug_info = rule( | ||
implementation = _impl, | ||
attrs = dict( | ||
dep = attr.label( | ||
providers = [CcInfo], | ||
cfg = android_common.multi_cpu_configuration, | ||
), | ||
_cc_toolchain = attr.label( | ||
default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"), | ||
cfg = android_common.multi_cpu_configuration, | ||
), | ||
), | ||
fragments = ["cpp", "android"], | ||
) |
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