Bazel — Fast Scalable Build System for Multi-Language Projects
Bazel is Google's open-source build and test tool that handles multi-language, multi-platform projects at massive scale with hermetic, reproducible builds.
What it is
Bazel is an open-source build and test tool originally developed at Google to manage their monorepo. It builds and tests code across languages like Java, C++, Go, Python, and TypeScript using a unified dependency graph. Builds are hermetic, meaning they produce identical outputs regardless of the host machine.
Bazel is designed for large teams working on multi-language projects. It excels in monorepo setups where thousands of targets depend on each other and incremental builds must be fast and reliable.
How it saves time or tokens
Bazel caches build results at the action level. If a source file has not changed, its compilation step is skipped entirely. Remote caching and remote execution distribute builds across machines, turning hour-long builds into minutes. The dependency graph ensures only affected targets rebuild, and parallel execution saturates all available CPU cores.
How to use
- Install Bazelisk (a version manager that downloads the right Bazel version automatically).
- Define
BUILDfiles that describe your targets and their dependencies. - Run
bazel buildorbazel testto compile and test.
# Install via npm or Homebrew
npm install -g @bazel/bazelisk
# or
brew install bazelisk
# Build a target
bazel build //src:my_app
# Run all tests
bazel test //tests:all
Example
A BUILD file for a Go binary that depends on a library:
load('@io_bazel_rules_go//go:def.bzl', 'go_binary', 'go_library')
go_library(
name = 'lib',
srcs = ['lib.go'],
importpath = 'example.com/myapp/lib',
visibility = ['//visibility:public'],
)
go_binary(
name = 'server',
srcs = ['main.go'],
deps = [':lib'],
)
Running bazel build //:server compiles only what changed since the last build.
Related on TokRepo
- AI Tools for DevOps — Build and deployment tools for modern development teams
- AI Tools for Testing — Testing frameworks that integrate with build systems
Common pitfalls
- The learning curve for
BUILDfiles and Starlark syntax is steep. Teams migrating from Make or Gradle should expect a ramp-up period. - Third-party dependency management requires rules (rules_python, rules_go, etc.) that each have their own patterns. Version conflicts across rulesets are common.
- Hermeticity means Bazel ignores your system-installed tools. If a toolchain is not declared in the workspace, the build fails even if the tool exists on PATH.
Frequently Asked Questions
Bazel has official support for Java, C++, Python, Go, Android, and iOS. Community-maintained rulesets extend support to TypeScript, Rust, Scala, Kotlin, Haskell, Swift, and many others. Each language uses a dedicated ruleset that defines how to compile, test, and package.
Make uses file timestamps and shell commands. Bazel uses content hashing and a hermetic sandbox. This means Bazel builds are reproducible across machines, support remote caching, and correctly handle incremental builds. Make is simpler for small projects; Bazel pays off at scale.
Bazelisk is a launcher for Bazel that automatically downloads and runs the version of Bazel specified in the project's .bazelversion file. It eliminates version mismatches across team members and CI environments. Most teams use Bazelisk instead of installing Bazel directly.
Yes. Bazel supports remote caching where build outputs are stored on a shared server. When one developer builds a target, the cached result is available to everyone else. Remote execution goes further by distributing build actions across a cluster of workers.
For small single-language projects, Bazel adds overhead without much benefit. Language-specific tools like Go modules, npm, or Cargo are simpler. Bazel becomes valuable when projects span multiple languages, have many interconnected targets, or need reproducible builds across CI.
Citations (3)
- Bazel GitHub— Bazel build system from Google
- Bazel Official Docs— Bazel concepts and build rules documentation
- Bazel Remote Docs— Remote caching and execution in Bazel
Related on TokRepo
Discussion
Related Assets
doctest — The Fastest Feature-Rich C++ Testing Framework
doctest is a single-header C++ testing framework designed for minimal compile-time overhead and maximum speed.
Chai — BDD/TDD Assertion Library for Node.js
Chai is a flexible assertion library for Node.js and browsers that supports expect, should, and assert styles.
Supertest — HTTP Assertion Library for Node.js APIs
Supertest provides a high-level API for testing HTTP servers in Node.js with fluent assertion chaining.