]>
Commit | Line | Data |
---|---|---|
f0ede38f EP |
1 | # cargo-add(1) |
2 | {{*set actionverb="Add"}} | |
3 | {{*set nouns="adds"}} | |
4 | ||
5 | ## NAME | |
6 | ||
7 | cargo-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 | ||
18 | This command can add or modify dependencies. | |
19 | ||
20 | The 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 | ||
26 | If 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 | ||
32 | When you add a package that is already present, the existing entry will be updated with the flags specified. | |
33 | ||
9c8a8ea2 VL |
34 | Upon successful invocation, the enabled (`+`) and disabled (`-`) [features] of the specified |
35 | dependency 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_" }} | |
50 | Branch to use when adding from git. | |
51 | {{/option}} | |
52 | ||
53 | {{#option "`--tag` _tag_" }} | |
54 | Tag to use when adding from git. | |
55 | {{/option}} | |
56 | ||
57 | {{#option "`--rev` _sha_" }} | |
58 | Specific 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`" }} | |
74 | Add as a [development dependency](../reference/specifying-dependencies.html#development-dependencies). | |
75 | {{/option}} | |
76 | ||
77 | {{#option "`--build`" }} | |
78 | Add as a [build dependency](../reference/specifying-dependencies.html#build-dependencies). | |
79 | {{/option}} | |
80 | ||
81 | {{#option "`--target` _target_" }} | |
82 | Add 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`" }} | |
99 | Mark the dependency as [optional](../reference/features.html#optional-dependencies). | |
100 | {{/option}} | |
101 | ||
102 | {{#option "`--no-optional`" }} | |
103 | Mark the dependency as [required](../reference/features.html#optional-dependencies). | |
104 | {{/option}} | |
105 | ||
106 | {{#option "`--no-default-features`" }} | |
107 | Disable the [default features](../reference/features.html#dependency-features). | |
108 | {{/option}} | |
109 | ||
110 | {{#option "`--default-features`" }} | |
111 | Re-enable the [default features](../reference/features.html#dependency-features). | |
112 | {{/option}} | |
113 | ||
114 | {{#option "`--features` _features_" }} | |
115 | Space or comma separated list of [features to | |
116 | activate](../reference/features.html#dependency-features). When adding multiple | |
117 | crates, the features for a specific crate may be enabled with | |
118 | `package-name/feature-name` syntax. This flag may be specified multiple times, | |
119 | which 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 | ||
145 | 1. Add `regex` as a dependency | |
146 | ||
147 | cargo add regex | |
148 | ||
149 | 2. Add `trybuild` as a dev-dependency | |
150 | ||
151 | cargo add --dev trybuild | |
152 | ||
153 | 3. Add an older version of `nom` as a dependency | |
154 | ||
155 | cargo add nom@5 | |
156 | ||
157 | 4. 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}} |