How facebook/buck2 works
Buck2 is a hermetic, multi-language build system. A typical workflow starts with a user invoking the CLI, evaluates build definitions and dependencies, analyzes configured targets into actions, executes those actions, and exposes resulting artifacts. Separate branches support target queries and BXL graph introspection. The README documents remote execution, distributed compilation, filesystem watching, and user-defined language support; the supplied source excerpts do not show their full wiring, so those connections are kept conservative.
Main entry points: commands Command handlers · action_executor.rs Action executor · configure_targets.rs Target configuration · analysis.rs Target analysis
Components 19
Command entry
- Buck2 CLI
app/buck2/src/commands.rs - Command handlers
app/buck2/src/commands
Build planning
- Build definitions
app/buck2_build_api/src/interpreter.rs - Language rules
prelude - Target configuration
app/buck2_build_api/src/configure_targets.rs - Target analysis
app/buck2_analysis/src/analysis.rs - Incremental engine
dice/dice/src - Filesystem watcher
app/buck2_file_watcher
Action execution
- Action registration
app/buck2_build_api/src/actions/registry.rs - Action implementations
app/buck2_action_impl/src/actions - Action executor
app/buck2_build_api/src/actions/execute/action_executor.rs - Remote execution
app/buck2_execute_impl/src - Build artifacts
app/buck2_artifact/src/artifact.rs - Artifact materializer
app/buck2_build_api/src/materialize.rs
Inspection and extensions
- Build queries
app/buck2_build_api/src/query.rs - BXL extensions
app/buck2_bxl/src
Other components
- Developer
- Remote CAS
- Distributed compilation
Connections 20
- Developer → Buck2 CLI: invokes
- Buck2 CLI → Command handlers: dispatches
- Command handlers → Target configuration: requests build
- Build definitions → Language rules: loads rules
- Target configuration → Build definitions: evaluates definitions
- Target configuration → Target analysis: configures targets
- Target analysis → Incremental engine: calculates dependencies
- Target analysis → Action registration: registers actions
- Action registration → Action implementations: creates actions
- Command handlers → Action executor: requests execution
- Action executor → Action implementations: runs actions
- Action executor → Remote execution: dispatches remotely
- Remote execution → Remote CAS: reads and writes
- Action executor → Build artifacts: produces outputs
- Command handlers → Artifact materializer: requests materialization
- Artifact materializer → Build artifacts: materializes
- Filesystem watcher → Incremental engine: updates inputs
- Command handlers → Build queries: runs query
- Command handlers → BXL extensions: runs extension
- Remote execution → Distributed compilation: supports compilation