1CARGO-ADD(1)                General Commands Manual               CARGO-ADD(1)
2
3
4

NAME

6       cargo-add — Add dependencies to a Cargo.toml manifest file
7

SYNOPSIS

9       cargo add [options] crate
10       cargo add [options] --path path
11       cargo add [options] --git url [crate…]
12

DESCRIPTION

14       This command can add or modify dependencies.
15
16       The source for the dependency can be specified with:
17
18crate@version: Fetch from a registry with a version constraint of
19version
20
21--path path: Fetch from the specified path
22
23--git url: Pull from a git repo at url
24
25       If no source is specified, then a best effort will be made to select
26       one, including:
27
28       •  Existing dependencies in other tables (like dev-dependencies)
29
30       •  Workspace members
31
32       •  Latest release in the registry
33
34       When you add a package that is already present, the existing entry will
35       be updated with the flags specified.
36
37       Upon successful invocation, the enabled (+) and disabled (-) features
38       <https://doc.rust-lang.org/cargo/reference/features.md> of the
39       specified dependency will be listed in the command’s output.
40

OPTIONS

42   Source options
43       --git url
44           Git URL to add the specified crate from
45           <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories>.
46
47       --branch branch
48           Branch to use when adding from git.
49
50       --tag tag
51           Tag to use when adding from git.
52
53       --rev sha
54           Specific commit to use when adding from git.
55
56       --path path
57           Filesystem path
58           <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-path-dependencies>
59           to local crate to add.
60
61       --registry registry
62           Name of the registry to use. Registry names are defined in Cargo
63           config files
64           <https://doc.rust-lang.org/cargo/reference/config.html>. If not
65           specified, the default registry is used, which is defined by the
66           registry.default config key which defaults to crates-io.
67
68   Section options
69       --dev
70           Add as a development dependency
71           <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#development-dependencies>.
72
73       --build
74           Add as a build dependency
75           <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#build-dependencies>.
76
77       --target target
78           Add as a dependency to the given target platform
79           <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#platform-specific-dependencies>.
80
81           To avoid unexpected shell expansions, you may use quotes around
82           each target, e.g., --target 'cfg(unix)'.
83
84   Dependency options
85       --dry-run
86           Don’t actually write the manifest
87
88       --rename name
89           Rename
90           <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml>
91           the dependency.
92
93       --optional
94           Mark the dependency as optional
95           <https://doc.rust-lang.org/cargo/reference/features.html#optional-dependencies>.
96
97       --no-optional
98           Mark the dependency as required
99           <https://doc.rust-lang.org/cargo/reference/features.html#optional-dependencies>.
100
101       --no-default-features
102           Disable the default features
103           <https://doc.rust-lang.org/cargo/reference/features.html#dependency-features>.
104
105       --default-features
106           Re-enable the default features
107           <https://doc.rust-lang.org/cargo/reference/features.html#dependency-features>.
108
109       -F features, --features features
110           Space or comma separated list of features to activate
111           <https://doc.rust-lang.org/cargo/reference/features.html#dependency-features>.
112           When adding multiple crates, the features for a specific crate may
113           be enabled with package-name/feature-name syntax. This flag may be
114           specified multiple times, which enables all specified features.
115
116       --ignore-rust-version
117           Ignore rust-version specification in packages.
118
119           This option is unstable and available only on the nightly channel
120           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
121           requires the -Z unstable-options flag to enable. See
122           <https://github.com/rust-lang/cargo/issues/5579> for more
123           information.
124
125   Display Options
126       -v, --verbose
127           Use verbose output. May be specified twice for “very verbose”
128           output which includes extra output such as dependency warnings and
129           build script output. May also be specified with the term.verbose
130           config value
131           <https://doc.rust-lang.org/cargo/reference/config.html>.
132
133       -q, --quiet
134           Do not print cargo log messages. May also be specified with the
135           term.quiet config value
136           <https://doc.rust-lang.org/cargo/reference/config.html>.
137
138       --color when
139           Control when colored output is used. Valid values:
140
141auto (default): Automatically detect if color support is
142               available on the terminal.
143
144always: Always display colors.
145
146never: Never display colors.
147
148           May also be specified with the term.color config value
149           <https://doc.rust-lang.org/cargo/reference/config.html>.
150
151   Manifest Options
152       --manifest-path path
153           Path to the Cargo.toml file. By default, Cargo searches for the
154           Cargo.toml file in the current directory or any parent directory.
155
156       -p spec, --package spec
157           Add dependencies to only the specified package.
158
159       --frozen, --locked
160           Either of these flags requires that the Cargo.lock file is
161           up-to-date. If the lock file is missing, or it needs to be updated,
162           Cargo will exit with an error. The --frozen flag also prevents
163           Cargo from attempting to access the network to determine if it is
164           out-of-date.
165
166           These may be used in environments where you want to assert that the
167           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
168           network access.
169
170       --offline
171           Prevents Cargo from accessing the network for any reason. Without
172           this flag, Cargo will stop with an error if it needs to access the
173           network and the network is not available. With this flag, Cargo
174           will attempt to proceed without the network if possible.
175
176           Beware that this may result in different dependency resolution than
177           online mode. Cargo will restrict itself to crates that are
178           downloaded locally, even if there might be a newer version as
179           indicated in the local copy of the index. See the cargo-fetch(1)
180           command to download dependencies before going offline.
181
182           May also be specified with the net.offline config value
183           <https://doc.rust-lang.org/cargo/reference/config.html>.
184
185   Common Options
186       +toolchain
187           If Cargo has been installed with rustup, and the first argument to
188           cargo begins with +, it will be interpreted as a rustup toolchain
189           name (such as +stable or +nightly). See the rustup documentation
190           <https://rust-lang.github.io/rustup/overrides.html> for more
191           information about how toolchain overrides work.
192
193       --config KEY=VALUE or PATH
194           Overrides a Cargo configuration value. The argument should be in
195           TOML syntax of KEY=VALUE, or provided as a path to an extra
196           configuration file. This flag may be specified multiple times. See
197           the command-line overrides section
198           <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
199           for more information.
200
201       -C PATH
202           Changes the current working directory before executing any
203           specified operations. This affects things like where cargo looks by
204           default for the project manifest (Cargo.toml), as well as the
205           directories searched for discovering .cargo/config.toml, for
206           example. This option must appear before the command name, for
207           example cargo -C path/to/my-project build.
208
209           This option is only available on the nightly channel
210           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
211           requires the -Z unstable-options flag to enable (see #10098
212           <https://github.com/rust-lang/cargo/issues/10098>).
213
214       -h, --help
215           Prints help information.
216
217       -Z flag
218           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
219           details.
220

ENVIRONMENT

222       See the reference
223       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
224       for details on environment variables that Cargo reads.
225

EXIT STATUS

2270: Cargo succeeded.
228
229101: Cargo failed to complete.
230

EXAMPLES

232        1. Add regex as a dependency
233
234               cargo add regex
235
236        2. Add trybuild as a dev-dependency
237
238               cargo add --dev trybuild
239
240        3. Add an older version of nom as a dependency
241
242               cargo add nom@5
243
244        4. Add support for serializing data structures to json with derives
245
246               cargo add serde serde_json -F serde/derive
247
248        5. Add windows as a platform specific dependency on cfg(windows)
249
250               cargo add windows --target 'cfg(windows)'
251

SEE ALSO

253       cargo(1), cargo-remove(1)
254
255
256
257                                                                  CARGO-ADD(1)
Impressum