Skip to content
Latchkey

cargo generate-lockfile: Usage & Common CI Errors

Create Cargo.lock without compiling anything.

cargo generate-lockfile resolves the dependency graph and writes Cargo.lock, but unlike cargo build it does no compilation. It is handy for generating a lockfile in a lightweight CI step.

What it does

Performs dependency resolution against Cargo.toml and produces a fresh Cargo.lock with the latest compatible versions. With no existing lock it creates one; with one present it fully re-resolves.

Common usage

Terminal
cargo generate-lockfile           # create/refresh Cargo.lock
cargo generate-lockfile --offline # resolve from cached metadata

Common CI error: unexpected version bumps

Like cargo update, generate-lockfile re-resolves to the newest allowed versions, so running it in CI can silently change pinned dependencies and hide regressions. Fix: generate the lockfile in a dedicated update PR and commit it; in normal CI build with --locked to detect drift instead.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →