How to use buildrules

Install, initialize, build. Configuration and Examples are the next two pages; Why buildrules is the design.

Note. Everything here is version 0 and runs on linux x86_64 only. It describes the repository at its current main. The longer text is docs/how.md in the repository.
Planned. Not built yet: Arm and macOS hosts for the rules. A Homebrew formula and an apt repository are made by every release and published only after setup (RELEASING.md): until then there is none.

What you need #

Get the command line #

The install script picks the program for your machine, checks its sha256 against the release's SHA256SUMS, and installs it as ~/.buildrules/bin/buildrules. It needs curl, tar and awk, edits no startup file, needs no root, and installs nothing if a check fails:

shell
curl -fsSL https://buildrules.dev/install.sh | sh
Planned. The site is not published yet, so https://buildrules.dev/install.sh answers only after the repository owner has published it (what is not done). Until then run the script from a checkout of the repository: sh site/static/install.sh.

Options follow sh -s -- when the script is piped: --version V installs that release instead of the latest, --prefix DIR installs DIR/bin/buildrules instead of under ~/.buildrules, --verify also checks the keyless signature of the tarball with cosign verify-blob (it stops if cosign is not installed), and --releases-url URL reads releases from a mirror. The macOS program is for Apple silicon: on an Intel Mac the script stops and says so before it asks for anything.

Or by hand: a release carries the command line as a static program for three platforms, as a Debian package for the two Linux ones, and a source archive. Pick a release from the releases page. To use a program, unpack the tarball of your platform (linux-x86_64, linux-aarch64, or macos-arm64), check it, and put buildrules on your PATH:

shell
v=0.0.1     # the release you chose
t=linux-x86_64     # your platform
curl -fsSLO "https://github.com/komira-ai/buildrules/releases/download/v$v/buildrules-cli-$v-$t.tar.gz"
curl -fsSLO "https://github.com/komira-ai/buildrules/releases/download/v$v/SHA256SUMS"
sha256sum --check --ignore-missing SHA256SUMS
tar -xzf "buildrules-cli-$v-$t.tar.gz"
"buildrules-cli-$v-$t/buildrules" --version

--version prints buildrules <version>, the number of the release. Each tarball carries a build provenance attestation and a signature, checked with gh attestation verify as for the source archive below. The macOS program (Apple silicon: there is no program for an Intel Mac) is not code-signed or notarised, and only the linux x86_64 program is run by the release's user beta. The rules themselves run on a linux x86_64 farm or machine.

Planned. A Homebrew formula and an apt repository are published only after setup (RELEASING.md); until then there is none to install from.

