build tools

Build With Bazel: An Overview

1224 VIEWS

·

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

Unlike many other build systems, Bazel can support almost any programming language through extension. C++, Objective-C, Shell, Java, Python, Scala, D, JavaScript, and Groovy are well-supported with little to no tweaking required on your part. Bazel can also be used in building Docker images. Bazel’s build speed is achieved by compiling only files that require recompilation. Redundant aspects of the build process can be intelligently skipped altogether. Bazel supports all three major platforms—Linux, Windows, and MacOS.

Installation

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.

More

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.

Conclusion

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.


Bruno is a junior at Ashesi University College studying Computer Science. He is interested in leveraging the power of technology to increase productivity. As a big fan of open source technology, he is currently exploring the possibility of using the Bitcoin Blockchain to fight corruption in government.


Discussion

Click on a tab to select how you'd like to leave your comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Menu