Simplify Your Bazel Workflow with Bazelisk

yanir manor
3 min readMar 19, 2023

--

Photo by Sivani Bandaru on Unsplash

Introduction

Bazel is a powerful build tool that is used extensively at Google for building large-scale software projects. It is designed to be fast, scalable, and extensible. However, using Bazel can be a bit of a hassle, especially when it comes to managing different versions of Bazel and ensuring that your project works with the correct version of Bazel. This is where Bazelisk comes in.

What is Bazelisk?

Bazelisk is a simple wrapper script for Bazel that is designed to make it easy to use different versions of Bazel. It automatically downloads the correct version of Bazel for your project and ensures that your project always uses the correct version of Bazel, regardless of what version you have installed on your system.

How does Bazelisk work?

Bazelisk works by querying a remote server to determine the latest version of Bazel that is compatible with your project. It then downloads the correct version of Bazel and sets up a symlink to it in your system PATH. This means that you can simply run bazelisk build instead of bazel build, and Bazelisk will take care of the rest.

Why use Bazelisk?

Using Bazelisk has several advantages over using Bazel directly. Firstly, it simplifies the process of managing different versions of Bazel. You no longer need to worry about which version of Bazel you have installed or whether your project is compatible with that version. Bazelisk takes care of all of this for you.

Secondly, Bazelisk ensures that your project always uses the latest version of Bazel that is compatible with your project. This means that you get all of the latest features and bug fixes without having to manually upgrade your version of Bazel.

Finally, Bazelisk makes it easy to switch between different versions of Bazel. If you need to use an older version of Bazel for a particular project, you can simply specify the version number in a configuration file, and Bazelisk will take care of the rest.

How to use Bazelisk?

To use Bazelisk, simply replace the bazel command with bazelisk. For example, to build your project with Bazelisk, you would run:

bazelisk build //path/to:target

This will automatically download the correct version of Bazel for your project and ensure that your project uses the correct version of Bazel. You can also specify the version of Bazel to use by adding a .bazelversion file to the root of your project directory. For example, to use version 3.7.2, you would add the following to your .bazelversion file:

3.7.2

Then, when you run bazelisk build, it will use version 3.7.2 of Bazel instead of the latest version.

Conclusion

Bazelisk is a simple but powerful tool that makes it easy to use Bazel without any of the hassles. It simplifies the process of managing different versions of Bazel, ensures that your project always uses the correct version of Bazel, and makes it easy to switch between different versions of Bazel. If you are using Bazel for your project, I highly recommend giving Bazelisk a try. You won’t be disappointed!

--

--