| 1 |
# Regenerating project files |
| 2 |
|
| 3 |
Prerequisites |
| 4 |
- `python` |
| 5 |
- `pip install mako` (the template processor) |
| 6 |
- `pip install pyyaml` (to read the yaml files) |
| 7 |
- `go` (required by boringssl dependency) |
| 8 |
|
| 9 |
``` |
| 10 |
# Regenerate the projects files (and other generated files) using templates |
| 11 |
tools/buildgen/generate_projects.sh |
| 12 |
``` |
| 13 |
|
| 14 |
# Quick justification |
| 15 |
|
| 16 |
We've approached the problem of the build system from a lot of different |
| 17 |
angles. The main issue was that there isn't a single build system that |
| 18 |
was going to single handedly cover all of our usage cases. |
| 19 |
|
| 20 |
So instead we decided to work the following way: |
| 21 |
|
| 22 |
* A `build.yaml` file at the root is the source of truth for listing all the |
| 23 |
targets and files needed to build grpc and its tests, as well as a basic system |
| 24 |
for dependency description. |
| 25 |
|
| 26 |
* Most of the build systems supported by gRPC (e.g. Makefile, cmake, XCode) have a template defined in this directory. The templates use the information from the `build.yaml` file to generate the project files specific to a given build system. |
| 27 |
|
| 28 |
This way we can maintain as many project system as we see fit, without having |
| 29 |
to manually maintain them when we add or remove new code to the repository. |
| 30 |
Only the structure of the project file is relevant to the template. The actual |
| 31 |
list of source code and targets isn't. |
| 32 |
|
| 33 |
# Structure of `build.yaml` |
| 34 |
|
| 35 |
The `build.yaml` file has the following structure: |
| 36 |
|
| 37 |
``` |
| 38 |
settings: # global settings, such as version number |
| 39 |
... |
| 40 |
filegroups: # groups of files that are automatically expanded |
| 41 |
... |
| 42 |
libs: # list of libraries to build |
| 43 |
... |
| 44 |
targets: # list of targets to build |
| 45 |
... |
| 46 |
``` |
| 47 |
|
| 48 |
The `filegroups` are helpful to re-use a subset of files in multiple targets. |
| 49 |
One `filegroups` entry has the following structure: |
| 50 |
|
| 51 |
``` |
| 52 |
- name: "arbitrary string", # the name of the filegroup |
| 53 |
public_headers: # list of public headers defined in that filegroup |
| 54 |
- ... |
| 55 |
headers: # list of headers defined in that filegroup |
| 56 |
- ... |
| 57 |
src: # list of source files defined in that filegroup |
| 58 |
- ... |
| 59 |
``` |
| 60 |
|
| 61 |
The `libs` collection contains the list of all the libraries we describe. Some may be |
| 62 |
helper libraries for the tests. Some may be installable libraries. Some may be |
| 63 |
helper libraries for installable binaries. |
| 64 |
|
| 65 |
The `targets` array contains the list of all the binary targets we describe. Some may |
| 66 |
be installable binaries. |
| 67 |
|
| 68 |
One `libs` or `targets` entry has the following structure (see below for |
| 69 |
details): |
| 70 |
|
| 71 |
``` |
| 72 |
name: "arbitrary string", # the name of the library |
| 73 |
build: "build type", # in which situation we want that library to be |
| 74 |
# built and potentially installed (see below). |
| 75 |
language: "...", # the language tag; "c" or "c++" |
| 76 |
public_headers: # list of public headers to install |
| 77 |
headers: # list of headers used by that target |
| 78 |
src: # list of files to compile |
| 79 |
baselib: boolean, # this is a low level library that has system |
| 80 |
# dependencies |
| 81 |
filegroups: # list of filegroups to merge to that project |
| 82 |
# note that this will be expanded automatically |
| 83 |
deps: # list of libraries this target depends on |
| 84 |
dll: "..." # see below. |
| 85 |
``` |
| 86 |
|
| 87 |
## The `"build"` tag |
| 88 |
|
| 89 |
Currently, the "`build`" tag have these meanings: |
| 90 |
|
| 91 |
* `"all"`: library to build on `"make all"`, and install on the system. |
| 92 |
* `"protoc"`: a protoc plugin to build on `"make all"` and install on the system. |
| 93 |
* `"private"`: a library to only build for tests. |
| 94 |
* `"test"`: a test binary to run on `"make test"`. |
| 95 |
* `"tool"`: a binary to be built upon `"make tools"`. |
| 96 |
|
| 97 |
All of the targets should always be present in the generated project file, if |
| 98 |
possible and applicable. But the build tag is what should group the targets |
| 99 |
together in a single build command. |
| 100 |
|
| 101 |
## The `"baselib"` boolean |
| 102 |
|
| 103 |
This means this is a library that will provide most of the features for gRPC. |
| 104 |
In particular, if we're locally building OpenSSL, protobuf or zlib, then we |
| 105 |
should merge OpenSSL, protobuf or zlib inside that library. That effect depends |
| 106 |
on the `"language"` tag. OpenSSL and zlib are for `"c"` libraries, while |
| 107 |
protobuf is for `"c++"` ones. |
| 108 |
|
| 109 |
# The template system |
| 110 |
|
| 111 |
We're currently using the [mako templates](http://www.makotemplates.org/) |
| 112 |
renderer. That choice enables us to simply render text files without dragging |
| 113 |
with us a lot of other features. Feel free to explore the current templates |
| 114 |
in that directory. |
| 115 |
|
| 116 |
## The renderer engine |
| 117 |
|
| 118 |
As mentioned, the renderer is using [mako templates](http://www.makotemplates.org/), |
| 119 |
but some glue is needed to process all of that. See the [buildgen folder](../tools/buildgen) |
| 120 |
for more details. We're mainly loading the build.json file, and massaging it, |
| 121 |
in order to get the list of properties we need, into a Python dictionary, that |
| 122 |
is then passed to the template while rending it. |
| 123 |
|
| 124 |
## The plugins |
| 125 |
|
| 126 |
The file build.json itself isn't passed straight to the template files. It is |
| 127 |
first processed and modified by a few plugins. For example, the version |
| 128 |
expander is [a plugin](../tools/buildgen/plugins/expand_version.py). |
| 129 |
|
| 130 |
The structure of a plugin is simple. The plugin must defined the function |
| 131 |
`mako_plugin` that takes a Python dictionary. That dictionary represents the |
| 132 |
current state of the build.json contents. The plugin can alter it to whatever |
| 133 |
feature it needs to add. |