CARGO-ADD(1)

πŸ“¦ version 1.79.0, in ubuntu jammy, ubuntu noble

okay bestie, welcome to the cargo-add(1) page from the General Commands Manual β€” it's literally here to help you add deps to a Cargo.toml manifest file, and it ate πŸ’…

✨ NAME ✨

cargo-add β€” add dependencies to a Cargo.toml manifest file. no cap, that's the whole point 🫢

πŸ’– SYNOPSIS πŸ’–

the vibes in command form:

cargo add [options] crate…
cargo add [options] --path path
cargo add [options] --git url [crate…]

🌸 DESCRIPTION 🌸

this command can add or modify dependencies. yes, both. it's giving multitasking queen πŸ‘‘

the source for the dependency can be specified with:

  • crate@version: fetch from a registry with a version constraint of version
  • --path path: fetch from the specified path
  • --git url: pull from a git repo at url

if no source is specified, then a best effort will be made to select one, including:

  • existing dependencies in other tables (like dev-dependencies)
  • workspace members
  • latest release in the registry

when you add a package that is already present, the existing entry will be updated with the flags specified. periodt.

upon successful invocation, the enabled (+) and disabled (-) features (the whole https://doc.rust-lang.org/cargo/reference/features.html situation) of the specified dependency will be listed in the command’s output. iconic behavior, honestly ✨

πŸ‘‘ OPTIONS πŸ‘‘

okay here's the full menu, bestie. every flag, every value, no skips πŸ’–

πŸŽ€ Source options πŸŽ€

πŸ¦‹ Section options πŸ¦‹

πŸ“ Dependency options πŸ“

✨ Display Options ✨

πŸ’œ 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.
  • -p spec, --package spec β€” Add dependencies to only the specified package.
  • --ignore-rust-version β€” Ignore rust-version specification in packages.
  • --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.
  • --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. See the cargo-fetch(1) command to download dependencies before going offline. May also be specified with the net.offline config value (https://doc.rust-lang.org/cargo/reference/config.html).
  • --frozen β€” Equivalent to specifying both --locked and --offline.

🌈 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 (https://rust-lang.github.io/rustup/overrides.html) for more information about how toolchain overrides work.
  • --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 (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 https://github.com/rust-lang/cargo/issues/10098).
  • -h, --help β€” Prints help information.
  • -Z flag β€” Unstable (nightly-only) flags to Cargo. Run cargo -Z help for details.

🌱 ENVIRONMENT 🌱

See the reference (https://doc.rust-lang.org/cargo/reference/environment-variables.html) for details on environment variables that Cargo reads. iykyk 🌈

πŸ’€ EXIT STATUS πŸ’€

  • 0: Cargo succeeded.
  • 101: Cargo failed to complete.

πŸ”₯ EXAMPLES πŸ”₯

  1. Add regex as a dependency
cargo add regex
  1. Add trybuild as a dev-dependency
cargo add --dev trybuild
  1. Add an older version of nom as a dependency
cargo add nom@5
  1. Add support for serializing data structures to json with derives
cargo add serde serde_json -F serde/derive
  1. Add windows as a platform specific dependency on cfg(windows)
cargo add windows --target 'cfg(windows)'

πŸ‘― SEE ALSO πŸ‘―

cargo(1), cargo-remove(1)


that's the whole CARGO-ADD(1) page from the General Commands Manual, bestie β€” go add those deps and slay βœ¨πŸ’…

πŸ“¦ where this page comes from