1*cc02d7e2SAndroid Build Coastguard Worker# Running Remote Builds with bazel 2*cc02d7e2SAndroid Build Coastguard Worker 3*cc02d7e2SAndroid Build Coastguard WorkerThis allows you to spawn gRPC C/C++ remote build and tests from your workstation with 4*cc02d7e2SAndroid Build Coastguard Workerconfiguration that's very similar to what's used by our CI Kokoro. 5*cc02d7e2SAndroid Build Coastguard Worker 6*cc02d7e2SAndroid Build Coastguard WorkerNote that this will only work for gRPC team members (it requires access to the 7*cc02d7e2SAndroid Build Coastguard Workerremote build and execution cluster), others will need to rely on local test runs 8*cc02d7e2SAndroid Build Coastguard Workerand tests run by Kokoro CI. 9*cc02d7e2SAndroid Build Coastguard Worker 10*cc02d7e2SAndroid Build Coastguard Worker 11*cc02d7e2SAndroid Build Coastguard Worker## Prerequisites 12*cc02d7e2SAndroid Build Coastguard Worker 13*cc02d7e2SAndroid Build Coastguard Worker- See [Installing Bazel](https://docs.bazel.build/versions/master/install.html) for instructions how to install bazel on your system. 14*cc02d7e2SAndroid Build Coastguard Worker 15*cc02d7e2SAndroid Build Coastguard Worker- 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*cc02d7e2SAndroid Build Coastguard Worker 17*cc02d7e2SAndroid Build Coastguard Worker 18*cc02d7e2SAndroid Build Coastguard Worker## Running remote build manually from dev workstation 19*cc02d7e2SAndroid Build Coastguard Worker 20*cc02d7e2SAndroid Build Coastguard WorkerIMPORTANT: 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*cc02d7e2SAndroid Build Coastguard Worker 22*cc02d7e2SAndroid Build Coastguard Worker### Linux 23*cc02d7e2SAndroid Build Coastguard Worker 24*cc02d7e2SAndroid Build Coastguard WorkerFor `opt` or `dbg` run this command: 25*cc02d7e2SAndroid Build Coastguard Worker``` 26*cc02d7e2SAndroid Build Coastguard Worker# manual run of bazel tests remotely on Foundry 27*cc02d7e2SAndroid Build Coastguard Workerbazel --bazelrc=tools/remote_build/linux.bazelrc test --config=opt //test/... 28*cc02d7e2SAndroid Build Coastguard Worker``` 29*cc02d7e2SAndroid Build Coastguard Worker 30*cc02d7e2SAndroid Build Coastguard WorkerThis also works for sanitizer runs (`asan`, `msan`, `tsan`, `ubsan`): 31*cc02d7e2SAndroid Build Coastguard Worker``` 32*cc02d7e2SAndroid Build Coastguard Worker# manual run of bazel tests remotely on Foundry with given sanitizer 33*cc02d7e2SAndroid Build Coastguard Workerbazel --bazelrc=tools/remote_build/linux.bazelrc test --config=asan //test/... 34*cc02d7e2SAndroid Build Coastguard Worker``` 35*cc02d7e2SAndroid Build Coastguard Worker 36*cc02d7e2SAndroid Build Coastguard WorkerNOTE: 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*cc02d7e2SAndroid Build Coastguard Worker 38*cc02d7e2SAndroid Build Coastguard Worker### Windows 39*cc02d7e2SAndroid Build Coastguard Worker 40*cc02d7e2SAndroid Build Coastguard Worker``` 41*cc02d7e2SAndroid Build Coastguard Worker# manual run of bazel tests remotely on RBE Windows (must be run from Windows machine) 42*cc02d7e2SAndroid Build Coastguard Workerbazel --bazelrc=tools/remote_build/windows.bazelrc test --config=windows_opt //test/... 43*cc02d7e2SAndroid Build Coastguard Worker``` 44*cc02d7e2SAndroid Build Coastguard Worker 45*cc02d7e2SAndroid Build Coastguard WorkerNOTE: Unlike on Linux and Mac, the bazel version won't get autoselected for you, 46*cc02d7e2SAndroid Build Coastguard Workerso check that you're using the [right bazel version](https://github.com/grpc/grpc/blob/master/tools/bazel). 47*cc02d7e2SAndroid Build Coastguard Worker 48*cc02d7e2SAndroid Build Coastguard Worker### MacOS 49*cc02d7e2SAndroid Build Coastguard Worker 50*cc02d7e2SAndroid Build Coastguard WorkerThere is no such thing as Mac RBE cluster, so a real remote build on Macs is currently impossible. 51*cc02d7e2SAndroid Build Coastguard WorkerThe following setup will build and run test on you local mac machine, but will give 52*cc02d7e2SAndroid Build Coastguard Workeryou the RBE-like look & feel (e.g. a results link will be generated and some extra configuration will 53*cc02d7e2SAndroid Build Coastguard Workerbe used). 54*cc02d7e2SAndroid Build Coastguard Worker 55*cc02d7e2SAndroid Build Coastguard Worker``` 56*cc02d7e2SAndroid Build Coastguard Worker# manual run of bazel tests on Mac (must be run from Mac machine) 57*cc02d7e2SAndroid Build Coastguard Worker# NOTE: it's not really a "remote execution", but uploads results to ResultStore 58*cc02d7e2SAndroid Build Coastguard Workerbazel --bazelrc=tools/remote_build/mac.bazelrc test --config=opt //test/... 59*cc02d7e2SAndroid Build Coastguard Worker``` 60*cc02d7e2SAndroid Build Coastguard Worker 61*cc02d7e2SAndroid Build Coastguard WorkerNOTE: Because this is essentially a local run, you'll need to run start port server first (`tools/run_tests/start_port_server.py`) 62*cc02d7e2SAndroid Build Coastguard Worker 63*cc02d7e2SAndroid Build Coastguard Worker## Running local builds with bazel 64*cc02d7e2SAndroid Build Coastguard Worker 65*cc02d7e2SAndroid Build Coastguard WorkerOn all platforms, you can generally still use bazel builds & tests locally without any extra settings, but you might need to 66*cc02d7e2SAndroid Build Coastguard Workerstart port server first (`tools/run_tests/start_port_server.py`) to be able to run the tests locally. 67*cc02d7e2SAndroid Build Coastguard Worker 68*cc02d7e2SAndroid Build Coastguard WorkerE.g.: `bazel test --config=opt //test/...` 69*cc02d7e2SAndroid Build Coastguard Worker 70*cc02d7e2SAndroid Build Coastguard Worker## Bazel command line options 71*cc02d7e2SAndroid Build Coastguard Worker 72*cc02d7e2SAndroid Build Coastguard WorkerAvailable command line options can be found in 73*cc02d7e2SAndroid Build Coastguard Worker[Bazel command line reference](https://docs.bazel.build/versions/master/command-line-reference.html) 74