Chapter 26: toolchains, the compilers buck uses, all from nix
buck2 does not bring its own compilers. It asks a toolchain target "what is your C compiler, your Rust compiler, your Python?" and runs whatever it is told. This folder answers, and every answer is a path into the nix store.
They are the buck prelude's own system_demo_toolchains, copied and
configured as that macro's documentation asks, with one change in where the
paths come from: not from PATH, which buck's C shim never searches (it
execs by absolute path), but from .buckconfig.local, which the devshell
writes on every entry (chapter 16). So a build sees exactly the tools the
flake pins, and nothing else on the machine.
flowchart LR F["flake.nix devshell"] -->|"shellHook writes"| L[".buckconfig.local: [nix] cc, cxx, ar, python, [rust] rustc_identity"] L -->|"read_root_config"| T["toolchains/BUCK: cxx, python, rust, genrule, test, zip_file"] T --> B["every buck action"]
The Rust toolchain carries three settings worth knowing about. Optimisation
is explicit (-Copt-level=3), because build scripts read their OPT_LEVEL
from it. Debug assertions stay on for development and tests (the executor's
thread checks are debug_asserts), and the nix package turns them off for
release. And every compile carries an inert --cfg rustc_identity="…" with
the compiler's store path.
Aside: a flag that does nothing, on purpose. No code reads
rustc_identity. It is there because the prelude's toolchain invokes the bare namerustc, so buck's cache key never recorded which rustc compiled a crate. With a build cache shared across repositories, a library compiled by another repository's older rustc was served back and failed with E0514, "compiled by an incompatible version of rustc". Putting the compiler's path in a flag puts it in every key, and the collision is gone.
Try it.
cat .buckconfig.localinsidenix develop: every path in it is the one this folder hands to buck.
For the people who maintain it
| File | What |
|---|---|
| BUCK | The toolchains: cxx (clang from nix), genrule, python and python_bootstrap (nix's python), rust (edition from build/defs.bzl, the flags above), remote_test_execution, test, zip_file. |
← Previous: Chapter 25, record-gates/src/ · Up: postjevsql · Next: Chapter 27, platforms/ →