]> git.proxmox.com Git - cargo.git/blame - src/doc/src/commands/cargo-doc.md
Merge branch 'debian/sid' into proxmox/bullseye
[cargo.git] / src / doc / src / commands / cargo-doc.md
CommitLineData
2d4aa38b
EH
1# cargo-doc(1)
2
3
3e177e0f 4
2d4aa38b
EH
5## NAME
6
7cargo-doc - Build a package's documentation
8
9## SYNOPSIS
10
11`cargo doc` [_options_]
12
13## DESCRIPTION
14
15Build the documentation for the local package and all dependencies. The output
16is placed in `target/doc` in rustdoc's usual format.
17
18## OPTIONS
19
20### Documentation Options
21
22<dl>
23
24<dt class="option-term" id="option-cargo-doc---open"><a class="option-anchor" href="#option-cargo-doc---open"></a><code>--open</code></dt>
25<dd class="option-desc">Open the docs in a browser after building them. This will use your default
6128b54b
J
26browser unless you define another one in the <code>BROWSER</code> environment variable
27or use the <a href="../reference/config.html#docbrowser"><code>doc.browser</code></a> configuration
28option.</dd>
2d4aa38b
EH
29
30
31<dt class="option-term" id="option-cargo-doc---no-deps"><a class="option-anchor" href="#option-cargo-doc---no-deps"></a><code>--no-deps</code></dt>
32<dd class="option-desc">Do not build documentation for dependencies.</dd>
33
34
35<dt class="option-term" id="option-cargo-doc---document-private-items"><a class="option-anchor" href="#option-cargo-doc---document-private-items"></a><code>--document-private-items</code></dt>
61282336 36<dd class="option-desc">Include non-public items in the documentation. This will be enabled by default if documenting a binary target.</dd>
2d4aa38b
EH
37
38
39</dl>
40
41### Package Selection
42
43By default, when no package selection options are given, the packages selected
44depend on the selected manifest file (based on the current working directory if
45`--manifest-path` is not given). If the manifest is the root of a workspace then
46the workspaces default members are selected, otherwise only the package defined
47by the manifest will be selected.
48
49The default members of a workspace can be set explicitly with the
50`workspace.default-members` key in the root manifest. If this is not set, a
51virtual workspace will include all workspace members (equivalent to passing
52`--workspace`), and a non-virtual workspace will include only the root crate itself.
53
54<dl>
55
56<dt class="option-term" id="option-cargo-doc--p"><a class="option-anchor" href="#option-cargo-doc--p"></a><code>-p</code> <em>spec</em>...</dt>
57<dt class="option-term" id="option-cargo-doc---package"><a class="option-anchor" href="#option-cargo-doc---package"></a><code>--package</code> <em>spec</em>...</dt>
1a86f232 58<dd class="option-desc">Document only the specified packages. See <a href="cargo-pkgid.html">cargo-pkgid(1)</a> for the
4a61d8a4
WL
59SPEC format. This flag may be specified multiple times and supports common Unix
60glob patterns like <code>*</code>, <code>?</code> and <code>[]</code>. However, to avoid your shell accidentally
61expanding glob patterns before Cargo handles them, you must use single quotes or
62double quotes around each pattern.</dd>
2d4aa38b
EH
63
64
65<dt class="option-term" id="option-cargo-doc---workspace"><a class="option-anchor" href="#option-cargo-doc---workspace"></a><code>--workspace</code></dt>
66<dd class="option-desc">Document all members in the workspace.</dd>
67
68
69
70<dt class="option-term" id="option-cargo-doc---all"><a class="option-anchor" href="#option-cargo-doc---all"></a><code>--all</code></dt>
71<dd class="option-desc">Deprecated alias for <code>--workspace</code>.</dd>
72
73
74
75<dt class="option-term" id="option-cargo-doc---exclude"><a class="option-anchor" href="#option-cargo-doc---exclude"></a><code>--exclude</code> <em>SPEC</em>...</dt>
76<dd class="option-desc">Exclude the specified packages. Must be used in conjunction with the
4a61d8a4
WL
77<code>--workspace</code> flag. This flag may be specified multiple times and supports
78common Unix glob patterns like <code>*</code>, <code>?</code> and <code>[]</code>. However, to avoid your shell
79accidentally expanding glob patterns before Cargo handles them, you must use
80single quotes or double quotes around each pattern.</dd>
2d4aa38b
EH
81
82
83</dl>
84
85
86### Target Selection
87
88When no target selection options are given, `cargo doc` will document all
89binary and library targets of the selected package. The binary will be skipped
90if its name is the same as the lib target. Binaries are skipped if they have
91`required-features` that are missing.
92
93The default behavior can be changed by setting `doc = false` for the target in
94the manifest settings. Using target selection options will ignore the `doc`
95flag and will always document the given target.
96
97<dl>
98<dt class="option-term" id="option-cargo-doc---lib"><a class="option-anchor" href="#option-cargo-doc---lib"></a><code>--lib</code></dt>
99<dd class="option-desc">Document the package's library.</dd>
100
101
102<dt class="option-term" id="option-cargo-doc---bin"><a class="option-anchor" href="#option-cargo-doc---bin"></a><code>--bin</code> <em>name</em>...</dt>
4a61d8a4
WL
103<dd class="option-desc">Document the specified binary. This flag may be specified multiple times
104and supports common Unix glob patterns.</dd>
2d4aa38b
EH
105
106
107<dt class="option-term" id="option-cargo-doc---bins"><a class="option-anchor" href="#option-cargo-doc---bins"></a><code>--bins</code></dt>
108<dd class="option-desc">Document all binary targets.</dd>
109
110
f2cfd676 111
65c8eb34 112<dt class="option-term" id="option-cargo-doc---example"><a class="option-anchor" href="#option-cargo-doc---example"></a><code>--example</code> <em>name</em>...</dt>
113<dd class="option-desc">Document the specified example. This flag may be specified multiple times
114and supports common Unix glob patterns.</dd>
115
116
117<dt class="option-term" id="option-cargo-doc---examples"><a class="option-anchor" href="#option-cargo-doc---examples"></a><code>--examples</code></dt>
f2cfd676 118<dd class="option-desc">Document all example targets.</dd>
65c8eb34 119
120
2d4aa38b
EH
121</dl>
122
123### Feature Selection
124
d087aeb8
EH
125The feature flags allow you to control which features are enabled. When no
126feature options are given, the `default` feature is activated for every
127selected package.
2d4aa38b 128
d087aeb8
EH
129See [the features documentation](../reference/features.html#command-line-feature-options)
130for more details.
2d4aa38b
EH
131
132<dl>
133
f7280457 134<dt class="option-term" id="option-cargo-doc--F"><a class="option-anchor" href="#option-cargo-doc--F"></a><code>-F</code> <em>features</em></dt>
2d4aa38b 135<dt class="option-term" id="option-cargo-doc---features"><a class="option-anchor" href="#option-cargo-doc---features"></a><code>--features</code> <em>features</em></dt>
d087aeb8
EH
136<dd class="option-desc">Space or comma separated list of features to activate. Features of workspace
137members may be enabled with <code>package-name/feature-name</code> syntax. This flag may
138be specified multiple times, which enables all specified features.</dd>
2d4aa38b
EH
139
140
141<dt class="option-term" id="option-cargo-doc---all-features"><a class="option-anchor" href="#option-cargo-doc---all-features"></a><code>--all-features</code></dt>
142<dd class="option-desc">Activate all available features of all selected packages.</dd>
143
144
145<dt class="option-term" id="option-cargo-doc---no-default-features"><a class="option-anchor" href="#option-cargo-doc---no-default-features"></a><code>--no-default-features</code></dt>
d087aeb8 146<dd class="option-desc">Do not activate the <code>default</code> feature of the selected packages.</dd>
2d4aa38b
EH
147
148
149</dl>
150
151
152### Compilation Options
153
154<dl>
155
156<dt class="option-term" id="option-cargo-doc---target"><a class="option-anchor" href="#option-cargo-doc---target"></a><code>--target</code> <em>triple</em></dt>
08734a66 157<dd class="option-desc">Document for the given architecture. The default is the host architecture. The general format of the triple is
2d4aa38b 158<code>&lt;arch&gt;&lt;sub&gt;-&lt;vendor&gt;-&lt;sys&gt;-&lt;abi&gt;</code>. Run <code>rustc --print target-list</code> for a
3e177e0f 159list of supported targets. This flag may be specified multiple times.</p>
2d4aa38b 160<p>This may also be specified with the <code>build.target</code>
1a86f232 161<a href="../reference/config.html">config value</a>.</p>
2d4aa38b
EH
162<p>Note that specifying this flag makes Cargo run in a different mode where the
163target artifacts are placed in a separate directory. See the
1a86f232 164<a href="../guide/build-cache.html">build cache</a> documentation for more details.</dd>
2d4aa38b
EH
165
166
167
c92d917f 168<dt class="option-term" id="option-cargo-doc--r"><a class="option-anchor" href="#option-cargo-doc--r"></a><code>-r</code></dt>
2d4aa38b 169<dt class="option-term" id="option-cargo-doc---release"><a class="option-anchor" href="#option-cargo-doc---release"></a><code>--release</code></dt>
895f5271
EH
170<dd class="option-desc">Document optimized artifacts with the <code>release</code> profile.
171See also the <code>--profile</code> option for choosing a specific profile by name.</dd>
172
173
174
175<dt class="option-term" id="option-cargo-doc---profile"><a class="option-anchor" href="#option-cargo-doc---profile"></a><code>--profile</code> <em>name</em></dt>
176<dd class="option-desc">Document with the given profile.
177See the <a href="../reference/profiles.html">the reference</a> for more details on profiles.</dd>
2d4aa38b
EH
178
179
180
db3776cf
DO
181<dt class="option-term" id="option-cargo-doc---ignore-rust-version"><a class="option-anchor" href="#option-cargo-doc---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
182<dd class="option-desc">Document the target even if the selected Rust compiler is older than the
183required Rust version as configured in the project's <code>rust-version</code> field.</dd>
184
185
186
c8542471 187<dt class="option-term" id="option-cargo-doc---timings=fmts"><a class="option-anchor" href="#option-cargo-doc---timings=fmts"></a><code>--timings=</code><em>fmts</em></dt>
c0669189
JT
188<dd class="option-desc">Output information how long each compilation takes, and track concurrency
189information over time. Accepts an optional comma-separated list of output
086e71da 190formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
81e1998e
JT
191Specifying an output format (rather than the default) is unstable and requires
192<code>-Zunstable-options</code>. Valid output formats:</p>
c0669189 193<ul>
a6e6b89d 194<li><code>html</code> (unstable, requires <code>-Zunstable-options</code>): Write a human-readable file <code>cargo-timing.html</code> to the
e23f5f41
JT
195<code>target/cargo-timings</code> directory with a report of the compilation. Also write
196a report to the same directory with a timestamp in the filename if you want
197to look at older runs. HTML output is suitable for human consumption only,
198and does not provide machine-readable timing data.</li>
c0669189
JT
199<li><code>json</code> (unstable, requires <code>-Zunstable-options</code>): Emit machine-readable JSON
200information about timing information.</li>
201</ul></dd>
202
203
204
205
2d4aa38b
EH
206</dl>
207
208### Output Options
209
210<dl>
211<dt class="option-term" id="option-cargo-doc---target-dir"><a class="option-anchor" href="#option-cargo-doc---target-dir"></a><code>--target-dir</code> <em>directory</em></dt>
212<dd class="option-desc">Directory for all generated artifacts and intermediate files. May also be
213specified with the <code>CARGO_TARGET_DIR</code> environment variable, or the
ee53210f
WL
214<code>build.target-dir</code> <a href="../reference/config.html">config value</a>.
215Defaults to <code>target</code> in the root of the workspace.</dd>
2d4aa38b
EH
216
217
218</dl>
219
220### Display Options
221
222<dl>
223<dt class="option-term" id="option-cargo-doc--v"><a class="option-anchor" href="#option-cargo-doc--v"></a><code>-v</code></dt>
224<dt class="option-term" id="option-cargo-doc---verbose"><a class="option-anchor" href="#option-cargo-doc---verbose"></a><code>--verbose</code></dt>
225<dd class="option-desc">Use verbose output. May be specified twice for &quot;very verbose&quot; output which
226includes extra output such as dependency warnings and build script output.
227May also be specified with the <code>term.verbose</code>
1a86f232 228<a href="../reference/config.html">config value</a>.</dd>
2d4aa38b
EH
229
230
231<dt class="option-term" id="option-cargo-doc--q"><a class="option-anchor" href="#option-cargo-doc--q"></a><code>-q</code></dt>
232<dt class="option-term" id="option-cargo-doc---quiet"><a class="option-anchor" href="#option-cargo-doc---quiet"></a><code>--quiet</code></dt>
cd4e2804
SJ
233<dd class="option-desc">Do not print cargo log messages.
234May also be specified with the <code>term.quiet</code>
235<a href="../reference/config.html">config value</a>.</dd>
2d4aa38b
EH
236
237
238<dt class="option-term" id="option-cargo-doc---color"><a class="option-anchor" href="#option-cargo-doc---color"></a><code>--color</code> <em>when</em></dt>
239<dd class="option-desc">Control when colored output is used. Valid values:</p>
240<ul>
241<li><code>auto</code> (default): Automatically detect if color support is available on the
242terminal.</li>
243<li><code>always</code>: Always display colors.</li>
244<li><code>never</code>: Never display colors.</li>
245</ul>
246<p>May also be specified with the <code>term.color</code>
1a86f232 247<a href="../reference/config.html">config value</a>.</dd>
2d4aa38b
EH
248
249
250
251<dt class="option-term" id="option-cargo-doc---message-format"><a class="option-anchor" href="#option-cargo-doc---message-format"></a><code>--message-format</code> <em>fmt</em></dt>
252<dd class="option-desc">The output format for diagnostic messages. Can be specified multiple times
253and consists of comma-separated values. Valid values:</p>
254<ul>
d174b773
CR
255<li><code>human</code> (default): Display in a human-readable text format. Conflicts with
256<code>short</code> and <code>json</code>.</li>
257<li><code>short</code>: Emit shorter, human-readable text messages. Conflicts with <code>human</code>
258and <code>json</code>.</li>
2d4aa38b 259<li><code>json</code>: Emit JSON messages to stdout. See
1a86f232 260<a href="../reference/external-tools.html#json-messages">the reference</a>
d174b773 261for more details. Conflicts with <code>human</code> and <code>short</code>.</li>
2d4aa38b 262<li><code>json-diagnostic-short</code>: Ensure the <code>rendered</code> field of JSON messages contains
d174b773 263the &quot;short&quot; rendering from rustc. Cannot be used with <code>human</code> or <code>short</code>.</li>
2d4aa38b
EH
264<li><code>json-diagnostic-rendered-ansi</code>: Ensure the <code>rendered</code> field of JSON messages
265contains embedded ANSI color codes for respecting rustc's default color
d174b773 266scheme. Cannot be used with <code>human</code> or <code>short</code>.</li>
195b1e0e 267<li><code>json-render-diagnostics</code>: Instruct Cargo to not include rustc diagnostics
2d4aa38b
EH
268in JSON messages printed, but instead Cargo itself should render the
269JSON diagnostics coming from rustc. Cargo's own JSON diagnostics and others
d174b773 270coming from rustc are still emitted. Cannot be used with <code>human</code> or <code>short</code>.</li>
2d4aa38b
EH
271</ul></dd>
272
273
274</dl>
275
276### Manifest Options
277
278<dl>
279<dt class="option-term" id="option-cargo-doc---manifest-path"><a class="option-anchor" href="#option-cargo-doc---manifest-path"></a><code>--manifest-path</code> <em>path</em></dt>
280<dd class="option-desc">Path to the <code>Cargo.toml</code> file. By default, Cargo searches for the
281<code>Cargo.toml</code> file in the current directory or any parent directory.</dd>
282
283
284
285<dt class="option-term" id="option-cargo-doc---frozen"><a class="option-anchor" href="#option-cargo-doc---frozen"></a><code>--frozen</code></dt>
286<dt class="option-term" id="option-cargo-doc---locked"><a class="option-anchor" href="#option-cargo-doc---locked"></a><code>--locked</code></dt>
287<dd class="option-desc">Either of these flags requires that the <code>Cargo.lock</code> file is
288up-to-date. If the lock file is missing, or it needs to be updated, Cargo will
289exit with an error. The <code>--frozen</code> flag also prevents Cargo from
290attempting to access the network to determine if it is out-of-date.</p>
291<p>These may be used in environments where you want to assert that the
292<code>Cargo.lock</code> file is up-to-date (such as a CI build) or want to avoid network
293access.</dd>
294
295
296<dt class="option-term" id="option-cargo-doc---offline"><a class="option-anchor" href="#option-cargo-doc---offline"></a><code>--offline</code></dt>
297<dd class="option-desc">Prevents Cargo from accessing the network for any reason. Without this
298flag, Cargo will stop with an error if it needs to access the network and
299the network is not available. With this flag, Cargo will attempt to
300proceed without the network if possible.</p>
301<p>Beware that this may result in different dependency resolution than online
302mode. Cargo will restrict itself to crates that are downloaded locally, even
303if there might be a newer version as indicated in the local copy of the index.
1a86f232 304See the <a href="cargo-fetch.html">cargo-fetch(1)</a> command to download dependencies before going
2d4aa38b 305offline.</p>
1a86f232 306<p>May also be specified with the <code>net.offline</code> <a href="../reference/config.html">config value</a>.</dd>
2d4aa38b
EH
307
308
309</dl>
310
311### Common Options
312
313<dl>
314
315<dt class="option-term" id="option-cargo-doc-+toolchain"><a class="option-anchor" href="#option-cargo-doc-+toolchain"></a><code>+</code><em>toolchain</em></dt>
316<dd class="option-desc">If Cargo has been installed with rustup, and the first argument to <code>cargo</code>
317begins with <code>+</code>, it will be interpreted as a rustup toolchain name (such
318as <code>+stable</code> or <code>+nightly</code>).
fac70ee7 319See the <a href="https://rust-lang.github.io/rustup/overrides.html">rustup documentation</a>
2d4aa38b
EH
320for more information about how toolchain overrides work.</dd>
321
322
65332bc9
WL
323<dt class="option-term" id="option-cargo-doc---config"><a class="option-anchor" href="#option-cargo-doc---config"></a><code>--config</code> <em>KEY=VALUE</em> or <em>PATH</em></dt>
324<dd class="option-desc">Overrides a Cargo configuration value. The argument should be in TOML syntax of <code>KEY=VALUE</code>,
325or provided as a path to an extra configuration file. This flag may be specified multiple times.
326See the <a href="../reference/config.html#command-line-overrides">command-line overrides section</a> for more information.</dd>
7eefb422
JG
327
328
2d4aa38b
EH
329<dt class="option-term" id="option-cargo-doc--h"><a class="option-anchor" href="#option-cargo-doc--h"></a><code>-h</code></dt>
330<dt class="option-term" id="option-cargo-doc---help"><a class="option-anchor" href="#option-cargo-doc---help"></a><code>--help</code></dt>
331<dd class="option-desc">Prints help information.</dd>
332
333
334<dt class="option-term" id="option-cargo-doc--Z"><a class="option-anchor" href="#option-cargo-doc--Z"></a><code>-Z</code> <em>flag</em></dt>
335<dd class="option-desc">Unstable (nightly-only) flags to Cargo. Run <code>cargo -Z help</code> for details.</dd>
336
337
338</dl>
339
340
341### Miscellaneous Options
342
343<dl>
344<dt class="option-term" id="option-cargo-doc--j"><a class="option-anchor" href="#option-cargo-doc--j"></a><code>-j</code> <em>N</em></dt>
345<dt class="option-term" id="option-cargo-doc---jobs"><a class="option-anchor" href="#option-cargo-doc---jobs"></a><code>--jobs</code> <em>N</em></dt>
346<dd class="option-desc">Number of parallel jobs to run. May also be specified with the
1a86f232 347<code>build.jobs</code> <a href="../reference/config.html">config value</a>. Defaults to
5b76fb3d
YT
348the number of logical CPUs. If negative, it sets the maximum number of
349parallel jobs to the number of logical CPUs plus provided value.
350Should not be 0.</dd>
2d4aa38b
EH
351
352
4e45f588
DT
353<dt class="option-term" id="option-cargo-doc---keep-going"><a class="option-anchor" href="#option-cargo-doc---keep-going"></a><code>--keep-going</code></dt>
354<dd class="option-desc">Build as many crates in the dependency graph as possible, rather than aborting
355the build on the first one that fails to build. Unstable, requires
356<code>-Zunstable-options</code>.</dd>
357
358
2d4aa38b
EH
359</dl>
360
2d4aa38b
EH
361## ENVIRONMENT
362
363See [the reference](../reference/environment-variables.html) for
364details on environment variables that Cargo reads.
365
366
367## EXIT STATUS
368
369* `0`: Cargo succeeded.
370* `101`: Cargo failed to complete.
371
372
373## EXAMPLES
374
3751. Build the local package documentation and its dependencies and output to
376 `target/doc`.
377
378 cargo doc
379
380## SEE ALSO
1a86f232 381[cargo(1)](cargo.html), [cargo-rustdoc(1)](cargo-rustdoc.html), [rustdoc(1)](https://doc.rust-lang.org/rustdoc/index.html)