table of contents
CARGO-ADD(1) | General Commands Manual | 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:
If no source is specified, then a best effort will be made to select one, including:
When you add a package that is already present, the existing entry will be updated with the flags specified.
Upon successful invocation, the enabled (+) and disabled (-) features <https://doc.rust-lang.org/cargo/reference/features.html> of the specified dependency will be listed in the command’s output.
OPTIONS¶
Source options¶
--git url
--branch branch
--tag tag
--rev sha
--path path
--registry registry
Section options¶
--dev
--build
--target target
To avoid unexpected shell expansions, you may use quotes around each target, e.g., --target 'cfg(unix)'.
Dependency options¶
--dry-run
--rename name
--optional
--no-optional
--public
The dependency can be referenced in your library’s public API.
Unstable (nightly-only) <https://doc.rust-lang.org/cargo/reference/unstable.html#public-dependency>
--no-public
While you can use the crate in your implementation, it cannot be referenced in your public API.
Unstable (nightly-only) <https://doc.rust-lang.org/cargo/reference/unstable.html#public-dependency>
--no-default-features
--default-features
-F features, --features features
Display Options¶
-v, --verbose
-q, --quiet
--color when
May also be specified with the term.color config value <https://doc.rust-lang.org/cargo/reference/config.html>.
Manifest Options¶
--manifest-path path
-p spec, --package spec
--ignore-rust-version
--locked
It may be used in environments where deterministic builds are desired, such as in CI pipelines.
--offline
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
--lockfile-path PATH
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 #14421 <https://github.com/rust-lang/cargo/issues/14421>).
Common Options¶
+toolchain
--config KEY=VALUE or PATH
-C PATH
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
-Z flag
ENVIRONMENT¶
See the reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for details on environment variables that Cargo reads.
EXIT STATUS¶
EXAMPLES¶
cargo add regex
cargo add --dev trybuild
cargo add nom@5
cargo add serde serde_json -F serde/derive
cargo add windows --target 'cfg(windows)'