liveBook · Manning

Lock file

As explained in Code Like a Pro in Rust

Cargo.lock is Cargo’s lock file that records exact package dependency versions and integrity checksums.

Cargo.lock records the resolved versions of direct and indirect package dependencies, along with checksums for integrity verification. Cargo.toml specifies dependency requirements; the lock file records the resolved dependency tree. section 2.2.1 section 2.2

Run `cargo update` to update Cargo.lock to the newest available crates permitted by the dependency specifications. A requirement that allows compatible upgrades gives Cargo more flexibility than an exact version requirement. section 2.2

Handle the lock file according to the project’s role:

  • For applications, commit Cargo.lock alongside Cargo.toml to help keep published releases consistent when third-party libraries change. section 2.2.1
  • For libraries, omit Cargo.lock from version control; with Git, add it to .gitignore. This leaves downstream packages free to update indirect dependencies as needed. section 2.2.1

A Cargo workspace shares one top-level Cargo.lock and resolved dependency tree across its members. Workspace membership does not itself declare dependencies: define a dependency between members when one uses another. section 2.10

Workspace dependency

In a workspace containing `subproject`, declare `subproject = { path = "./subproject" }` under `[dependencies]` and list `subproject` in `[workspace].members`. The projects then share the workspace’s top-level lock file. section 2.10

How Code Like a Pro in Rust covers it

How deep it goes
Explains lockfile contents, updates, version-control choices, and workspace sharing without detailing the file format.
Examples
Uses an application with a path-dependent workspace library and Git ignore rules to illustrate lockfile handling.
What you can do after
Operate/configure Cargo dependency updates and choose whether to commit the lock file for an application or library.
How it connects
Connects dependency resolution, semantic versioning, version control, and Cargo workspaces.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Code Like a Pro in Rust. The section links point to the parts of the book it draws on.