|
3 | 3 | One of Cargo's primary tasks is to determine the versions of dependencies to
|
4 | 4 | use based on the version requirements specified in each package. This process
|
5 | 5 | is called "dependency resolution" and is performed by the "resolver". The
|
6 |
| -result of the resolution is stored in the `Cargo.lock` file which "locks" the |
| 6 | +result of the resolution is stored in the [`Cargo.lock` file] which "locks" the |
7 | 7 | dependencies to specific versions, and keeps them fixed over time.
|
8 | 8 | The [`cargo tree`] command can be used to visualize the result of the
|
9 | 9 | resolver.
|
10 | 10 |
|
| 11 | +[`Cargo.lock` file]: ../guide/cargo-toml-vs-cargo-lock.md |
11 | 12 | [dependency specifications]: specifying-dependencies.md
|
12 | 13 | [dependency specification]: specifying-dependencies.md
|
13 | 14 | [`cargo tree`]: ../commands/cargo-tree.md
|
@@ -203,6 +204,30 @@ ecosystem if you publish a SemVer-incompatible version of a popular library.
|
203 | 204 | [semver trick]: https://github.com/dtolnay/semver-trick
|
204 | 205 | [`downcast_ref`]: ../../std/any/trait.Any.html#method.downcast_ref
|
205 | 206 |
|
| 207 | +### Lock file |
| 208 | + |
| 209 | +Cargo gives the highest priority to versions contained in the [`Cargo.lock` file], when used. |
| 210 | +This is intended to balance reproducible builds with adjusting to changes in the manifest. |
| 211 | + |
| 212 | +For example, if you had a package in the resolve graph with: |
| 213 | +```toml |
| 214 | +[dependencies] |
| 215 | +bitflags = "*" |
| 216 | +``` |
| 217 | +If at the time your `Cargo.lock` file is generated, the greatest version of |
| 218 | +`bitflags` is `1.2.1`, then the package will use `1.2.1` and recorded in the `Cargo.lock` file. |
| 219 | + |
| 220 | +By the time Cargo next runs, `bitflags` `1.3.5` is out. |
| 221 | +When resolving dependencies, |
| 222 | +`1.2.1` will still be used because it is present in your `Cargo.lock` file. |
| 223 | + |
| 224 | +The package is then edited to: |
| 225 | +```toml |
| 226 | +[dependencies] |
| 227 | +bitflags = "1.3.0" |
| 228 | +``` |
| 229 | +`bitflags` `1.2.1` does not match this version requirement and so that entry in your `Cargo.lock` file is ignored and version `1.3.5` will now be used and recorded in your `Cargo.lock` file. |
| 230 | + |
206 | 231 | ### Rust version
|
207 | 232 |
|
208 | 233 | To support developing software with a minimum supported [Rust version],
|
|
0 commit comments