rust-build-conventions
Skill7 starsChanged 3 days agoMITView on GitHub
Rust build and test infrastructure: toolchain pin, sqlx database tests, `build.rs`, cargo-chef, test coverage. TRIGGER when: scaffolding a Rust project; pinning the Rust toolchain; a `rust-toolchain.toml` (or `rust-toolchain`) in the repo; editing a `build.rs`; calling `sqlx::migrate!` or writing a `#[sqlx::test]`; "relation does not exist" after adding a migration; building a Rust `Dockerfile` or touching `cargo chef`; CI red after a clippy release; measuring test coverage, `cargo llvm-cov` or `cargo tarpaulin`. SKIP when: no such file or test is involved (`rust-conventions`). Load `rust-conventions` alongside.
- Installs packages
1 other project uses a version of this.
Adopted by
Most recently taken up by
- leroyguillaume/skillsword for word, first seen Nov 22, 2026
Other versions1 project uses a version of this.
Word for word · 1
- leroyguillaume/skills★ 7100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository54 other files it gives its agents.
- adr-conventionsSkill
- api-conventionsSkill
- architecture-conventionsSkill
- argocd-conventionsSkill
- ci-conventionsSkill
- config-conventionsSkill
- contributing-conventionsSkill
- councilSkill
- cryptography-conventionsSkill
- dependency-update-conventionsSkill
- diagram-conventionsSkill
- docker-conventionsSkill
- documentation-conventionsSkill
- frontend-conventionsSkill
- github-actions-conventionsSkill
- github-issue-conventionsSkill
- github-pr-conventionsSkill
- github-repo-settingsSkill
- gitlab-ci-conventionsSkill
- helm-conventionsSkill
- herdr-core-delegationSkill
- herdr-delegationSkill
- herdr-tui-delegationSkill
- kopf-conventionsSkill
- kubernetes-operator-conventionsSkill
- logging-conventionsSkill
- logo-conventionsSkill
- mise-conventionsSkill
- ollama-conventionsSkill
- openssf-conventionsSkill
- pr-conventionsSkill
- pre-commit-conventionsSkill
- project-metadata-conventionsSkill
- python-async-conventionsSkill
- python-conventionsSkill
- readme-conventionsSkill
- release-script-conventionsSkill
- release-supply-chain-conventionsSkill
- renovate-ci-conventionsSkill
- rest-conventionsSkill
- rust-conventionsSkill
- rust-http-conventionsSkill
- security-policy-conventionsSkill
- signal-handling-conventionsSkill
- sql-conventionsSkill
- starlight-conventionsSkill
- systemd-conventionsSkill
- system-user-conventionsSkill
- task-conventionsSkill
- terraform-conventionsSkill
- topic-splittingSkill
- ui-copy-conventionsSkill
- web-layout-conventionsSkill
- yaml-conventionsSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 0 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 39
When a crate embeds migrations with sqlx::migrate!(...), add a build.rs that re-runs on migration changes.
- Very specific: line 52
Create this build.rs as soon as the crate calls sqlx::migrate!, not after the first stale-migration surprise.
- Very specific: line 62
When the project ships a Dockerfile, build it with cargo-chef — but only inside the Dockerfile.
- Very specific: line 76
Never add cargo-chef to Cargo.toml (deps or dev-deps) and never invoke it in local development or CI outside the image build — it is purely …
- Very specific: line 111
Never use testcontainers (or other throwaway-container harnesses) for database tests.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Rust build and test conventions
Always:
- Pin the toolchain in
mise.toml(mise-conventions), on an exact patch version, never in arust-toolchain.toml: an existing one moves intomise.tomland is deleted. Without a pin, a clippy release turns CI red on code nobody touched; with one, a toolchain bump is a reviewable diff.
Resolve[tools] rust = { version = "<current stable release>", components = ["rustfmt", "clippy"], profile = "minimal" }<current stable release>when you write the file, frommise latest rustor https://releases.rs, never from memory. This pin is not the MSRV.rust-versioninCargo.tomlis what consumers must have and should stay as low as the code allows; the toolchain pin is what contributors and CI build with and should stay current. Never collapse the two. - For database integration tests, run against a real Postgres (the
project's
docker-composeservice) and isolate with#[sqlx::test]— it creates a fresh database per test, applies the migrations, and injects aPgPool(orPgConnection). PointDATABASE_URLat the compose Postgres when running the suite. Do not usetestcontainers. - When a crate embeds migrations with
sqlx::migrate!(...), add abuild.rsthat re-runs on migration changes. The macro embeds the migrations at compile time, so adding a new.sqlfile does not, on its own, make Cargo rebuild the crate — the macro keeps expanding to the stale set and tests fail with confusing "relation does not exist" errors against the just-added schema. The fix is one line:
Create this// build.rs fn main() { println!("cargo::rerun-if-changed=build.rs"); println!("cargo::rerun-if-changed=migrations"); }build.rsas soon as the crate callssqlx::migrate!, not after the first stale-migration surprise. - This is specific to macros that read files themselves (
sqlx::migrate!and similar proc macros).include_str!/include_bytes!need nobuild.rs:rustcrecords the included file in its dep-info, and Cargo rebuilds when it changes. Whenever abuild.rsexists, emitrerun-if-changedforbuild.rsitself and every path it watches: a build script that emits norerun-if-changedat all is re-run on any file change in the package. Thecargo::form needs Rust ≥ 1.77; a crate whoserust-versionis lower keeps the single-coloncargo:form. - When the project ships a
Dockerfile, build it with cargo-chef — but only inside theDockerfile. Install it there withcargo install cargo-chef --locked --version "${CARGO_CHEF_VERSION}", the version in anARG CARGO_CHEF_VERSION=<latest release>resolved when you write it, preceded by# renovate: datasource=crate depName=cargo-cheffor the Renovate custom manager that keeps it current (dependency-update-conventions). TheARGsits at the top of theDockerfilewith the other version knobs (docker-conventions) and is redeclared, bare, in thechefstage: anARGbeforeFROMis not visible inside a stage. Stage itchef→planner(cargo chef prepare) →builder(cargo chef cookthencargo build --release --locked). The recipe normalises away the package version and other non-dependencyCargo.tomlmetadata, so the cooked dependency layer stays cached across version bumps and source-only changes. Never addcargo-cheftoCargo.toml(deps or dev-deps) and never invoke it in local development or CI outside the image build — it is purely a Docker layer-caching tool. - Measure coverage with
cargo-llvm-cov(ci-conventions). It reads rustc's own source-based instrumentation, so it runs on stable, on every platform, and counts regions as well as lines;cargo-tarpaulindefaults to a ptrace engine on Linux and wraps that same instrumentation elsewhere. The registry lacks it, and it needs thellvm-toolscomponent:[tools] "aqua:taiki-e/cargo-llvm-cov" = "<latest>" rust = { version = "<current stable release>", components = ["rustfmt", "clippy", "llvm-tools"], profile = "minimal" }
The HTML report lands incoverage: desc: Run the tests and measure their line and region coverage cmds: - cargo llvm-cov --workspace --all-targets --locked {{.CLI_ARGS}} - cargo llvm-cov report --html coverage:summary: desc: Print the summary of the last coverage run cmds: - cargo llvm-cov reporttarget/llvm-cov/html/. On GitLab,coveragealso writescargo llvm-cov report --cobertura --output-path target/llvm-cov/cobertura.xml, and the job's regex reads theTOTALline's line coverage:/^TOTAL(?:\s+\S+){8}\s+(\d+(?:\.\d+)?)%/. Branch coverage (--branch) and doctests (--doctests) need nightly: never add a nightly toolchain for them.
Never:
- Never use
testcontainers(or other throwaway-container harnesses) for database tests. Use a real Postgres (the project'sdocker-compose) with#[sqlx::test]for per-test isolation.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

