$ cargo new hello_world Cargo defaults to --bin to make a binary program. To make a library, we would pass --lib, instead. Let’s check out what Cargo has generated for us: $ cd hello_world $ tree . . ├── Cargo.toml └── src └── main.rs 1 directory, 2 files This is all we need to get started. First, let’s check out Cargo.toml:
The --frozen flag also prevents Cargo from attempting to access the network to determine if it is out-of-date. These may be used in environments where you want to assert that the Cargo.lock file is up-to-date (such as a CI build) or want to avoid network access.--offline Prevents Cargo from accessing the network for any reason. Without this ...
As of Rust 1.41.0, you can use the following command to update crates to their latest version:
cargo install <crate>
This came from pull request #6798 (Add install-upgrade) and was stabilized in #7560 (Stabilize install-upgrade).
Instead of failing when detects a package is already installed, it will upgrade if the versions don't match, or do nothing (exit 0) if it is considered "up-to-date".cargo install
The following command will always uninstall, download and compile the latest version of the crate - even if there's no newer version available. Under normal circumstances the feature should be preferred as it does save time and bandwidth if there's no new version of the crate.install-upgrade
cargo install --force <crate>
Further information can be found in the GitHub issue rust-lang/cargo#6797 and in the official documentation chapter.
I believe that file is just for the built-in libraries, i.e. those distributed with manifest. rustc itself stores things in cargo (for the moment), if you do wish to just remove all the libraries then deleting that directory won't break anything.~/.cargo
If you're just wanting to rebuild/update dependencies you can run cargo.cargo update
If you look at the documentation for configuring Cargo, you'll note there is an key in the index section. This can be any path to a Git repository.[registry]
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 , but this should work anywhere the documentation describes) to contain:~/.cargo/config
[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 packages, then copy the cached cargo fetch files in *.crate.$HOME/.cargo/registry/cache/*
This causes the package identifiers in your 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.Cargo.lock
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 from source control, or just have a "doesn't use the official index" branch.Cargo.lock