cargo-add(1)
NAME
cargo-add - Add dependencies to a Cargo.toml manifest file
SYNOPSIS
cargo add [options] crate...
cargo add [options] --path path
cargo add [options] --git url [crate...]
DESCRIPTION
This command can add or modify dependencies.
The source for the dependency can be specified with:
- crate
@version: Fetch from a registry with a version constraint of "version" --pathpath: Fetch from the specified path--giturl: 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.
OPTIONS
Source options
--giturl- Git URL to add the specified crate from.
--branchbranch- Branch to use when adding from git.
--tagtag- Tag to use when adding from git.
--revsha- Specific commit to use when adding from git.
--pathpath- Filesystem path to local crate to add.
--registryregistry- Name of the registry to use. Registry names are defined in Cargo config
files. If not specified, the default registry is used,
which is defined by the
registry.defaultconfig key which defaults tocrates-io.
Section options
--dev- Add as a development dependency.
--build- Add as a build dependency.
--targettarget- Add as a dependency to the given target platform.
Dependency options
--renamename- Rename the dependency.
--optional- Mark the dependency as optional.
--no-optional- Mark the dependency as required.
--no-default-features- Disable the default features.
--default-features- Re-enable the default features.
--featuresfeatures- Space or comma separated list of features to
activate. When adding multiple
crates, the features for a specific crate may be enabled with
package-name/feature-namesyntax. This flag may be specified multiple times, which enables all specified features.
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.verboseconfig value. -q--quiet- Do not print cargo log messages.
May also be specified with the
term.quietconfig value. --colorwhen- 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.colorconfig value.
Manifest Options
--manifest-pathpath- Path to the
Cargo.tomlfile. By default, Cargo searches for theCargo.tomlfile in the current directory or any parent directory.
Common Options
+toolchain- If Cargo has been installed with rustup, and the first argument to
cargobegins with+, it will be interpreted as a rustup toolchain name (such as+stableor+nightly). See the rustup documentation for more information about how toolchain overrides work. --configKEY=VALUE- Overrides a Cargo configuration value.
-h--help- Prints help information.
-Zflag- Unstable (nightly-only) flags to Cargo. Run
cargo -Z helpfor details.
ENVIRONMENT
See the reference for details on environment variables that Cargo reads.
EXIT STATUS
0: Cargo succeeded.101: Cargo failed to complete.
EXAMPLES
-
Add
regexas a dependencycargo add regex -
Add
trybuildas a dev-dependencycargo add --dev trybuild -
Add an older version of
nomas a dependencycargo add nom@5 -
Add support for serializing data structures to json with
derivescargo add serde serde_json -F serde/derive