Bazel is one of Google’s 2,000-plus open source projects. Bazel is an open source variant of Google’s in-house build tool with a close name: Blaze. As a tool used by a company with a massive codebase, it handles builds efficiently and has excellent language support. The tool is written in Java. It was open-sourced in early 2015 and is seeing rapid adoption. In this article, I’ll give a general overview of Bazel—a tool for building and testing software.
Build tools are essential in software development, especially in the commercial setting. A key benefit is that they save us a great deal of time and effort, as they help automate repetitive and otherwise tedious tasks. There are numerous build tools available. Some of the popular ones include Make, CMake, Gradle, ANT, Maven, Buildr, Rake, sbt, and SCons. These tools all come with their pros and cons (Bazel included). There are few that satisfy the needs of all developers. For this reason, new tools spring up every now and then, seeking to eliminate the challenges in other tools and meet the evolving needs of developers.
Why Add Another Build Tool?
The Bazel philosophy is to build quickly, correctly, and be reproducible (a set of inputs will always yield the same output). As previously stated, very few tools satisfy the needs of all developers—and in fact, no tool can. Bazel is used extensively by Google. It was designed to handle very large projects. Small projects may not see any additional benefit in build using the tool. Nonetheless, projects using Bazel can benefit in several other ways.
Bazel is Language-Neutral
Initially, Bazel supported only Mac and Linux (Windows support came a little later). For full platform-specific instructions, see the official installation guide. Otherwise, you can download Bazel from the Bazel GitHub releases page.
Ubuntu users need these packages installed as well as the JDK:
sudo apt install pkg-config zip g++ zlib1g-dev unzip python
Once installed, you should have a client server, which you interact with via the command line with the bazel command.
Moving to Bazel requires a little more effort than that usually required of other build tools. It is still worth the move considering the benefits involved in switching. The process is made even simpler because Bazel is exceptionally well-documented. Almost all aspects of Bazel are included in the documentation: migration guide, best practices, API reference, language-specific information, command reference, tests, external dependencies, etc.
Bazel was designed for certain use cases. However, if your project has a large codebase, spans across multiple programming languages, and you deploy on multiple platforms and test extensively, but you want a reliable and fast build tool, you should—seriously—consider Bazel.