5 Things you didn’t know about Buck2

Meta has a very large monorepo, with many  different programming languages. To optimize build and performance, we developed our own build system called Buck, which was first open-sourced in 2013.  …

Neil Mitchell
4 min readintermediate
--
View Original

Overview

The article discusses five interesting facts about Buck2, Meta's recently open-sourced build system that serves as a successor to Buck. It highlights Buck2's performance improvements, unique features, and its design choices, particularly its use of Rust and Starlark.

What You'll Learn

1

How to configure Buck2 for remote execution to save bandwidth and disk space

2

Why using Rust for build systems can improve performance and memory management

3

How to utilize BXL for defining new build actions in Buck2

Prerequisites & Requirements

  • Understanding of build systems and their architecture
  • Familiarity with Rust and Starlark programming languages(optional)

Key Questions Answered

What programming language is Buck2 written in?
Buck2 is primarily written in Rust, with build rules defined in Starlark, a Python-like language. This choice was made for its performance, memory control, and concurrency capabilities, which are essential for a highly parallel build system.
How does Buck2 optimize remote execution?
Buck2 can execute actions remotely and avoid downloading intermediate outputs by remembering the resulting hash of those actions. This allows builds to proceed with minimal local activity, saving both bandwidth and disk space.
What types of file paths does Buck2 support?
Buck2 utilizes 11 different types of file paths internally, including the built-in Rust Path type and additional types to specify relative paths. This design enhances type safety and helps prevent bugs related to path handling.
What is the purpose of BXL in Buck2?
BXL, or Buck2 Extension Language, allows users to inspect and interact with the Buck graph using Starlark APIs. It enables the definition of new build actions and facilitates the reuse of build graph information, enhancing project management.

Key Statistics & Figures

Build speed improvement
approximately 2x as fast as Buck1
This performance improvement was observed in internal tests conducted at Meta.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Key Actionable Insights

1
Utilize Buck2's remote execution capabilities to streamline your build process.
By configuring remote execution, you can significantly reduce local resource usage and improve build times, especially in large projects with complex dependencies.
2
Leverage the type safety provided by Buck2's multiple path types to avoid common bugs.
By using distinct path types, you can ensure that your build system correctly interprets paths relative to various project contexts, reducing errors during the build process.
3
Explore the capabilities of BXL to create custom build actions tailored to your project's needs.
BXL's flexibility allows you to define unique build actions that can optimize performance for specific languages or frameworks, enhancing your overall development workflow.

Common Pitfalls

1
Failing to configure remote execution properly can lead to inefficient builds.
Without proper configuration, builds may not take advantage of remote execution benefits, resulting in longer build times and unnecessary resource consumption.

Related Concepts

Build Systems
Performance Optimization In Software Development
Dependency Management In Large Projects