CARGO-FETCH(1)

πŸ“¦ version 1.95.0, in ubuntu stonking

πŸ’– 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 the term.verbose config 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 the term.quiet config 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 the Cargo.toml file. By default, Cargo searches for the Cargo.toml file 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 existing Cargo.lock file 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 --locked and --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 +stable or +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 of KEY=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 example cargo -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. Run cargo -Z help for 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 🌸

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