Skip to content

Allow to set lockfile-path via an environment variable #15510

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

Open
Tracked by #14421
tnull opened this issue May 9, 2025 · 5 comments
Open
Tracked by #14421

Allow to set lockfile-path via an environment variable #15510

tnull opened this issue May 9, 2025 · 5 comments
Labels
A-lockfile Area: Cargo.lock issues C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage.

Comments

@tnull
Copy link

tnull commented May 9, 2025

Problem

In #14326, the capability to specify an lockfile-path was added to cargo. It would be awesome if this would also possible to configure via an environment variable, similar to CARGO_TARGET_DIR.

Proposed Solution

Add the capability to set the lockfile path via a CARGO_LOCKFILE_PATH environment variable.

Notes

See also #14421

@tnull tnull added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels May 9, 2025
@epage
Copy link
Contributor

epage commented May 9, 2025

Could you describe your use case?

@tnull
Copy link
Author

tnull commented May 9, 2025

Could you describe your use case?

Sure! I'd like to be able to mount the Rust project directory read-only into a container environment (e.g., docker,podman) for security reasons. To this end, I'd love to use lockfile-path to avoid having to modify the project directory.

This however currently would require me to append --lockfile-path to each invocation of cargo build/cargo test, which is fine for manually-run commands, but there are also a bunch of CI scripts that I'd need to patch each time the container is set up to consider the lockfile-path argument. Instead, it would be really handy to be able to set CARGO_LOCKFILE_PATH once globally, which is what I already do for CARGO_TARGET_DIR.

(Btw, it seems I'm not alone in this: https://users.rust-lang.org/t/specifying-the-location-of-the-cargo-lock-file/8977/5 describes exactly my use-case, essentially)

@weihanglo
Copy link
Member

Out of curiosity, why do you generate Cargo.lock on the fly, instead of checking it in the version control system?

@tnull
Copy link
Author

tnull commented May 9, 2025

Out of curiosity, why do you generate Cargo.lock on the fly, instead of checking it in the version control system?

For one, the projects this is referring to are all libraries, where we still adhere to the (by now somewhat relaxed) guidance to not check-in Cargo.lock. We also run cargo update as part of our CI to pin/unpin certain package versions, depending on whether we're testing under MSRV or not.

@epage
Copy link
Contributor

epage commented May 9, 2025

I can see having the lockfile-path more easily reused between multiple commands. As this flag is not expected to be commonly used, I wonder if we should remove --lockfile-path in favor of the config.

I think I would name the config resolver.lockfile-path (CARGO_RESOLVER_LOCKFILE_PATH). See also [resolver].

If this is put in the config, I wonder if we should support variable substitution like build-dir so its easier to set this once for all packages that make be interacted with when in this mode of operation.

@epage epage added the A-lockfile Area: Cargo.lock issues label May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lockfile Area: Cargo.lock issues C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

3 participants