ScriptsApr 16, 2026·3 min read

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.

TL;DR
Bazel provides hermetic, reproducible builds across 20+ languages with aggressive caching and parallel execution.
§01

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.

§02

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.

§03

How to use

  1. Install Bazelisk (a version manager that downloads the right Bazel version automatically).
  2. Define BUILD files that describe your targets and their dependencies.
  3. Run bazel build or bazel test to 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
§04

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.

§05

Related on TokRepo

§06

Common pitfalls

  • The learning curve for BUILD files 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

What languages does Bazel support?+

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.

How does Bazel compare to Make?+

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.

What is Bazelisk?+

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.

Can Bazel cache builds across machines?+

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.

Is Bazel worth it for small projects?+

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)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets