Skip to content

bazel: Add custom rule to produce android debug info#2047

Merged
keith merged 2 commits intomainfrom
ks/bazel-add-custom-rule-to-produce-android-debug-info
Feb 9, 2022
Merged

bazel: Add custom rule to produce android debug info#2047
keith merged 2 commits intomainfrom
ks/bazel-add-custom-rule-to-produce-android-debug-info

Conversation

@keith
Copy link
Member

@keith keith commented Feb 9, 2022

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 Add support for fission on 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

keith added 2 commits February 9, 2022 13:39
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 ignores #2 but fixes #3 so it requires you to explicitly
build the library as part of the command line invocation if you want
debug info, like:

```
./bazelw build --fat_apk_cpu=... android_dist //library/common/jni:libenvoy_jni.so.debug_info
```

Theoretically we could probably shove this artifact into the aar to make
sure it was correctly produced, but that risks us accidentally shipping
that in the aar.

Signed-off-by: Keith Smiley <keithbsmiley@gmail.com>
Signed-off-by: Keith Smiley <keithbsmiley@gmail.com>
@keith keith marked this pull request as ready for review February 9, 2022 22:05
Copy link
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

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

Thanks!

@keith keith merged commit d7ff393 into main Feb 9, 2022
@keith keith deleted the ks/bazel-add-custom-rule-to-produce-android-debug-info branch February 9, 2022 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants