CARGO-FETCH(1)
π NAME π
cargo-fetch β bestie, it fetches the dependencies of a package from the network π¦
(also hiii this is from the General Commands Manual section of the manual, iykyk π )
β¨ SYNOPSIS β¨
cargo fetch [options]
πΈ DESCRIPTION πΈ
Okay so here's the tea β β if a Cargo.lock file is available, this command will make sure that all of the git dependencies and/or registry dependencies are downloaded and locally available. And the slay part? Subsequent Cargo commands will be able to run offline after a cargo fetch unless the lock file changes. Iconic behavior honestly.
If the lock file is not available, then this command will generate the lock file before fetching the dependencies. No lock file, no problem, it just makes one π
If --target is not specified, then all target dependencies are fetched. All of them. Every single one. Periodt.
Also see the cargo-prefetch plugin at https://crates.io/crates/cargo-prefetch which adds a command to download popular crates. This may be useful if you plan to use Cargo without a network with the --offline flag. Little tip from the ancestors, take it π«Ά
π OPTIONS π
π Fetch options
--target tripleβ Fetch for the specified target architecture. This flag may be specified multiple times (yes, multiple, go off). The default is all architectures. The general format of the triple is<arch><sub>-<vendor>-<sys>-<abi>.
Possible values:
- Any supported target in
rustc --print target-list. "host-tuple", which will internally be substituted by the host's target. This can be particularly useful if you're cross-compiling some crates, and don't want to specify your host's machine as a target (for instance, an xtask in a shared project that may be worked on by many hosts).- A path to a custom target specification. See Custom Target Lookup Path at https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-path for more information.
This may also be specified with the build.target config value at https://doc.rust-lang.org/cargo/reference/config.html.
β οΈ Note that specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. See the build cache documentation at https://doc.rust-lang.org/cargo/reference/build-cache.html for more details. Don't say nobody warned you π
π Display Options
-v, --verboseβ Use verbose output. May be specified twice for "very verbose" output, which includes extra output such as dependency warnings and build script output. May also be specified with theterm.verboseconfig value at https://doc.rust-lang.org/cargo/reference/config.html. Double it and give it to the next person π-q, --quietβ Do not print cargo log messages. May also be specified with theterm.quietconfig value at https://doc.rust-lang.org/cargo/reference/config.html. Shhhh π€«--color whenβ Control when colored output is used. Valid values:auto(default): Automatically detect if color support is available on the terminal.always: Always display colors.never: Never display colors.
May also be specified with the term.color config value at https://doc.rust-lang.org/cargo/reference/config.html. Aesthetics are configurable, as they should be π
π¦ Manifest Options
--manifest-path pathβ Path to theCargo.tomlfile. By default, Cargo searches for theCargo.tomlfile in the current directory or any parent directory. It's giving "I'll find it myself" π΅οΈ--lockedβ Asserts that the exact same dependencies and versions are used as when the existingCargo.lockfile was originally generated. Cargo will exit with an error when either of the following scenarios arises:- The lock file is missing.
- Cargo attempted to change the lock file due to a different dependency resolution.
It may be used in environments where deterministic builds are desired, such as in CI pipelines. Locked in, literally π
--offlineβ Prevents Cargo from accessing the network for any reason. Without this flag, Cargo will stop with an error if it needs to access the network and the network is not available. With this flag, Cargo will attempt to proceed without the network if possible.
β οΈ Beware that this may result in different dependency resolution than online mode. Cargo will restrict itself to crates that are downloaded locally, even if there might be a newer version as indicated in the local copy of the index. Not a bug, just the vibe check failing π
May also be specified with the net.offline config value at https://doc.rust-lang.org/cargo/reference/config.html.
--frozenβ Equivalent to specifying both--lockedand--offline. Two-for-one combo, we love a bundle deal π
π Common Options
+toolchainβ If Cargo has been installed with rustup, and the first argument to cargo begins with+, it will be interpreted as a rustup toolchain name (such as+stableor+nightly). See the rustup documentation at https://rust-lang.github.io/rustup/overrides.html for more information about how toolchain overrides work. Main character toolchain selection β¨--config KEY=VALUE or PATHβ Overrides a Cargo configuration value. The argument should be in TOML syntax ofKEY=VALUE, or provided as a path to an extra configuration file. This flag may be specified multiple times. See the command-line overrides section at https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides for more information.-C PATHβ Changes the current working directory before executing any specified operations. This affects things like where cargo looks by default for the project manifest (Cargo.toml), as well as the directories searched for discovering.cargo/config.toml, for example. This option must appear before the command name, for examplecargo -C path/to/my-project build.
β οΈ This option is only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the -Z unstable-options flag to enable (see #10098 at https://github.com/rust-lang/cargo/issues/10098). Nightly only besties, don't come crying to me π₯²
-h, --helpβ Prints help information. Your emergency bestie when everything is confusing π«Ά-Z flagβ Unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor details. Chaos mode, unlocked π₯
π§ ENVIRONMENT π§
See the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for details on environment variables that Cargo reads. It's all in there, go read it, I believe in you π
β EXIT STATUS β
0: Cargo succeeded. We ate and left no crumbs π101: Cargo failed to complete. It's giving flop, unfortunately π
πΈ EXAMPLES πΈ
- Fetch all dependencies:
cargo fetch
That's it. That's the whole example. Simple, clean, iconic π
π SEE ALSO π
cargo(1), cargo-update(1), cargo-generate-lockfile(1)
and that's the whole page bestie!! πβ¨π¦πΈππππ
This lil masterpiece lives under the name CARGO-FETCH(1) in the General Commands Manual β yeah, the same name at the top and the bottom, they really said symmetry β¨ β so if you ever need to find it again, that's the glow-up label it's filed under. Love that for us. Byeee π«Άπ
π¦ where this page comes from
- ubuntu stonking: cargo-1.97 1.97.1+dfsg-0ubuntu1 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms