@@ -214,8 +214,56 @@ def buildtools_dir():
214214 return '%s-%s' % (host_os, host_cpu)
215215
216216
217+ def setup_rbe(args):
218+ rbe_gn_args = {}
219+ if get_host_os() not in ['linux']:
220+ print('--rbe flag has no effect. RBE is currently only supported on Linux.')
221+ return rbe_gn_args
222+
223+ # When running in CI, the recipes use their own rbe install, and take
224+ # care of starting and stopping the compiler proxy.
225+ running_on_luci = os.environ.get('LUCI_CONTEXT') is not None
226+
227+ cipd_reclient_dir = os.path.join(
228+ SRC_ROOT,
229+ 'buildtools',
230+ buildtools_dir(),
231+ 'reclient',
232+ )
233+
234+ rbe_gn_args['use_rbe'] = args.rbe
235+ if rbe_gn_args['use_rbe'] and sys.platform == 'darwin':
236+ if (not running_on_luci or args.xcode_symlinks or
237+ os.getenv('FLUTTER_GOMA_CREATE_XCODE_SYMLINKS', '0') == '1'):
238+ rbe_gn_args['create_xcode_symlinks'] = True
239+
240+ # Bootstrap reproxy if not running in CI.
241+ if rbe_gn_args['use_rbe'] and not running_on_luci:
242+ bootstrap_path = os.path.join(cipd_reclient_dir, 'bootstrap')
243+ reproxy_path = os.path.join(cipd_reclient_dir, 'reproxy')
244+ rbe_cfg_path = os.path.join(SRC_ROOT, 'build', 'rbe.cfg')
245+ bootstrap_cmd = [
246+ bootstrap_path,
247+ '--re_proxy=' + reproxy_path,
248+ '--automatic_auth=true',
249+ '--cfg=' + rbe_cfg_path,
250+ ]
251+ try:
252+ subprocess.call(bootstrap_cmd, cwd=SRC_ROOT)
253+ except subprocess.CalledProcessError as exc:
254+ print('Failed to boostrap reproxy: ', exc.returncode, exc.output)
255+ return {}
256+
257+ return rbe_gn_args
258+
259+
217260def setup_goma(args):
218261 goma_gn_args = {}
262+ # If RBE is requested, don't try to use goma.
263+ if args.rbe:
264+ goma_gn_args['use_goma'] = False
265+ goma_gn_args['goma_dir'] = None
266+ return goma_gn_args
219267
220268 # args.goma has three states, True (--goma), False (--no-goma), and
221269 # None (default). In True mode, we force GOMA to be used (and fail
@@ -290,6 +338,8 @@ def to_gn_args(args):
290338
291339 gn_args.update(setup_goma(args))
292340
341+ gn_args.update(setup_rbe(args))
342+
293343 # If building for WASM, set the GN args using 'to_gn_wasm_args' as most
294344 # of the Flutter SDK specific arguments are unused.
295345 if args.target_os == 'wasm' or args.web:
@@ -913,6 +963,9 @@ def parse_args(args):
913963 help='Do not build the host-side development artifacts.'
914964 )
915965
966+ parser.add_argument('--rbe', default=None, action='store_true')
967+ parser.add_argument('--no-rbe', dest='rbe', action='store_false')
968+
916969 parser.add_argument('--goma', default=None, action='store_true')
917970 parser.add_argument('--no-goma', dest='goma', action='store_false')
918971 parser.add_argument(
0 commit comments