Configuring buildrules
Which file does what, who writes it, and whether it is committed. Part of how to use buildrules.
Files at a glance #
| File | Who writes it | Committed | Purpose |
|---|---|---|---|
.buckconfig | init | yes | cells, execution platform, timeouts |
.buckconfig.local | you | no | the farm, or mode = local; endpoints live only here |
rust-toolchain.toml | init, you | yes | the Rust version (exact) |
buildrules-pins.toml | you | yes | hashes for a version buildrules does not pin |
mopm-toolchain.toml | you | yes | mopm and Mojo versions (Mojo packages) |
toolchains/BUCK | init; you add families | yes | which toolchain families exist |
platforms/BUCK | init | yes | execution platforms |
buildrules.lock.bzl, buildrules.bzl | sync | yes | the generated table and its binding (Rust and npm, per directory) |
third_party/buildrules/ | sync | yes | registry crates as units |
toolchains/rust_pins.bzl, mopm_pins.bzl, mojo_pins.bzl | sync, mojo sync | yes | generated pins |
rust-project.json | rust-project develop | **no** | rust-analyzer's view of the workspace, with this machine's paths |
<pkg>/buildrules.mojo.lock.bzl, buildrules.mojo.bzl | mojo sync | yes | a Mojo package's graph and binding |
Generated files say "Do not edit" in their first line, and editing one is detected.
.buckconfig #
init writes, with CELL the value of --cell:
[cells]
CELL = .
prelude = prelude
toolchains = toolchains
none = none
buildrules = buildrules-ext # with --path: buildrules = <RELPATH>
[external_cells]
prelude = bundled
buildrules = git # --git only
[external_cell_buildrules]
git_origin = <ORIGIN>
commit_hash = <40 hex>
[build]
execution_platforms = CELL//platforms:exec
[http]
connect_timeout_ms = 30000
read_timeout_ms = 120000The file also has [cell_aliases], [buildfile], [buck2], [project] and a [parser] target platform detector; see the generated file. The [http] timeouts are longer than Buck2's defaults (5 seconds to connect) because every pin is a download. To upgrade buildrules, change commit_hash, run buildrules sync (and mojo sync, npm sync if you use them), review the diff, commit.
Where actions run #
[buildrules_re] mode is remote (the default, also when unset) or local. Any other value is refused.
| Setting (in .buckconfig.local) | Meaning |
|---|---|
[buck2_re_client] engine_address, action_cache_address, cas_address | standard Buck2 RE client settings; many farms use one address for all three |
[buck2_re_client] instance_name, tls | the REAPI instance; whether to use TLS |
[buildrules_re] linux_x86_64_properties | the exact property set of the workers that run linux x86_64 actions |
[buildrules_re] linux_aarch64_properties, macos_aarch64_properties | optional: the exact property set of the workers that run linux aarch64 / macOS arm64 actions; absent = no such platform is registered, and a Mojo package built for that platform fails analysis naming the key |
[buildrules_re] darwin_macos_hosts | required with macos_aarch64_properties to build a Mojo package for macOS arm64: the identities of the macOS workers, separated by spaces (what mojo_compile host-identity prints on each); a compile on any other host is refused |
[buildrules_re] macos_library_dirs | optional: absolute directories, separated by : or spaces, that a macOS test run searches for a library it opens by its bare name (such as liblz4.dylib), before dyld's defaults /usr/local/lib:/usr/lib; absent, dyld's own defaults only |
[buildrules_re] linux_arm64_enabled | true or false (the default, also when absent). Linux arm64 tests are off until Linux arm64 farm hardware is racked: while false, the linux aarch64 platform is not registered even if linux_aarch64_properties is set, and every Mojo target configured for linux aarch64 is incompatible, reported as skipped: waiting on linux-arm64 hardware (Buck2 lists it among the skipped incompatible targets, naming //platforms:skipped_waiting_on_linux_arm64_hardware). macOS arm64 is not covered. To re-enable: linux_arm64_enabled = true under [buildrules_re] |
[buildrules_re] mode | remote or local |
Action cache keys do not depend on the mode. Local mode is hermetic in what it runs (the pinned tools, checked by sha256), not in where: the machine supplies Buck2, its kernel and its CPU. buildrules has been run against one farm. It uses plain REAPI v2 through Buck2, so other farms that implement it should work; if yours differs, check the worker properties and the glibc version first. See also Remote execution.
The Rust toolchain #
[toolchain]
channel = "1.95.0"
components = ["clippy", "rustfmt"]
profile = "minimal"It is required: sync and check fail without it. Only channel is read, and it must be an exact release such as 1.95.0. stable, 1.95, a beta channel and a dated nightly are refused. A path key is refused, because a toolchain on one machine is not a pin. Plain cargo (through rustup) reads the same file, so Cargo and Buck2 use the same compiler. buildrules pins 1.95.0 (the default) and 1.85.0 (the oldest it supports). Another release needs its hashes in buildrules-pins.toml.
Your own pins #
buildrules-pins.toml is optional, at the repository root, and hand-written. An unknown Rust version is refused unless this file supplies the hashes of all three components:
[rust."1.86.0".rustc]
sha256 = "<64 lower-case hex>" # the hash of rustc-1.86.0-x86_64-unknown-linux-gnu.tar.gz in the dist manifest
size = 122722040 # bytes of that file
[rust."1.86.0".rust-std]
sha256 = "..."
size = 0 # a positive number of bytes
[rust."1.86.0".cargo]
sha256 = "..."
size = 0
[rust."1.86.0".clippy] # the clippy-preview tarball
sha256 = "..."
size = 0Only these tables and keys are read; # comments are allowed; there is no date key. A version that buildrules already pins is refused (the reviewed hashes win). sync copies the file into toolchains/rust_pins.bzl. A wrong hash fails the download, never the build silently. A mopm version buildrules does not pin goes in [mopm."0.0.2"] with url, sha256 and size; buildrules mojo sync copies it into toolchains/mopm_pins.bzl.
Cargo policy #
Policy lives in Cargo.toml tables that Cargo ignores. It is allowed in [workspace.metadata.buildrules] and, overriding per key, in [package.metadata.buildrules]. Any other key is refused, naming the key and the file.
| Key | Meaning |
|---|---|
actions | named chains of steps, such as ci = ["lint", "test"]; a name may not be a step name |
lint.deny-warnings | clippy -D warnings for :lint |
default-action | recorded in the table (no target derives from it yet) |
postgres | { url-env = "NAME" }: every test of the package runs with a private Postgres, its URL in NAME |
postgres = { url-env = "NAME" } starts, for each test run, a server of the pinned Postgres (17, from conda-forge) on a Unix socket in the action's TMPDIR (in /tmp when that path is too long for a socket), sets NAME to its URL (postgresql://postgres@<socket directory, percent-encoded>:5432/postgres) for the test, and stops the server after it. A package's postgres replaces the workspace's.
Steps are fmt, lint, typecheck, debug, test, release and coverage; for Rust, coverage is a member's line and branch figures under llvm-cov, and a coverage_floor.txt beside the member's BUCK file gives it :coverage_floor, which holds them to it. init writes a virtual workspace with resolver = "3" and incremental = false under the dev profile. Incremental builds cannot be hermetic, and sync refuses an incremental profile with this fix. Link-time optimization, a custom codegen backend, rpath and split-debuginfo profile fields are refused too.
npm policy #
The "buildrules" key of package.json is ignored by npm.
"buildrules": {
"steps": { "typecheck": "tsc-check" },
"actions": { "ci": ["typecheck", "test", "build"] },
"dist": "dist"
}steps renames the script a step runs (by default, the script of the step's own name). actions are named chains of steps. dist is the directory the build script writes. Any other key is refused.
Mojo toolchain #
[toolchain]
mopm = "0.0.48" # an exact release buildrules pins, or one buildrules-pins.toml supplies
mojo = "1.0.0" # an exact release mopm pins a toolchain forIt is required, and found by walking up from the package directory. Without it, mojo sync, mojo check and package analysis stop and print a minimal example. buildrules does not pin a Mojo compiler: mopm's unit graph names the compiler packages, and sync records them.
Mirrors #
-c buildrules.url_map="<from-prefix>=<to-prefix> ...", or the same under [buildrules] in .buckconfig.local, replaces the leading part of a pinned download's URL and nothing else. The sha256 and size are still checked, so a mirror cannot change the bytes. docs/pins.md lists mirrors that were verified byte-identical, and which pins have none.
Target platforms and CPU levels #
buildrules//platforms:linux_x86_64 is the default target platform and passes no CPU flag. For a CPU level, build with a platform of that level:
buck2 build --target-platforms buildrules//platforms:linux_x86_64_v3 //examples/isa:audit //examples/isa:isa_lib_testLevels are x86-64-v1 to v4 (platforms linux_x86_64_v1 to v4). A test at a level runs on a worker that reports at least that level, so your farm must schedule on the ISA property. In local mode the test runs on your CPU, which must have the level. The platforms/BUCK that init writes registers only the ISA-agnostic execution platform; to run tests at v2 to v4 you pass isa_platforms to buildrules_execution_platforms, as buildrules' own platforms/exec/BUCK does.
linux_armv8_0 to linux_armv8_4) exist as data only. There is no Arm worker and no execution platform that carries an Arm level, so an Arm test is refused.Registry crates with native build scripts #
third_party/buildrules/overrides.json is hand-written and read by sync. It maps name version to a why (required), drop_build_script, cfgs, native_deps (static archives a binary or test links) and a patch (copy, sub, add) on the unpacked crate. Every other build script runs as it is. A substitution that stops matching after a version bump fails the build.