{{*set command="add"}}
{{*set actionverb="Add"}}
{{~*set nouns="adds"}}
cargo-add --- Add dependencies to a Cargo.toml manifest file
cargo add [options] crate...
cargo add [options] --path path
cargo add [options] --git url [crate...]
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.
Upon successful invocation, the enabled (+) and disabled (-) features of the specified
dependency will be listed in the command's output.
{{#options}}
{{#option "--git url" }}
Git URL to add the specified crate from.
{{/option}}
{{#option "--branch branch" }}
Branch to use when adding from git.
{{/option}}
{{#option "--tag tag" }}
Tag to use when adding from git.
{{/option}}
{{#option "--rev sha" }}
Specific commit to use when adding from git.
{{/option}}
{{#option "--path path" }}
Filesystem path to local crate to add.
{{/option}}
{{> options-registry }}
{{/options}}
{{#options}}
{{#option "--dev" }}
Add as a development dependency.
{{/option}}
{{#option "--build" }}
Add as a build dependency.
{{/option}}
{{#option "--target target" }}
Add as a dependency to the given target platform.
To avoid unexpected shell expansions, you may use quotes around each target, e.g., --target 'cfg(unix)'.
{{/option}}
{{/options}}
{{#options}}
{{#option "--dry-run" }}
Don't actually write the manifest
{{/option}}
{{#option "--rename name" }}
Rename the dependency.
{{/option}}
{{#option "--optional" }}
Mark the dependency as optional.
{{/option}}
{{#option "--no-optional" }}
Mark the dependency as required.
{{/option}}
{{#option "--public" }}
Mark the dependency as public.
The dependency can be referenced in your library's public API.
Unstable (nightly-only) {{/option}}
{{#option "--no-public" }}
Mark the dependency as private.
While you can use the crate in your implementation, it cannot be referenced in your public API.
Unstable (nightly-only) {{/option}}
{{#option "--no-default-features" }}
Disable the default features.
{{/option}}
{{#option "--default-features" }}
Re-enable the default features.
{{/option}}
{{#option "-F features" "--features features" }}
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-name syntax. This flag may be specified multiple times,
which enables all specified features.
{{/option}}
{{#option "--ignore-rust-version" }}
Ignore rust-version specification in packages.
{{/option}}
{{/options}}
{{#options}} {{> options-display }} {{/options}}
{{#options}} {{> options-manifest-path }}
{{#option "-p spec" "--package spec" }}
Add dependencies to only the specified package.
{{/option}}
{{> options-locked }} {{/options}}
{{> section-options-common }}
{{> section-environment }}
{{> section-exit-status }}
-
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 -
Add
windowsas a platform specific dependency oncfg(windows)cargo add windows --target 'cfg(windows)'
{{man "cargo" 1}}, {{man "cargo-remove" 1}}