]> git.proxmox.com Git - cargo.git/blame - src/doc/man/cargo-add.md
Document cargo-add's feature message
[cargo.git] / src / doc / man / cargo-add.md
CommitLineData
f0ede38f
EP
1# cargo-add(1)
2{{*set actionverb="Add"}}
3{{*set nouns="adds"}}
4
5## NAME
6
7cargo-add - Add dependencies to a Cargo.toml manifest file
8
9## SYNOPSIS
10
11`cargo add` [_options_] _crate_...\
12`cargo add` [_options_] `--path` _path_\
13`cargo add` [_options_] `--git` _url_ [_crate_...]\
14
15
16## DESCRIPTION
17
18This command can add or modify dependencies.
19
20The source for the dependency can be specified with:
21
22* _crate_`@`_version_: Fetch from a registry with a version constraint of "_version_"
23* `--path` _path_: Fetch from the specified _path_
24* `--git` _url_: Pull from a git repo at _url_
25
26If no source is specified, then a best effort will be made to select one, including:
27
28* Existing dependencies in other tables (like `dev-dependencies`)
29* Workspace members
30* Latest release in the registry
31
32When you add a package that is already present, the existing entry will be updated with the flags specified.
33
9c8a8ea2
VL
34Upon successful invocation, the enabled (`+`) and disabled (`-`) [features] of the specified
35dependency will be listed in the command's output.
36
37[features]: ../reference/features.md
38
f0ede38f
EP
39## OPTIONS
40
41### Source options
42
43{{#options}}
44
45{{#option "`--git` _url_" }}
46[Git URL to add the specified crate from](../reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories).
47{{/option}}
48
49{{#option "`--branch` _branch_" }}
50Branch to use when adding from git.
51{{/option}}
52
53{{#option "`--tag` _tag_" }}
54Tag to use when adding from git.
55{{/option}}
56
57{{#option "`--rev` _sha_" }}
58Specific commit to use when adding from git.
59{{/option}}
60
61{{#option "`--path` _path_" }}
62[Filesystem path](../reference/specifying-dependencies.html#specifying-path-dependencies) to local crate to add.
63{{/option}}
64
65{{> options-registry }}
66
67{{/options}}
68
69### Section options
70
71{{#options}}
72
73{{#option "`--dev`" }}
74Add as a [development dependency](../reference/specifying-dependencies.html#development-dependencies).
75{{/option}}
76
77{{#option "`--build`" }}
78Add as a [build dependency](../reference/specifying-dependencies.html#build-dependencies).
79{{/option}}
80
81{{#option "`--target` _target_" }}
82Add as a dependency to the [given target platform](../reference/specifying-dependencies.html#platform-specific-dependencies).
83{{/option}}
84
85{{/options}}
86
87
88</dl>
89
90### Dependency options
91
92{{#options}}
93
94{{#option "`--rename` _name_" }}
95[Rename](../reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml) the dependency.
96{{/option}}
97
98{{#option "`--optional`" }}
99Mark the dependency as [optional](../reference/features.html#optional-dependencies).
100{{/option}}
101
102{{#option "`--no-optional`" }}
103Mark the dependency as [required](../reference/features.html#optional-dependencies).
104{{/option}}
105
106{{#option "`--no-default-features`" }}
107Disable the [default features](../reference/features.html#dependency-features).
108{{/option}}
109
110{{#option "`--default-features`" }}
111Re-enable the [default features](../reference/features.html#dependency-features).
112{{/option}}
113
114{{#option "`--features` _features_" }}
115Space or comma separated list of [features to
116activate](../reference/features.html#dependency-features). When adding multiple
117crates, the features for a specific crate may be enabled with
118`package-name/feature-name` syntax. This flag may be specified multiple times,
119which enables all specified features.
120{{/option}}
121
122{{/options}}
123
124
125### Display Options
126
127{{#options}}
128{{> options-display }}
129{{/options}}
130
131### Manifest Options
132
133{{#options}}
134{{> options-manifest-path }}
135{{/options}}
136
137{{> section-options-common }}
138
139{{> section-environment }}
140
141{{> section-exit-status }}
142
143## EXAMPLES
144
1451. Add `regex` as a dependency
146
147 cargo add regex
148
1492. Add `trybuild` as a dev-dependency
150
151 cargo add --dev trybuild
152
1533. Add an older version of `nom` as a dependency
154
155 cargo add nom@5
156
1574. Add support for serializing data structures to json with `derive`s
158
159 cargo add serde serde_json -F serde/derive
160
161## SEE ALSO
162{{man "cargo" 1}}