Disable registry update in Cargo

假装没事ソ 提交于 2019-11-30 17:50:49

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:

  1. 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/*.

  2. 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 your Cargo.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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!