|
1
|
+
|
|
2
|
+.. _bazel-builds:
|
|
3
|
+
|
|
4
|
+Bazel builds
|
|
5
|
+============
|
|
6
|
+
|
|
7
|
+`Bazel`_ is a *“fast, scalable, multi-language and extensible build system”*
|
|
8
|
+that supports remote build execution using the remote execution API (REAPI) v2
|
|
9
|
+since its `0.17 release`_.
|
|
10
|
+
|
|
11
|
+.. _Bazel: https://bazel.build
|
|
12
|
+.. _0.17 release: https://blog.bazel.build/2018/09/14/bazel-0.17.html
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+.. _bazel-configuration:
|
|
16
|
+
|
|
17
|
+Configuration
|
|
18
|
+-------------
|
|
19
|
+
|
|
20
|
+Bazel accepts many options that can either be specified as command line
|
|
21
|
+arguments when involking the ``bazel`` tool or stored in a `.bazelrc`_
|
|
22
|
+configuration file. In order to activate remote build execution, the
|
|
23
|
+``bazel build`` subcommand needs to be given specific `build options`_,
|
|
24
|
+including:
|
|
25
|
+
|
|
26
|
+- ``--remote_executor``: remote execution endpoint's location, ``{host}:{port}``.
|
|
27
|
+- ``--remote_instance_name``: remote execution instance's name.
|
|
28
|
+- ``--spawn_strategy``: action execution method.
|
|
29
|
+- ``--genrule_strategy``: `genrules`_ execution method.
|
|
30
|
+
|
|
31
|
+Spawn and genrule strategies need to be set to ``remote`` for remote execution.
|
|
32
|
+
|
|
33
|
+As an example, in order to activate remote execution on the ``main`` instance of
|
|
34
|
+the remote execution server available at ``controller.grid.build`` on port
|
|
35
|
+``50051`` you should amend your ``.bazelrc`` with:
|
|
36
|
+
|
|
37
|
+.. code-block:: sh
|
|
38
|
+
|
|
39
|
+ build --spawn_strategy=remote --genrule_strategy=remote --remote_executor=controller.grid.build:50051 --remote_instance_name=main
|
|
40
|
+
|
|
41
|
+.. _.bazelrc: https://docs.bazel.build/versions/master/user-manual.html#bazelrc
|
|
42
|
+.. _build options: https://docs.bazel.build/versions/master/command-line-reference.html#build-options
|
|
43
|
+.. _genrules: https://docs.bazel.build/versions/master/be/general.html#genrule
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+.. _bazel-example:
|
|
47
|
+
|
|
48
|
+Example build
|
|
49
|
+-------------
|
|
50
|
+
|
|
51
|
+The `bazel-examples`_ repository contains example Bazel workspaces that can be
|
|
52
|
+used for testing purpose. We'll focus here on instructions on how to build the
|
|
53
|
+`stage3 CPP example`_ running Bazel and BuildGrid on your local machine,
|
|
54
|
+compiling the C++ source code using host-tools.
|
|
55
|
+
|
|
56
|
+First, you need to checkout the bazel-examples repository sources:
|
|
57
|
+
|
|
58
|
+.. code-block:: sh
|
|
59
|
+
|
|
60
|
+ git clone https://github.com/bazelbuild/examples.git bazel-examples
|
|
61
|
+
|
|
62
|
+Next, change the current directory to the Bazel workspace root:
|
|
63
|
+
|
|
64
|
+.. code-block:: sh
|
|
65
|
+
|
|
66
|
+ cd bazel-examples/cpp-tutorial/stage3
|
|
67
|
+
|
|
68
|
+.. note::
|
|
69
|
+
|
|
70
|
+ All the commands in the instructions below are expected to be executed from
|
|
71
|
+ that root directory (the stage3 example workspace's root directory).
|
|
72
|
+
|
|
73
|
+Before running Bazel and building the example workspace, you'll have to setup
|
|
74
|
+and run a BuildGrid server and bot. A minimal server's configuration is given
|
|
75
|
+below, paste it in a ``server.conf`` file in the root directory:
|
|
76
|
+
|
|
77
|
+.. literalinclude:: ./data/bazel-example-server.conf
|
|
78
|
+ :language: yaml
|
|
79
|
+
|
|
80
|
+This defines a single ``main`` server instance implementing a
|
|
81
|
+``ContentAddressableStorage`` (CAS) + ``ByteStream`` service together with an
|
|
82
|
+``Execution`` + ``ActionCache`` service, both using the same in-memory storage.
|
|
83
|
+You can then start the BuildGrid server deamon using that configuration by
|
|
84
|
+running:
|
|
85
|
+
|
|
86
|
+.. code-block:: sh
|
|
87
|
+
|
|
88
|
+ bgd server start server.conf
|
|
89
|
+
|
|
90
|
+In order to perform the actual build work, you need to attach a worker bot to
|
|
91
|
+that server for that ``main`` instance. A simple host-tools based bot should be
|
|
92
|
+enough to build the stage3 CPP example. Once you've make sure that your machine
|
|
93
|
+has ``gcc`` installed, run:
|
|
94
|
+
|
|
95
|
+.. code-block:: sh
|
|
96
|
+
|
|
97
|
+ bgd bot --remote=http://localhost:50051 --parent=main temp-directory
|
|
98
|
+
|
|
99
|
+The ``--remote`` option is used to specify the server location (running on the
|
|
100
|
+same machine here, and listenning to port 50051). The ``--parent`` option is
|
|
101
|
+used to specifiy the server instance you except the bot to be attached to.
|
|
102
|
+
|
|
103
|
+The BuildGrid server is now ready to accept jobs and execute them. Bazel needs
|
|
104
|
+some :ref:`configuration <bazel-configuration>` in order to run remote builds.
|
|
105
|
+Below are the minimal build options you should use, paste them in a ``.bazelrc``
|
|
106
|
+file in the root directory:
|
|
107
|
+
|
|
108
|
+.. code-block:: sh
|
|
109
|
+
|
|
110
|
+ build --spawn_strategy=remote --genrule_strategy=remote --remote_executor=localhost:50051 --remote_instance_name=main
|
|
111
|
+
|
|
112
|
+This ativates Bazel's remote execution mode and points to the ``main`` remote
|
|
113
|
+execution server instance at ``localhost:50051``.
|
|
114
|
+
|
|
115
|
+You can finally have Bazel to build the example workspace by running:
|
|
116
|
+
|
|
117
|
+.. code-block:: sh
|
|
118
|
+
|
|
119
|
+ bazel build //main:hello-world
|
|
120
|
+
|
|
121
|
+You can verify that the example has been successfully build by runnig the
|
|
122
|
+generated executable. Simply invoke:
|
|
123
|
+
|
|
124
|
+.. code-block:: sh
|
|
125
|
+
|
|
126
|
+ ./bazel-bin/main/hello-world
|
|
127
|
+
|
|
128
|
+.. _bazel-examples: https://github.com/bazelbuild/examples
|
|
129
|
+.. _stage3 CPP example: https://github.com/bazelbuild/examples/tree/master/cpp-tutorial/stage3
|