Specifying the location of the Cargo.lock file

Is there a way (flag, environment variable) to force cargo to look for/generate the Cargo.lock file somewhere othern than the default location - the crate's root? Something similar to how CARGO_TARGET_DIR specifies the location of the output directory. This would be very useful to integrate into an existing build system which expects the source tree to remain intact during a build.

Don't believe so. Even if there was, it'd be a bit weird given that, for binaries at least, Cargo.lock is part of the source tree. Having Cargo look in multiple places simultaneously also feels like a bad idea.

See the --frozen and --locked flags if you want to ensure the tree is not modified during a build.

1 Like

It should be part of all source trees nowadays, as it allows for repeatable builds.

I'm actually interested in this kind of functionality. Using the following command for example wouldn't work for building a library (where the Cargo.lock should not be in the versioning system).

cd /path/to/my/rust/crate/
docker run --volume "${PWD}:/tmp/workspace:ro" --workdir "/tmp/workspace" rust:latest cargo test

Notice how I did mount the volume with the READ-ONLY rights because I do not want to pollute the host with new files.

I believe the original question is perfectly valid but was never really answered.