|
| 1 | +# RBE for Flutter Engine Developers |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This is documentation on setting up RBE for building the Flutter engine. It is |
| 6 | +expected to work for Googlers only on corp Linux, macOS, and Windows hosts, |
| 7 | +including cloudtop instances. |
| 8 | + |
| 9 | +## Getting started |
| 10 | + |
| 11 | +The first step is to add an entry to the `.gclient` file. The entry to add is |
| 12 | +`"use_rbe": True` in the `custom_vars` section. It should look like this: |
| 13 | + |
| 14 | +After making this edit, you must be authenticated as a Googler by CIPD so that |
| 15 | +the RBE configurations can be downloaded from the `flutter_internal` |
| 16 | +[CIPD bucket](https://chrome-infra-packages.appspot.com/p/flutter_internal): |
| 17 | + |
| 18 | +After authentication successfully, run `gclient sync -D`. |
| 19 | + |
| 20 | +## Running an RBE build |
| 21 | + |
| 22 | +In the engine repo, all RBE builds must be initiated through the `et` tool whose |
| 23 | +entrypoint is the script `//flutter/bin/et`. This is so that the local RBE |
| 24 | +proxy is correctly initialized and shut down around invocations of `ninja`. |
| 25 | + |
| 26 | +### gcloud |
| 27 | + |
| 28 | +Before running an RBE build, you must be authenticated with the Google cloud |
| 29 | +project that owns the RBE worker pool. A gcloud SDK is checked out with the |
| 30 | +engine repo under e.g. `//flutter/buildtools/mac-arm64/gcloud`. |
| 31 | +(Replace `mac-arm64` with the directory name that is correct for your host |
| 32 | +platform.) |
| 33 | + |
| 34 | +The `gcloud` tool in this SDK must be on your path. The tool lives under |
| 35 | +`//flutter/buildtools/mac-arm64/gcloud/bin`, which is the path to add to your |
| 36 | +`PATH` environment variable. Alternatively, you can get the gcloud SDK on your |
| 37 | +path by installing it on your system by following the instructions at |
| 38 | +[https://cloud.google.com/sdk/docs/install] |
| 39 | +(https://cloud.google.com/sdk/docs/install). |
| 40 | + |
| 41 | +On macOS, before running the `gcloud` command ensure that `python3` is on your |
| 42 | +path, and does not come from e.g. homebrew. The command `which python3` should |
| 43 | +return `/usr/bin/python3`. |
| 44 | + |
| 45 | +### Listing builds |
| 46 | + |
| 47 | +The builds available to the `et` tool are those specified by the build |
| 48 | +configuration json files under `//flutter/ci/builders`. A list of builds |
| 49 | +suitable for local development can also be printed by running `et help build`. |
| 50 | +The list of all builds can be printed by running `et help build --verbose`. |
| 51 | +Builds in the verbose list prefixed with `ci/` or `ci\` are exactly the builds |
| 52 | +run on CI with the same GN flags and Ninja targets. |
| 53 | + |
| 54 | +### Running builds |
| 55 | + |
| 56 | +To run a build, pass the name of the configuration to the `et build` command: |
| 57 | + |
| 58 | +If RBE is working correctly, you should see logs like the following: |
| 59 | + |
| 60 | +To disable RBE in a build, pass the flag `--no-rbe` to the `build` command. |
| 61 | + |
| 62 | +Since LTO is slow and rarely useful in local builds, `et` disables it by default |
| 63 | +in all builds, even when it is specified by a build configuration. To enable |
| 64 | +it, pass the `--lto` flag to the `build` command. |
| 65 | + |
| 66 | +### Customizing builds |
| 67 | + |
| 68 | +Beyond enabling/disabling RBE and LTO, the `build` command does not currently |
| 69 | +support customizing builds at the command line. |
| 70 | + |
| 71 | +If you need custom GN flags or Ninja targets, then this can be achieved by |
| 72 | +making local edits to the build configuration json files in your checkout. In |
| 73 | +particular, the file `//flutter/ci/builders/local_engine.json` is intended to |
| 74 | +contain builds that are commonly used for local engine development. |
| 75 | + |
| 76 | +If a configuration does not exist there, and will be needed by multiple people |
| 77 | +over a long period of time, consider checking in the new configuration so that |
| 78 | +it will be built on CI, which will keep the RBE cache warm for fast local |
| 79 | +builds. |
| 80 | + |
| 81 | +On the other hand, if a build is intended to produce artifacts or run tests on |
| 82 | +CI, then it should _not_ go in `local_engine.json`. Instead, it should go in |
| 83 | +the json file appropriate for its purpose. There are many examples available, |
| 84 | +so following suit is likely your best bet, but if you are unsure, ask in the |
| 85 | +`hackers-engine` Discord. |
| 86 | + |
| 87 | +## Maintaining Compatibility with RBE |
| 88 | + |
| 89 | +RBE is sensitive to what paths in compile commands look like. In particular, all |
| 90 | +paths in compile commands must be relative paths, and those relative paths must |
| 91 | +all resolve to files within the engine source tree. In practice, this means |
| 92 | +that the GN function `rebase_path()` should only lack a second parameter when |
| 93 | +its result won’t be used in a compile or link command. There are unfortunately |
| 94 | +many examples in the tree where `rebase_path()` lacks a second parameter. |
| 95 | +However to be on the safe side a good rule of thumb is: do not add new usages |
| 96 | +of the single parameter `rebase_path()`. |
| 97 | + |
| 98 | +## Troubleshooting |
| 99 | + |
| 100 | +### Slow builds |
| 101 | + |
| 102 | +RBE builds can be slow for a few different reasons. The most common reason is |
| 103 | +likely to be that the remote caches are cold. When the caches are warm, a |
| 104 | +compile step consists only of downloading the compiled TU from the cache. When |
| 105 | +the caches are cold, the remote workers must run the compilation commands, |
| 106 | +which takes more time. |
| 107 | + |
| 108 | +RBE builds can also be slow if your network connection is bandwidth constrained. |
| 109 | +Anecdotally, even with a warm cache, I have noticed slow builds from home due |
| 110 | +to RBE saturating my low-tier Comcast Business connection. |
| 111 | + |
| 112 | +When RBE builds are slow, non-RBE builds may be faster, especially incremental |
| 113 | +builds. |
| 114 | + |
| 115 | +### Proxy status and debug logs |
| 116 | + |
| 117 | +The status of the local RBE proxy can be queried with the following command |
| 118 | + |
| 119 | +It will give output describing the number of actions completed and in progress, |
| 120 | +and the number of remote executions, local executions, and remote cache hits. |
| 121 | + |
| 122 | +The logs for RBE live under the system `/tmp` folder in the files `/tmp/reproxy. |
| 123 | +{INFO,WARNING,ERROR}` and `/tmp/bootstrap.{INFO,WARNING,ERROR}`. |
| 124 | + |
| 125 | +In CI runs, the RBE logs are also available by following the links as in the |
| 126 | +screenshot below under `teardown remote execution > collect rbe logs`: |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | +### Dependency analysis failures |
| 131 | + |
| 132 | +These logs can be useful to highlight failures in RBE’s dependency analysis. The |
| 133 | +dependency analysis can fail for a variety of reasons, but a common one during |
| 134 | +development is likely to be that the source file is really malformed somehow. |
| 135 | +This can be debugged by doing a local build with RBE turned off. |
| 136 | + |
| 137 | + |
| 138 | +## References |
| 139 | + |
| 140 | +* Code for RBE (i.e. reproxy, rewrapper, bootstrap, etc.) lives in [this GitHub |
| 141 | + repository](https://github.com/bazelbuild/reclient). The tools are not |
| 142 | + well-documented, so the source code is the source of truth for the command |
| 143 | + line flags that they accept, for example. |
| 144 | +* Internal-facing RBE migration guide is [here](go/reclient-migration-guide). |
| 145 | + (Mostly focused on Chrome and Android, so not all parts are relevant to |
| 146 | + Flutter.) |
| 147 | +* The version of RBE for local development is set in the DEPS file [here] |
| 148 | + (https://github.com/flutter/engine/blob/8578edf9c9393471ca9eab18e9154f0e6066dcb6/DEPS#L53). |
| 149 | + It needs to be manually rolled occasionally. |
| 150 | +* The version of RBE used by CI is set in a LUCI recipe [here] |
| 151 | + (https://flutter.googlesource.com/recipes/+/be12675150183af68223f5fbc6e0f888a1139e79/recipe_modules/rbe/api.py#16). |
| 152 | + It also needs to be manually rolled occasionally. |
| 153 | +* Googler-only RBE configuration files live in the CIPD bucket [here] |
| 154 | + (https://chrome-infra-packages.appspot.com/p/flutter_internal/rbe/reclient_cfgs). |
| 155 | + They need to be updated when we roll clang to a new version as described |
| 156 | + [here] |
| 157 | + (https://github.com/flutter/engine/pull/52062#issuecomment-2050902282). |
| 158 | +* Flutter’s RBE worker pool is defined [here] |
| 159 | + (https://source.corp.google.com/piper///depot/google3/configs/cloud/gong/services/flutter_rbe/modules/infra/prod/main.tf). |
| 160 | +* Using RBE for Engine clang-tidy is blocked on [b/326591374] |
| 161 | + (http://b/326591374). |
0 commit comments