4 cargo-add - Add dependencies to a Cargo.toml manifest file
7 cargo add [options] crate...
8 cargo add [options] --path path
9 cargo add [options] --git url [crate...]
12 This command can add or modify dependencies.
14 The source for the dependency can be specified with:
16 o crate@version: Fetch from a registry with a version constraint of
19 o --path path: Fetch from the specified path
21 o --git url: Pull from a git repo at url
23 If no source is specified, then a best effort will be made to select
26 o Existing dependencies in other tables (like dev-dependencies)
30 o Latest release in the registry
32 When you add a package that is already present, the existing entry will
33 be updated with the flags specified.
35 Upon successful invocation, the enabled (+) and disabled (-) features
36 <https://doc.rust-lang.org/cargo/reference/features.md> of the specified
37 dependency will be listed in the command's output.
42 Git URL to add the specified crate from
43 <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories>.
46 Branch to use when adding from git.
49 Tag to use when adding from git.
52 Specific commit to use when adding from git.
56 <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-path-dependencies>
57 to local crate to add.
60 Name of the registry to use. Registry names are defined in Cargo
62 <https://doc.rust-lang.org/cargo/reference/config.html>. If not
63 specified, the default registry is used, which is defined by the
64 registry.default config key which defaults to crates-io.
68 Add as a development dependency
69 <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#development-dependencies>.
72 Add as a build dependency
73 <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#build-dependencies>.
76 Add as a dependency to the given target platform
77 <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#platform-specific-dependencies>.
84 <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml>
88 Mark the dependency as optional
89 <https://doc.rust-lang.org/cargo/reference/features.html#optional-dependencies>.
92 Mark the dependency as required
93 <https://doc.rust-lang.org/cargo/reference/features.html#optional-dependencies>.
96 Disable the default features
97 <https://doc.rust-lang.org/cargo/reference/features.html#dependency-features>.
100 Re-enable the default features
101 <https://doc.rust-lang.org/cargo/reference/features.html#dependency-features>.
104 Space or comma separated list of features to activate
105 <https://doc.rust-lang.org/cargo/reference/features.html#dependency-features>.
106 When adding multiple crates, the features for a specific crate may
107 be enabled with package-name/feature-name syntax. This flag may be
108 specified multiple times, which enables all specified features.
112 Use verbose output. May be specified twice for "very verbose" output
113 which includes extra output such as dependency warnings and build
114 script output. May also be specified with the term.verbose config
115 value <https://doc.rust-lang.org/cargo/reference/config.html>.
118 Do not print cargo log messages. May also be specified with the
119 term.quiet config value
120 <https://doc.rust-lang.org/cargo/reference/config.html>.
123 Control when colored output is used. Valid values:
125 o auto (default): Automatically detect if color support is
126 available on the terminal.
128 o always: Always display colors.
130 o never: Never display colors.
132 May also be specified with the term.color config value
133 <https://doc.rust-lang.org/cargo/reference/config.html>.
137 Path to the Cargo.toml file. By default, Cargo searches for the
138 Cargo.toml file in the current directory or any parent directory.
142 If Cargo has been installed with rustup, and the first argument to
143 cargo begins with +, it will be interpreted as a rustup toolchain
144 name (such as +stable or +nightly). See the rustup documentation
145 <https://rust-lang.github.io/rustup/overrides.html> for more
146 information about how toolchain overrides work.
149 Overrides a Cargo configuration value.
152 Prints help information.
155 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
160 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
161 for details on environment variables that Cargo reads.
164 o 0: Cargo succeeded.
166 o 101: Cargo failed to complete.
169 1. Add regex as a dependency
173 2. Add trybuild as a dev-dependency
175 cargo add --dev trybuild
177 3. Add an older version of nom as a dependency
181 4. Add support for serializing data structures to json with derives
183 cargo add serde serde_json -F serde/derive