Skip to content

Cargo.lock package order is unstable across different cargo versions #9334

Closed
@teor2345

Description

Problem

When a lockfile contains multiple entries with the same package name and version, but different sources, the order of these packages in the lockfile changes between builds. (Even though the dependencies are exactly the same.)

Since our project commits the lockfile to git, these redundant changes produce commit noise, checkout conflicts, and merge conflicts.

Steps

Stable to nightly:

  1. Build ZcashFoundation/zebra@6bb5220 with nightly cargo
  2. Run git diff

Nightly to stable:

  1. Build ZcashFoundation/zebra@64662a7 with stable cargo
  2. Run git diff

Building on a different version changes the lockfile, even though there haven't been any dependency changes.

Note: cargo just needs to do dependency resolution, so a cargo check should work just as well as a build.

Possible Solution(s)

  • Sort the lockfile by name, version, and source
  • Workaround: warn when a build uses packages with the same name and version from different sources

Notes

Output of cargo version:

cargo +nightly --version
cargo 1.52.0-nightly (90691f2bf 2021-03-16)
cargo +stable --version
cargo 1.51.0 (43b129a20 2021-03-16)

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions