Tiger Oakes | 95b7b7d | 2018-05-28 15:43:49 | [diff] [blame] | 1 | Name: R8 |
| 2 | URL: https://r8.googlesource.com/r8 |
Mohamed Heikal | 81e19d9 | 2021-09-17 14:50:32 | [diff] [blame] | 3 | Version: unknown |
Tiger Oakes | 95b7b7d | 2018-05-28 15:43:49 | [diff] [blame] | 4 | License: BSD 3-Clause |
Anne Redulla | eae2955c | 2023-07-10 23:45:56 | [diff] [blame] | 5 | License File: LICENSE |
Tiger Oakes | 95b7b7d | 2018-05-28 15:43:49 | [diff] [blame] | 6 | Security Critical: no |
Anne Redulla | eae2955c | 2023-07-10 23:45:56 | [diff] [blame] | 7 | Shipped: no |
Tiger Oakes | 95b7b7d | 2018-05-28 15:43:49 | [diff] [blame] | 8 | |
| 9 | Description: |
Andrew Grieve | 49229008 | 2022-11-15 02:05:32 | [diff] [blame] | 10 | R8 is a whole-program optimizer and dexer. It takes in .class files and outputs |
| 11 | .dex files. |
Andrew Grieve | 723c150 | 2020-04-23 16:27:42 | [diff] [blame] | 12 | |
Andrew Grieve | 49229008 | 2022-11-15 02:05:32 | [diff] [blame] | 13 | Directory overview: |
| 14 | * lib/r8.jar |
| 15 | * The copy of R8 that is used for proguarding. |
| 16 | * Updated daily by an auto-roller. |
| 17 | * d8/lib/r8.jar |
| 18 | * The copy of R8 that is used for dexing. |
| 19 | * Updated manually (and infrequently) in order to avoid having to re-dex all |
| 20 | library targets every day. |
| 21 | * 3pp |
| 22 | * Contains code for 3pp-linux-amd64-packager to package and upload new |
| 23 | versions of r8. |
Andrew Grieve | 49229008 | 2022-11-15 02:05:32 | [diff] [blame] | 24 | * print_version.sh |
| 25 | * Print the R8 commit for the current version.sh. |
Tiger Oakes | 95b7b7d | 2018-05-28 15:43:49 | [diff] [blame] | 26 | |
Eric Stevenson | 70ed356 | 2018-06-26 21:21:46 | [diff] [blame] | 27 | Local Modifications: |
Peter Wen | 3d6eb7ee | 2021-03-03 21:27:45 | [diff] [blame] | 28 | * Refer to commit descriptions within "3pp/patches" directory. |
Andrew Grieve | 1b0b910e | 2020-04-07 01:41:52 | [diff] [blame] | 29 | * Added "playground" directory for quick "how does this optimize" tests. |
Andrew Grieve | 49229008 | 2022-11-15 02:05:32 | [diff] [blame] | 30 | * Added "dump_inputs.py" and "print_version.sh" scripts. |
Peter Wen | 5ef0e3bb | 2021-01-15 19:59:08 | [diff] [blame] | 31 | * Added "java/src/org/chromium/build/CustomD8.java", custom_d8.jar, and BUILD.gn. |
| 32 | * Used in "build/android/gyp/dex.py" to enable desugar dependencies. |
Andrew Grieve | 92f162cf | 2020-03-31 20:32:35 | [diff] [blame] | 33 | |
| 34 | Update Instructions: |
Sam Maier | 276d77b5 | 2023-12-20 22:07:52 | [diff] [blame] | 35 | * For the custom r8/d8 jar: |
| 36 | * This is required only when Custom{R,D}8.java changes. |
Peter Wen | 45443be | 2021-04-08 22:41:26 | [diff] [blame] | 37 | * Uncomment the flag --skip-custom-d8 in internal_rules.gni to avoid depending |
| 38 | on the previously built custom_d8.jar. |
Sam Maier | 276d77b5 | 2023-12-20 22:07:52 | [diff] [blame] | 39 | autoninja -C out/Debug third_party/r8:custom_r8_java |
| 40 | cp out/Debug/obj/third_party/r8/custom_r8_java.javac.jar third_party/r8/custom_r8.jar |
| 41 | OR |
Peter Wen | 5ef0e3bb | 2021-01-15 19:59:08 | [diff] [blame] | 42 | autoninja -C out/Debug third_party/r8:custom_d8_java |
| 43 | cp out/Debug/obj/third_party/r8/custom_d8_java.javac.jar third_party/r8/custom_d8.jar |
| 44 | |
Mohamed Heikal | 81e19d9 | 2021-09-17 14:50:32 | [diff] [blame] | 45 | * For r8: |
Sam Maier | b6c91ba | 2022-05-06 17:11:42 | [diff] [blame] | 46 | * R8 is built daily and uploaded to CIPD. |
Mohamed Heikal | 81e19d9 | 2021-09-17 14:50:32 | [diff] [blame] | 47 | * New instances are uploaded by the packager bot: |
| 48 | https://ci.chromium.org/p/chromium/builders/ci/3pp-linux-amd64-packager |
| 49 | * The bot autoruns every 6 hours. Ping a trooper or a clank build core dev to |
| 50 | trigger it if you need it sooner: |
| 51 | https://luci-scheduler.appspot.com/jobs/chromium/3pp-linux-amd64-packager |
Peter Wen | 9152790 | 2021-11-22 17:12:43 | [diff] [blame] | 52 | * The autoroller runs automatically when a new cipd instance is uploaded. |
| 53 | * Since r8 rolls affect downstream, the roller is only accessible to Googlers. |
| 54 | * See its status here: https://skia-autoroll.corp.goog/r/r8-chromium |
Peter Wen | 3d6eb7ee | 2021-03-03 21:27:45 | [diff] [blame] | 55 | |
| 56 | * If patching fails: |
Andrew Grieve | 92f162cf | 2020-03-31 20:32:35 | [diff] [blame] | 57 | git clone https://r8.googlesource.com/r8 |
| 58 | cd r8 |
Sam Maier | 76dc7a0 | 2022-06-30 19:44:53 | [diff] [blame] | 59 | * Pull the latest code: |
| 60 | git pull |
Peter Wen | 3d6eb7ee | 2021-03-03 21:27:45 | [diff] [blame] | 61 | * Apply patches: |
Andrew Grieve | 1762aee | 2020-08-24 16:17:54 | [diff] [blame] | 62 | git checkout -b my_branch |
Peter Wen | 4981aa9 | 2021-04-27 14:20:47 | [diff] [blame] | 63 | git am $CHROMIUM_SRC/third_party/r8/3pp/patches/*.patch |
Peter Wen | 3d6eb7ee | 2021-03-03 21:27:45 | [diff] [blame] | 64 | * Fix patch conflicts. |
| 65 | * Save new patches. Change number if expecting more or fewer patches: |
Andrew Grieve | 754a0fc0 | 2022-05-30 18:52:15 | [diff] [blame] | 66 | rm $CHROMIUM_SRC/third_party/r8/3pp/patches/* |
Andrew Grieve | 08a8ebac | 2021-06-24 15:18:33 | [diff] [blame] | 67 | git format-patch origin/main..HEAD -o $CHROMIUM_SRC/third_party/r8/3pp/patches |
Peter Wen | 3d6eb7ee | 2021-03-03 21:27:45 | [diff] [blame] | 68 | * Submit these fixed patches and the bot will automatically retry. |
| 69 | |
Peter Wen | 4981aa9 | 2021-04-27 14:20:47 | [diff] [blame] | 70 | * Local development (see above for setting up the r8 repo and applying patches): |
Peter Wen | 3d6eb7ee | 2021-03-03 21:27:45 | [diff] [blame] | 71 | * Build |
Andrew Grieve | 92f162cf | 2020-03-31 20:32:35 | [diff] [blame] | 72 | tools/gradle.py r8 |
Peter Wen | 3d6eb7ee | 2021-03-03 21:27:45 | [diff] [blame] | 73 | * Shrink (improves r8/d8 launch time): |
Andrew Grieve | 92f162cf | 2020-03-31 20:32:35 | [diff] [blame] | 74 | java -jar build/libs/r8.jar --debug --classfile --output r8.jar \ |
| 75 | --lib $CHROMIUM_SRC/third_party/jdk/current --pg-conf src/main/keep.txt \ |
| 76 | --no-minification --no-desugaring build/libs/r8.jar |
Andrew Grieve | 089792f | 2020-10-27 17:49:44 | [diff] [blame] | 77 | mv $CHROMIUM_SRC/third_party/r8/lib/r8.jar{,.bak} |
Sam Maier | baa502f0 | 2020-05-21 14:27:57 | [diff] [blame] | 78 | cp r8.jar $CHROMIUM_SRC/third_party/r8/lib/r8.jar |
| 79 | |
Andrew Grieve | 605f1fbf | 2022-12-06 20:55:12 | [diff] [blame] | 80 | * Update backported methods list (used by lint): |
Mohamed Heikal | 7e123405 | 2020-11-17 16:14:47 | [diff] [blame] | 81 | cd $CHROMIUM_SRC |
Andrew Grieve | 605f1fbf | 2022-12-06 20:55:12 | [diff] [blame] | 82 | java -cp third_party/r8/lib/r8.jar com.android.tools.r8.BackportedMethodList --min-api 24 > third_party/r8/backported_methods.txt |
Andrew Grieve | 9a65844 | 2020-10-02 19:38:44 | [diff] [blame] | 83 | |
Andrew Grieve | be24d57 | 2020-12-04 20:58:55 | [diff] [blame] | 84 | How to file bugs against R8: |
| 85 | * Copy & paste the failing ninja command (starts with proguard.py), and add --dump-inputs. |
Peter Wen | 22ce1b0 | 2023-11-15 19:59:30 | [diff] [blame] | 86 | * On siso you may need to find it at the beginning of `out/<Directory>/siso_output`. |
Peter Wen | 5ef1cbd2 | 2021-03-17 22:08:12 | [diff] [blame] | 87 | * This also works for dex.py, it produces d8inputs.zip |
Andrew Grieve | 5262fe0 | 2022-06-24 02:55:43 | [diff] [blame] | 88 | * As a shortcut: third_party/r8/dump_inputs.py out/Release/apks/ChromePublic.apk.mapping |
Andrew Grieve | be24d57 | 2020-12-04 20:58:55 | [diff] [blame] | 89 | * File bug at go/r8bug |
| 90 | * Things to include (use discretion if some are not relevant): |
| 91 | * src revision bug reproduces at |
| 92 | * Repro steps (gn gen & autoninja commands) |
| 93 | * Prefer enable_chrome_android_internal=false |
| 94 | * The r8inputs.zip from --dump-inputs |
| 95 | * Any relevant dexdump analysis |
Peter Wen | 5ef1cbd2 | 2021-03-17 22:08:12 | [diff] [blame] | 96 | |
Mohamed Heikal | fdaecf12 | 2022-09-30 17:32:28 | [diff] [blame] | 97 | Example R8 git-bisect script: |
| 98 | ``` |
| 99 | set -x |
| 100 | CHROMIUM_SRC=/media/mheikal/code/clankium/src |
| 101 | tools/gradle.py r8 || exit -1 |
| 102 | chmod +r $CHROMIUM_SRC/third_party/r8/lib/r8.jar |
| 103 | rm -f $CHROMIUM_SRC/third_party/r8/lib/r8.jar |
| 104 | cp build/libs/r8.jar $CHROMIUM_SRC/third_party/r8/lib/r8.jar |
| 105 | |
| 106 | cd $CHROMIUM_SRC |
| 107 | exec tools/autotest.py --out-dir out/Release <Test Here> |
| 108 | ``` |
| 109 | |
| 110 | You can run this script like so: |
| 111 | ``` |
| 112 | cd $R8_REPO |
| 113 | git bisect start <known_good_rev> <known_bad_rev> |
| 114 | git bisect run <path_to_script.sh> |
| 115 | ``` |
| 116 | Tip: When you are done, you can delete the r8 jar and gclient sync to get back |
| 117 | to ToT R8. |
| 118 | `rm -f $CHROMIUM_SRC/third_party/r8/lib/r8.jar && gclient sync` |
| 119 | |
Peter Wen | 5ef1cbd2 | 2021-03-17 22:08:12 | [diff] [blame] | 120 | How to submit CLs to R8: |
| 121 | * Request to be added to their allowlist in order to upload CLs. |
| 122 | * After CLs are submitted, check the bots for build breakage. |
| 123 | * https://ci.chromium.org/p/r8/g/main_all/console |