Each release also builds the Homebrew formula (a pull request in the organisation's tap) and the Debian packages buildrules_<version>_amd64.deb and ..._arm64.deb, which are files of the release, checked like the tarballs. After setup, with OWNER the organisation that holds the repository:

shell
brew install OWNER/tap/buildrules
sudo apt install buildrules     # after adding the repository and its key, RELEASING.md

To install the package of a release by hand before then: sudo apt install "./buildrules_${v}_amd64.deb" (arm64 on an Arm machine), after the checks above.

Or build the command line from source with Buck2. Check the source archive:

shell
v=0.0.1     # the release you chose
curl -fsSLO "https://github.com/komira-ai/buildrules/releases/download/v$v/buildrules-$v.tar.gz"
curl -fsSLO "https://github.com/komira-ai/buildrules/releases/download/v$v/SHA256SUMS"
sha256sum --check SHA256SUMS
gh attestation verify "buildrules-$v.tar.gz" --repo OWNER/REPO
tar -xzf "buildrules-$v.tar.gz"
cd "buildrules-$v"

OWNER/REPO are the two path segments of the repository URL above. The attestation is GitHub build provenance, signed with the release workflow's identity; it proves the archive was built by that workflow from a commit of main. gh is only needed for that line.

Build the program. With no farm, use local mode:

shell
buck2 build -c buildrules_re.mode=local //cli:buildrules --show-output

--show-output prints the path of the executable. Put it on your PATH as buildrules. buildrules --help lists the commands and buildrules <command> --help their flags. Exit codes are the same everywhere: 0 ok, 1 failed or stale (the fix is printed), 2 usage. A program built from the source archive prints <MAJOR.MINOR>-dev for --version: only the released tarballs are stamped with the release number.

Initialize your repository #

Run init once, in the repository root. It adds buildrules as a Buck2 cell pinned to one commit. Get the commit of the release tag:

shell
git ls-remote https://github.com/komira-ai/buildrules 'refs/tags/v0.0.1^{}'
shell
buildrules init . --git https://github.com/komira-ai/buildrules --commit <the 40-hex commit above>

The commit must be 40 hex digits. A branch or tag is refused, because it is not a pin. init writes the files below and never overwrites one that exists:

FileWhat
.buckconfigcells, execution platform, the pinned buildrules commit, download timeouts
toolchains/BUCKone call: rust_toolchains(extra = EXTRA_RUST_VERSIONS)
toolchains/rust_pins.bzlthe extra Rust versions from buildrules-pins.toml (empty at first; sync rewrites it)
platforms/BUCKthe execution platform (remote by default)
.buckconfig.local.examplea template for the farm settings
rust-toolchain.tomlan exact compiler, if you have none
Cargo.tomla virtual workspace with the [workspace.metadata.buildrules] policy, if you have none
.gitignorelines for .buckconfig.local and buck-out/

Other flags: --path RELPATH instead of --git (buildrules is a local cell inside the repository, as a submodule or a vendored copy unpacked from the archive), --cell NAME (the name of your repository's own cell, default root) and --rust-version N.N.N (default 1.95.0). A root Cargo.toml that has a [package] is refused: the root must be a virtual workspace and your packages live in subdirectories.

Say where actions run #

Buck2 needs somewhere to run actions. buildrules has two modes, chosen by [buildrules_re] mode.

Local mode #

Local mode runs every action on the machine that runs Buck2, with the same pinned toolchains. Use it on a CI runner or without a farm. Pass the option on every command, or write it once in the gitignored .buckconfig.local:

shell
buck2 build -c buildrules_re.mode=local //crates/hello:test
.buckconfig.local
[buildrules_re]
  mode = local

Local mode is refused if an engine or CAS address or a worker property set is also configured: a machine that has a farm does not run locally.

Remote mode #

Remote mode is the default. It runs every action on a farm. Copy the template and fill it in; the copy is gitignored and must never be committed.

shell
cp .buckconfig.local.example .buckconfig.local
.buckconfig.local
[buck2_re_client]
  engine_address = <execution endpoint>
  action_cache_address = <action cache endpoint>
  cas_address = <content-addressable storage endpoint>
  instance_name = <instance name>
  tls = true

[buildrules_re]
  linux_x86_64_properties = OSFamily=Linux,ISA=x86-64,container-image=docker://<image>@sha256:<digest>

linux_x86_64_properties is your farm's own worker property set, comma-separated key=value pairs, passed through unchanged. If it is missing, the execution platform fails to load with a message that names the file; nothing falls back to your machine.

Limit. The comment in the .buckconfig.local.example that init writes still says there is no local fallback. Local mode exists; the comment is out of date.

Your first build #

shell
buildrules cargo new crates/hello      # a package, adopted: BUCK file, metadata, workspace member
buildrules sync                        # Cargo's files -> the generated table; commit the output
buck2 build //crates/hello:test //crates/hello:debug
buildrules check                       # offline: the pull-request gate

Commit everything init and sync wrote except .buckconfig.local.

Build it a second time #

Run the same build again: it should be all cached. Change one source file of a crate and rebuild: only that crate and what depends on it run. That is the per-dependency cache working; on a farm it is shared by every machine and every CI job.

Adding it to CI #

On a GitHub-hosted Ubuntu runner, local mode works with no farm. The buildrules repository's own .github/workflows/ci.yml is a working example: it installs the pinned Buck2, verifies its sha256, and runs every buck2 command with -c buildrules_re.mode=local. Run buildrules check as a separate, cheap step that needs no build.

Reading a failure #

Where to go next #