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
--ignore-rust-version
This option is unstable and available only 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 <https://github.com/rust-lang/cargo/issues/5579> for more information.
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
--frozen, --locked
These may be used in environments where you want to assert that the Cargo.lock file is up-to-date (such as a CI build) or want to avoid network access.
--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>.
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)'