Buck2 Compared
Buck2 is Meta's build system, open-sourced in 2023 as a rewrite of the original Buck (2013). It solves the same problem as Bazel (huge monorepos, many languages, remote execution) with the same core ideas: targets with labels, Starlark, content-hashed actions and REAPI. If you know Bazel you can read a Buck2 repository in an hour. The differences are in the architecture and in what is built in.
Note: Buck2 isn't installed in the course image, so this lesson shows its files and commands without running them. The concepts map one to one onto what you have run with Bazel.
The same ideas, different names
| Concept | Bazel | Buck2 |
|---|---|---|
| build file | BUILD.bazel |
BUCK (Meta internally: TARGETS) |
| repository root / config | MODULE.bazel, .bazelrc |
.buckconfig (INI-style), .buckroot |
| label | @repo//pkg:target |
cell//pkg:target (a cell is a named root, like a repository) |
| rules | built-in core + rule sets (rules_cc…) |
all rules in Starlark, in the prelude cell; nothing is built into the binary |
| rule API | ctx.actions.run, providers |
ctx.actions.run, providers (DefaultInfo, RunInfo); very close to Bazel's |
| configurations | platforms, select(), transitions |
the same model: platforms, constraints, select(), configured_alias |
| toolchains | toolchain_type + resolution |
ordinary targets in a toolchains// cell, depended on by rules |
| query | query, cquery, aquery |
buck2 uquery, cquery, aquery, plus BXL (Starlark scripts over the graph) |
| caching / RE | local action cache, disk/remote cache, REAPI | REAPI-first: designed around remote execution and caching |
| local sandboxing | linux-sandbox / processwrapper | none by default: hermeticity comes from remote execution |
| external deps | Bzlmod + registry | vendored or generated (e.g. reindeer for Rust crates); no central registry |
| implementation | Java (server) | Rust, single incremental engine (DICE) |
What a Buck2 repository looks like
# .buckconfig
[cells]
root = .
prelude = prelude
toolchains = toolchains
none = none
[cell_aliases]
config = prelude
fbcode = none
fbsource = none
[parser]
target_platform_detector_spec = target:root//...->prelude//platforms:default# toolchains/BUCK: use the system C++ and Python found on the machine
load("@prelude//toolchains:demo.bzl", "system_demo_toolchains")
system_demo_toolchains()# lib/BUCK
cxx_library(
name = "greet",
srcs = ["greet.cpp"],
exported_headers = ["greet.h"], # Bazel: hdrs
visibility = ["PUBLIC"], # Bazel: //visibility:public
)
# app/BUCK
cxx_binary(
name = "app",
srcs = ["main.cpp"],
deps = ["//lib:greet"],
)buck2 init --git # new project with the prelude as a submodule
buck2 build //app:app
buck2 run //app:app
buck2 test //...
buck2 cquery 'deps(//app:app)'
buck2 build //app:app --show-output # print where outputs went (buck-out/v2/...)Note the naming: C++ rules are cxx_*, headers that dependents see are exported_headers, and public visibility is the string "PUBLIC". Python is python_library/python_binary, Rust rust_library/rust_binary, Go go_library, Java java_library.
Where Buck2 differs in practice
Everything is a rule in the prelude. C++, Python, Rust, Go, Java, Erlang, OCaml, Haskell and Apple rules live in Starlark in the prelude cell, which you vendor and pin. You can read and patch every rule; there are no hidden built-ins.
One incremental graph (DICE). Loading, analysis and execution are a single dependency graph in Buck2's engine, so there's no separate "analysis cache" to discard when flags change, and dynamic dependencies (outputs that decide further actions, such as C++20 modules or OCaml dependency scanning) are first-class via dynamic_output.
Remote execution as the default mental model. Buck2 assumes an REAPI backend (Meta's internal one, or BuildBuddy, EngFlow, NativeLink, Buildbarn outside). Locally it runs actions without a sandbox, so a missing input may only show up when the action runs remotely. Bazel catches it locally.
BXL. Buck Extension Language scripts can query the graph and run analysis or build actions from Starlark, which is how Meta builds IDE integration (compile databases, Rust analyzer projects) and custom tooling without a separate tool.
Ecosystem. Bazel has the BCR with hundreds of modules, mature IDE plugins and a large community; Buck2's external ecosystem is smaller, and third-party code is usually vendored or generated into BUCK files.
Test yourself
Where do Buck2's language rules (cxx_library, python_binary…) come from?
- Built into the buck2 binary
- The prelude: Starlark code in a cell you vendor
- The Bazel Central Registry
- Gradle plugins
What is a Buck2 'cell'?
- A test shard
- A named root directory, similar to a Bazel repository
- A remote worker
- A configuration
How does Buck2's default local execution differ from Bazel's?
- It is sandboxed more strictly
- It doesn't sandbox locally by default; hermeticity comes from remote execution
- It can't run locally
- It uses timestamps