Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should the Cargo.lock be removed? #58

Closed
bassco opened this issue Nov 12, 2023 · 1 comment
Closed

Should the Cargo.lock be removed? #58

bassco opened this issue Nov 12, 2023 · 1 comment

Comments

@bassco
Copy link
Collaborator

bassco commented Nov 12, 2023

The general practise for libraries is to not enforce dependencies via Cargo.lock and to leave the versioning to the applications.

Investigate the impact of removing this file from the repository.

Applications that are created should have consistent versions and their repositories should include the lock file.

@bassco
Copy link
Collaborator Author

bassco commented Nov 12, 2023

Opinions have changed and this is no longer required, as cargo ignores library lock files by default these days.

See the Cargo FAQ on this topic, quoted below.

Why do binaries have Cargo.lock in version control, but not libraries?

The purpose of a Cargo.lock is to describe the state of the world at the time of a successful build. It is then used to provide deterministic builds across whatever machine is building the package by ensuring that the exact same dependencies are being compiled.

This property is most desirable from applications and packages which are at the very end of the dependency chain (binaries). As a result, it is recommended that all binaries check in their Cargo.lock.

For libraries the situation is somewhat different. A library is not only used by the library developers, but also any downstream consumers of the library. Users dependent on the library will not inspect the library’s Cargo.lock (even if it exists). This is precisely because a library should not be deterministically recompiled for all users of the library.

If a library ends up being used transitively by several dependencies, it’s likely that just a single copy of the library is desired (based on semver compatibility). If Cargo used all of the dependencies' Cargo.lock files, then multiple copies of the library could be used, and perhaps even a version conflict.

In other words, libraries specify semver requirements for their dependencies but cannot see the full picture. Only end products like binaries have a full picture to decide what versions of dependencies should be used.

@bassco bassco closed this as completed Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant