chore(tooling): add project rustfmt.toml and pin the stable toolchain

Merged
OW
25d ago
+100-67

What

Adds a project-level formatting policy and a toolchain pin, then applies the
formatting so the first step of the quality gate (cargo fmt --check) actually
passes.

  • rustfmt.toml (new) — edition = "2021", max_width = 100, plus a
    comment explaining why nothing nightly-only may be added.
  • rust-toolchain.toml (new) — channel = "stable" (the channel CI
    installs) with the rustfmt and clippy components, and no targets.
  • 10 source files — formatting only (39 sites).
  • AGENTS.md, .github/instructions/rust.instructions.md — document
    both files and the stable-only rule.

Why not the global ~/.rustfmt.toml

It cannot serve as project policy, for three measured reasons:

  1. rustfmt auto-loads it for every file in this repo, so it was silently
    in force — and it is a 79-key dump, not a deliberate project choice.
  2. required_version = "1.7.1" is a hard failure on any newer rustfmt
    (error: rustfmt version (1.11.0) doesn't match the required version (1.7.1)), and no installable nightly ships rustfmt 1.7.1 — the nightlies
    from 2024-12 onward are all 1.8.0+.
  3. unstable_features = false disables the 27 nightly-only options the same
    file declares, so they never applied even on a nightly formatter.

Measured diff sites for git ls-files '*.rs':

ConfigFormatterDiff sites
none (rustfmt defaults)stable 1.10.039
none (rustfmt defaults)nightly 1.11.039
~/.rustfmt.toml verbatimstable 1.10.050
~/.rustfmt.toml (stable subset)nightly 1.11.0101
~/.rustfmt.toml + use_small_heuristics = "Max"both206

Defaults + max_width = 100 is the only combination that is both small-churn
and identical on stable and nightly — which is what makes the gate
reproducible.

Toolchain decision

Keep rust-toolchain.toml, pinning stable to match CI
(.github/workflows/ci.yml and release.yml both use
dtolnay/rust-toolchain@stable). It replaces a stray untracked local file that
pinned 1.78.0 plus targets = ["x86_64-unknown-linux-gnu"] — unusable on
this machine and too old for current dependencies. No target is pinned because
cross-compilation is driven by release.yml, not by this file.

Note for mise users: when mise provides cargo on PATH it takes precedence
over the rustup shim, so this file is not a guarantee there. That is called out
in AGENTS.md.

Gate

All six steps green (RUSTFLAGS="-C linker=/usr/bin/cc" for the linker
workaround from #77):

  • cargo fmt --check — clean, and also clean under nightly rustfmt 1.11.0
  • cargo build --workspace / --features iklo-cli/turso — ok
  • cargo test --workspace (59 passed) / --features iklo-cli/turso (90 passed)
  • cargo clippy --workspace --all-targets --features iklo-cli/turso — no new
    warnings; the source diff is identical modulo whitespace (git diff -w shows
    no changed non-blank lines)

Follow-ups (deliberately not in this PR)

  • CI has no cargo fmt --check step, so this policy is still advisory. A
    3-line job in ci.yml would enforce it.
  • #77 stays open: the linker/Xcode 27 issue and the RUSTFLAGS workaround are
    untouched here.

Refs #77


Summary by cubic

Adds a project-level rustfmt policy and pins the Rust toolchain to stable so cargo fmt --check passes on every toolchain, now enforced in CI.

  • New rustfmt.toml keeps only options that behave identically across rustfmt releases (edition, max_width = 100); nightly-only options are banned.
  • New rust-toolchain.toml pins stable with the rustfmt and clippy components, matching CI; no cross-compilation target is pinned.
  • CI installs the rustfmt component and runs cargo fmt --check, so the policy is enforced rather than advisory (CI fixes: YAML indentation and action reference typos).
  • Reformats 10 source files (39 sites, whitespace-only) and documents both files in AGENTS.md and .github/instructions/rust.instructions.md.

Stable-only options keep the gate consistent across toolchains but don't freeze rustfmt defaults between stable releases; running the check in CI is what catches that drift.

Refs #77

Summary by Sourcery

Establish a reproducible stable Rust formatting workflow and enforce it in CI.

New Features:

  • Add project-level Rust formatting and toolchain configuration aligned with the stable CI environment.

Enhancements:

  • Apply the project formatting policy across the affected Rust sources.
  • Document the formatting and toolchain requirements, including the stable-only rustfmt policy and mise behavior.

CI:

  • Install rustfmt in CI and enforce formatting with cargo fmt --check.

Summary by CodeRabbit

  • Chores
    • Automated checks now verify Rust formatting before builds and tests, helping catch formatting issues earlier.
    • The project’s Rust toolchain now includes formatting and linting tools.
  • Documentation
    • Updated development guidance explains how to format and check code, the project’s formatting conventions, and how the configured Rust toolchain affects development commands.