Compile your C++ programs with Google's Bazel
Including programs written in Java and other programming languages.
Bazel is an open source tool for building automation and testing software developed by Google .
That is, Bazel is an alternative to Make(from the GNU project) or Ant and Maven, both to compile programs in Java, developed by the company: Apache .
Bazel builds almost all Google products: Google Search, GMail, Google Docs, …
What is the purpose of using Bazel ?
Bazel is designed to work in a standardized way across Google products.
Usually companies tend to create their own solutions for reasons of standardization and it also serves to avoid “free advertising of products from other companies”, even more Google that one of its main sources of revenue is precisely: advertising.
But, you can migrate your projects if you want!
There are several ways you can install it. You can use your operating system’s package manager, examples below:
And among others, for a more complete list see here .
You can also use npm regardless of OS:
The most basic example of all, in this case for C++, would be a project with 3 files:
- Your program:
BUILDfile that would have the macros to be processed
- And an empty file named
WORKSPACE, it serves to indicate the root of the project.
The example content for
main.cpp, a basic Hello, World!:
And the contents of
WORKSPACE empty, to create just use the command:
Now to compile, run:
It will have an output similar to the one below:
To run use the
run parameter followed by the target indicated in
BUILD, in this case we use the binary name
Before printing, the tests and analyzes performed are described. If you want to run only the binary, run:
build it creates some directories inside your project, example based above:
treecommand (if you have it installed) for more details.
More complete examples
The example we show is an “informal” way to create a project to be compiled with Bazel . The correct way can be found in Bazel repository, example:
stage1 directory that has the most basic example and then analyze and test the others, example for
Note the syntax stating that the
BUILDfile is inside the
For more information visit the official page: https://bazel.build/ .