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.
Buck2 is the recently open-sourced successor. In our internal tests at Meta, we observed that Buck2 completed builds approximately 2x as fast as Buck1. Below are five interesting facts you might not have known about Buck2.
Fact1: Buck2 is written in Rust
The core of Buck2 is written in Rust, with the rules written in Starlark (a Python-like language) and interpreted by our open-source Starlark library. Using Starlark was a natural choice since Buck1 and Bazel both already use it. We debated between using Java (like Buck1), Haskell (like the Shake build system) or Go for the core programming language. In the end we chose Rust because of its high performance, control over memory usage (garbage collection isn’t a great fit for big graphs), and its focus on correct concurrency (important for a highly parallel build system).
Fact2: Buck2 can avoid downloading intermediate outputs
When configured using remote execution, Buck2 can run actions remotely. If the output of those actions is then used as the input for a further remote action, we avoid ever downloading the intermediate output and just remember the resulting hash. In some cases a build will proceed entirely remotely, with only minimal local activity, followed by downloading the final results. This technique can save both bandwidth and disk space.
Fact3: Buck2 has 11 different types of file path internally
In addition to the built-in Rust Path type, and the relative-path crate’s type RelativePath, we have further defined nine additional path types. We use these distinct types to identify which paths are absolute and, for relative paths, what they are relative to (e.g., relative to project root, enclosing cell, package, a given label, etc). While it was fairly tedious to write out so many types of path, the bugs it prevented made it worth it. We take our type safety very seriously!
Fact4: Buck2 has no knowledge of any programming language built in
Everything language-specific in Buck2 is described in Starlark. Furthermore, while Buck2 comes with a Starlark “prelude” that supports a number of programming languages (e.g., C++, Rust, Python, OCaml, etc.) you can write your own prelude from scratch (several open source users have done so).
Because we kept the core of Buck2 free from language concepts, we had to make the Starlark APIs powerful enough to write things like dep files and conditional relinking– important performance optimisations in C++. Happily, the APIs required for those advanced features tend to be useful in other languages for purposes we hadn’t even imagined (e.g. Erlang dependency trimming, Android package grouping).
Fact5: Buck2 provides BXL (Buck2 Extension Language) for inspecting and interacting with the Buck graph
This feature, which is unique in the build system space as far as we are aware, gives access to the graph with Starlark API, and also lets you define new build actions native to BXL. The build graph often serves as the source of truth for a project, and BXL lets that information be easily reused. We have used BXL to generate IDE projects but think this could have lots of future opportunities.
- Build faster with Buck2: Our open source build system (Buck2 announcement blog)
- Buck2 website
- Buck2 GitHub
We hope you found this article insightful to show you what Buck2 is capable of and where you can use it for your own workflow. Stay tuned for our upcoming blog posts, where we will explore other projects from Meta’s DevInfra teams, and interesting facts on how you can use them in your own projects.
About this series
This blog is a part of our 5 Things you didn’t know series, where we go over the top five interesting facts about a DevInfra project from Meta that can help you simplify your projects or workflows. Look out for more of these blogs where we discuss other DevInfra projects and interesting facts to help you get started with using them in your own projects.