Benefits
Bazel offers the following advantages:- High-level build language. Bazel uses an abstract, human-readable language to describe the build properties of your project at a high semantical level. Unlike other tools, Bazel operates on the concepts of libraries, binaries, scripts, and data sets, shielding you from the complexity of writing individual calls to tools such as compilers and linkers.
- Bazel is fast and reliable. Bazel caches all previously done work and tracks changes to both file content and build commands. This way, Bazel knows when something needs to be rebuilt, and rebuilds only that. To further speed up your builds, you can set up your project to build in a highly parallel and incremental fashion.
- Bazel is multi-platform. Bazel runs on Linux, macOS, and Windows. Bazel can build binaries and deployable packages for multiple platforms, including desktop, server, and mobile, from the same project.
- Bazel scales. Bazel maintains agility while handling builds with 100k+ source files. It works with multiple repositories and user bases in the tens of thousands.
- Bazel is extensible. Many languages are supported, and you can extend Bazel to support any other language or framework.
Using Bazel
To build or test a project with Bazel, you typically do the following:- Set up Bazel. Download and install Bazel.
-
Set up a project workspace, which is a
directory where Bazel looks for build inputs and
BUILDfiles, and where it stores build outputs. -
Write a
BUILDfile, which tells Bazel what to build and how to build it. You write yourBUILDfile by declaring build targets using Starlark, a domain-specific language. (See example here.) A build target specifies a set of input artifacts that Bazel will build plus their dependencies, the build rule Bazel will use to build it, and options that configure the build rule. A build rule specifies the build tools Bazel will use, such as compilers and linkers, and their configurations. Bazel ships with a number of build rules covering the most common artifact types in the supported languages on supported platforms. - Run Bazel from the command line. Bazel places your outputs within the workspace.
Bazel build process
When running a build or a test, Bazel does the following:-
Loads the
BUILDfiles relevant to the target. - Analyzes the inputs and their dependencies, applies the specified build rules, and produces an action graph.
- Executes the build actions on the inputs until the final build outputs are produced.