README.md
1# Running Remote Builds with bazel
2
3This allows you to spawn gRPC C/C++ remote build and tests from your workstation with
4configuration that's very similar to what's used by our CI Kokoro.
5
6Note that this will only work for gRPC team members (it requires access to the
7remote build and execution cluster), others will need to rely on local test runs
8and tests run by Kokoro CI.
9
10
11## Prerequisites
12
13- See [Installing Bazel](https://docs.bazel.build/versions/master/install.html) for instructions how to install bazel on your system.
14
15- Setup Application Default Credentials (ADC) for running remote builds by following the ["Set credentials" section](https://developers.google.com/remote-build-execution/docs/set-up/first-remote-build#set_credentials). (Note: make sure that quota project "grpc-testing" was added to your ADC, you can double check the credential file at `${HOME}/.config/gcloud/application_default_credentials.json`)
16
17
18## Running remote build manually from dev workstation
19
20IMPORTANT: The OS from which you run the bazel command needs to always match your desired build & execution platform. If you want to run tests on linux, you need to run bazel from a linux machine, to execute tests on windows you need to be on windows etc. If you don't follow this guideline, the build might still appear like it's working, but you'll get nonsensical results (e.g. will be test configured as if on mac, but actually running on linux).
21
22### Linux
23
24For `opt` or `dbg` run this command:
25```
26# manual run of bazel tests remotely on Foundry
27bazel --bazelrc=tools/remote_build/linux.bazelrc test --config=opt //test/...
28```
29
30This also works for sanitizer runs (`asan`, `msan`, `tsan`, `ubsan`):
31```
32# manual run of bazel tests remotely on Foundry with given sanitizer
33bazel --bazelrc=tools/remote_build/linux.bazelrc test --config=asan //test/...
34```
35
36NOTE: If you see errors about Build Event Protocol upload failure (e.g. `ERROR: The Build Event Protocol upload failed: All retry attempts failed. PERMISSION_DENIED...`), try running `bazel shutdown` and try again.
37
38### Windows
39
40```
41# manual run of bazel tests remotely on RBE Windows (must be run from Windows machine)
42bazel --bazelrc=tools/remote_build/windows.bazelrc test --config=windows_opt //test/...
43```
44
45NOTE: Unlike on Linux and Mac, the bazel version won't get autoselected for you,
46so check that you're using the [right bazel version](https://github.com/grpc/grpc/blob/master/tools/bazel).
47
48### MacOS
49
50There is no such thing as Mac RBE cluster, so a real remote build on Macs is currently impossible.
51The following setup will build and run test on you local mac machine, but will give
52you the RBE-like look & feel (e.g. a results link will be generated and some extra configuration will
53be used).
54
55```
56# manual run of bazel tests on Mac (must be run from Mac machine)
57# NOTE: it's not really a "remote execution", but uploads results to ResultStore
58bazel --bazelrc=tools/remote_build/mac.bazelrc test --config=opt //test/...
59```
60
61NOTE: Because this is essentially a local run, you'll need to run start port server first (`tools/run_tests/start_port_server.py`)
62
63## Running local builds with bazel
64
65On all platforms, you can generally still use bazel builds & tests locally without any extra settings, but you might need to
66start port server first (`tools/run_tests/start_port_server.py`) to be able to run the tests locally.
67
68E.g.: `bazel test --config=opt //test/...`
69
70## Bazel command line options
71
72Available command line options can be found in
73[Bazel command line reference](https://docs.bazel.build/versions/master/command-line-reference.html)
74