Skip to content
Latchkey

buck2 build and test: Meta's Build System

buck2 build //path:target builds a target by its label, and buck2 test runs tests, using Buck2's hermetic, parallel build graph.

Buck2 (from Meta) addresses large monorepos with hermetic, cached builds. Targets are addressed by labels like //src/app:main rather than file paths, and //... means everything under a directory.

What it does

buck2 build resolves a target label to its build rule, builds it and its dependencies from the graph, and caches outputs. buck2 test builds and runs test targets. Buck2 is designed to be hermetic, so builds are reproducible across machines.

Common usage

Terminal
buck2 build //src/app:main
buck2 build //src/... --show-output
buck2 test //tests:unit
buck2 build //... --num-threads 8

Options

Flag / syntaxWhat it does
//path:targetFully-qualified target label to build
//path/...All targets recursively under a directory
--show-outputPrint the paths of built output artifacts
--num-threads <N>Cap the local build parallelism
-c <section.key>=<value>Override a buckconfig value for this run
buck2 test <targets>Build and run the named test targets

In CI

Buck2 expects a .buckconfig at the repo root and BUCK files defining targets. Use --show-output to capture artifact paths for upload. Remote caching (if configured) is where Buck2 pays off in CI; without it you lose the main advantage over per-directory build tools.

Common errors in CI

"Unknown cell name" or "Error: Unknown cell" means .buckconfig cells are misconfigured or you ran outside the repo root. "Target pattern //foo:bar could not be resolved" means the BUCK file has no such target. "buck2: command not found" means the buck2 binary is not installed. Parse errors in a BUCK file surface as Starlark evaluation errors pointing at the offending line.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →