1CARGO-ADD(1) General Commands Manual CARGO-ADD(1)
2
3
4
6 cargo-add - Add dependencies to a Cargo.toml manifest file
7
9 cargo add [options] crate...
10 cargo add [options] --path path
11 cargo add [options] --git url [crate...]
12
14 This command can add or modify dependencies.
15
16 The source for the dependency can be specified with:
17
18 • crate@version: Fetch from a registry with a version constraint of
19 "version"
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
38 Source options
39 --git url
40 Git URL to add the specified crate from
41 <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories>.
42
43 --branch branch
44 Branch to use when adding from git.
45
46 --tag tag
47 Tag to use when adding from git.
48
49 --rev sha
50 Specific commit to use when adding from git.
51
52 --path path
53 Filesystem path
54 <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-path-dependencies>
55 to local crate to add.
56
57 --registry registry
58 Name of the registry to use. Registry names are defined in Cargo
59 config files
60 <https://doc.rust-lang.org/cargo/reference/config.html>. If not
61 specified, the default registry is used, which is defined by the
62 registry.default config key which defaults to crates-io.
63
64 Section options
65 --dev
66 Add as a development dependency
67 <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#development-dependencies>.
68
69 --build
70 Add as a build dependency
71 <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#build-dependencies>.
72
73 --target target
74 Add as a dependency to the given target platform
75 <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#platform-specific-dependencies>.
76 </dl>
77
78 Dependency options
79 --rename name
80 Rename
81 <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml>
82 the dependency.
83
84 --optional
85 Mark the dependency as optional
86 <https://doc.rust-lang.org/cargo/reference/features.html#optional-dependencies>.
87
88 --no-optional
89 Mark the dependency as required
90 <https://doc.rust-lang.org/cargo/reference/features.html#optional-dependencies>.
91
92 --no-default-features
93 Disable the default features
94 <https://doc.rust-lang.org/cargo/reference/features.html#dependency-features>.
95
96 --default-features
97 Re-enable the default features
98 <https://doc.rust-lang.org/cargo/reference/features.html#dependency-features>.
99
100 --features features
101 Space or comma separated list of features to activate
102 <https://doc.rust-lang.org/cargo/reference/features.html#dependency-features>.
103 When adding multiple crates, the features for a specific crate may
104 be enabled with package-name/feature-name syntax. This flag may be
105 specified multiple times, which enables all specified features.
106
107 Display Options
108 -v, --verbose
109 Use verbose output. May be specified twice for "very verbose"
110 output which includes extra output such as dependency warnings and
111 build script output. May also be specified with the term.verbose
112 config value
113 <https://doc.rust-lang.org/cargo/reference/config.html>.
114
115 -q, --quiet
116 Do not print cargo log messages. May also be specified with the
117 term.quiet config value
118 <https://doc.rust-lang.org/cargo/reference/config.html>.
119
120 --color when
121 Control when colored output is used. Valid values:
122
123 • auto (default): Automatically detect if color support is
124 available on the terminal.
125
126 • always: Always display colors.
127
128 • never: Never display colors.
129
130 May also be specified with the term.color config value
131 <https://doc.rust-lang.org/cargo/reference/config.html>.
132
133 Manifest Options
134 --manifest-path path
135 Path to the Cargo.toml file. By default, Cargo searches for the
136 Cargo.toml file in the current directory or any parent directory.
137
138 Common Options
139 +toolchain
140 If Cargo has been installed with rustup, and the first argument to
141 cargo begins with +, it will be interpreted as a rustup toolchain
142 name (such as +stable or +nightly). See the rustup documentation
143 <https://rust-lang.github.io/rustup/overrides.html> for more
144 information about how toolchain overrides work.
145
146 -h, --help
147 Prints help information.
148
149 -Z flag
150 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
151 details.
152
154 See the reference
155 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
156 for details on environment variables that Cargo reads.
157
159 • 0: Cargo succeeded.
160
161 • 101: Cargo failed to complete.
162
164 1. Add regex as a dependency
165
166 cargo add regex
167
168 2. Add trybuild as a dev-dependency
169
170 cargo add --dev trybuild
171
172 3. Add an older version of nom as a dependency
173
174 cargo add nom@5
175
176 4. Add support for serializing data structures to json with derives
177
178 cargo add serde serde_json -F serde/derive
179
181 cargo(1)
182
183
184
185 CARGO-ADD(1)