Disable registry update in Cargo
If you look at the documentation for configuring Cargo, you'll note there is an index
key in the [registry]
section. This can be any path to a Git repository.
As such, you can make a local clone of the crates.io index. I verified this by cloning it like so:
git clone --bare https://github.com/rust-lang/crates.io-index.git
then editing my Cargo configuration (specifically, I changed ~/.cargo/config
, but this should work anywhere the documentation describes) to contain:
[registry]
index = "file:///F:/Data/Repositories/crates.io-index.git"
A few things to note:
This does not mirror the actual contents of the packages. Those come from a different host. I do not know how to mirror those, however: Cargo is much better about caching those locally. It should be enough to
cargo fetch
packages, then copy the cached*.crate
files in$HOME/.cargo/registry/cache/*
.This causes the package identifiers in your
Cargo.lock
file to change. This isn't a problem for developing libraries, but it does become a problem for binaries. Standard practice is to check yourCargo.lock
into source control for binaries so that everyone downstream builds with the exact same package versions. However, the modified index means no one else will be able to build the package with that lock file in place.I've worked around this by placing another config override within binary packages that resets the index to the "official" one, but that may not even be possible in your situation. In that case, you may need to either exclude
Cargo.lock
from source control, or just have a "doesn't use the official index" branch.