4.8 KiB
cargo-add(1)
{{~*set command="add"}} {{~*set actionverb="Add"}} {{~*set nouns="adds"}}
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" --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.
Upon successful invocation, the enabled (+
) and disabled (-
) features of the specified
dependency will be listed in the command's output.
OPTIONS
Source options
{{#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}}
Section 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}}
Dependency 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}}
{{/options}}
Display Options
{{#options}} {{> options-display }} {{/options}}
Manifest Options
{{#options}} {{> options-manifest-path }}
{{#option "-p
spec" "--package
spec" }}
Add dependencies to only the specified package.
{{/option}}
{{> options-ignore-rust-version }}
{{> options-locked }} {{/options}}
{{> section-options-common }}
{{> section-environment }}
{{> section-exit-status }}
EXAMPLES
-
Add
regex
as a dependencycargo add regex
-
Add
trybuild
as a dev-dependencycargo add --dev trybuild
-
Add an older version of
nom
as a dependencycargo add nom@5
-
Add support for serializing data structures to json with
derive
scargo add serde serde_json -F serde/derive
-
Add
windows
as a platform specific dependency oncfg(windows)
cargo add windows --target 'cfg(windows)'
SEE ALSO
{{man "cargo" 1}}, {{man "cargo-remove" 1}}