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

NAME

6       cargo-rustdoc — Build a package’s documentation, using specified custom
7       flags
8

SYNOPSIS

10       cargo rustdoc [options] [-- args]
11

DESCRIPTION

13       The specified target for the current package (or package specified by
14       -p if provided) will be documented with the specified args being passed
15       to the final rustdoc invocation. Dependencies will not be documented as
16       part of this command. Note that rustdoc will still unconditionally
17       receive arguments such as -L, --extern, and --crate-type, and the
18       specified args will simply be added to the rustdoc invocation.
19
20       See <https://doc.rust-lang.org/rustdoc/index.html> for documentation on
21       rustdoc flags.
22
23       This command requires that only one target is being compiled when
24       additional arguments are provided. If more than one target is available
25       for the current package the filters of --lib, --bin, etc, must be used
26       to select which target is compiled.
27
28       To pass flags to all rustdoc processes spawned by Cargo, use the
29       RUSTDOCFLAGS environment variable
30       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
31       or the build.rustdocflags config value
32       <https://doc.rust-lang.org/cargo/reference/config.html>.
33

OPTIONS

35   Documentation Options
36       --open
37           Open the docs in a browser after building them. This will use your
38           default browser unless you define another one in the BROWSER
39           environment variable or use the doc.browser
40           <https://doc.rust-lang.org/cargo/reference/config.html#docbrowser>
41           configuration option.
42
43   Package Selection
44       By default, the package in the current working directory is selected.
45       The -p flag can be used to choose a different package in a workspace.
46
47       -p spec, --package spec
48           The package to document. See cargo-pkgid(1) for the SPEC format.
49
50   Target Selection
51       When no target selection options are given, cargo rustdoc will document
52       all binary and library targets of the selected package. The binary will
53       be skipped if its name is the same as the lib target. Binaries are
54       skipped if they have required-features that are missing.
55
56       Passing target selection flags will document only the specified
57       targets.
58
59       Note that --bin, --example, --test and --bench flags also support
60       common Unix glob patterns like *, ? and []. However, to avoid your
61       shell accidentally expanding glob patterns before Cargo handles them,
62       you must use single quotes or double quotes around each glob pattern.
63
64       --lib
65           Document the package’s library.
66
67       --bin name…
68           Document the specified binary. This flag may be specified multiple
69           times and supports common Unix glob patterns.
70
71       --bins
72           Document all binary targets.
73
74       --example name…
75           Document the specified example. This flag may be specified multiple
76           times and supports common Unix glob patterns.
77
78       --examples
79           Document all example targets.
80
81       --test name…
82           Document the specified integration test. This flag may be specified
83           multiple times and supports common Unix glob patterns.
84
85       --tests
86           Document all targets in test mode that have the test = true
87           manifest flag set. By default this includes the library and
88           binaries built as unittests, and integration tests. Be aware that
89           this will also build any required dependencies, so the lib target
90           may be built twice (once as a unittest, and once as a dependency
91           for binaries, integration tests, etc.). Targets may be enabled or
92           disabled by setting the test flag in the manifest settings for the
93           target.
94
95       --bench name…
96           Document the specified benchmark. This flag may be specified
97           multiple times and supports common Unix glob patterns.
98
99       --benches
100           Document all targets in benchmark mode that have the bench = true
101           manifest flag set. By default this includes the library and
102           binaries built as benchmarks, and bench targets. Be aware that this
103           will also build any required dependencies, so the lib target may be
104           built twice (once as a benchmark, and once as a dependency for
105           binaries, benchmarks, etc.). Targets may be enabled or disabled by
106           setting the bench flag in the manifest settings for the target.
107
108       --all-targets
109           Document all targets. This is equivalent to specifying --lib --bins
110           --tests --benches --examples.
111
112   Feature Selection
113       The feature flags allow you to control which features are enabled. When
114       no feature options are given, the default feature is activated for
115       every selected package.
116
117       See the features documentation
118       <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>
119       for more details.
120
121       -F features, --features features
122           Space or comma separated list of features to activate. Features of
123           workspace members may be enabled with package-name/feature-name
124           syntax. This flag may be specified multiple times, which enables
125           all specified features.
126
127       --all-features
128           Activate all available features of all selected packages.
129
130       --no-default-features
131           Do not activate the default feature of the selected packages.
132
133   Compilation Options
134       --target triple
135           Document for the given architecture. The default is the host
136           architecture. The general format of the triple is
137           <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
138           a list of supported targets. This flag may be specified multiple
139           times.
140
141           This may also be specified with the build.target config value
142           <https://doc.rust-lang.org/cargo/reference/config.html>.
143
144           Note that specifying this flag makes Cargo run in a different mode
145           where the target artifacts are placed in a separate directory. See
146           the build cache
147           <https://doc.rust-lang.org/cargo/guide/build-cache.html>
148           documentation for more details.
149
150       -r, --release
151           Document optimized artifacts with the release profile. See also the
152           --profile option for choosing a specific profile by name.
153
154       --profile name
155           Document with the given profile. See the the reference
156           <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
157           details on profiles.
158
159       --ignore-rust-version
160           Document the target even if the selected Rust compiler is older
161           than the required Rust version as configured in the project’s
162           rust-version field.
163
164       --timings=fmts
165           Output information how long each compilation takes, and track
166           concurrency information over time. Accepts an optional
167           comma-separated list of output formats; --timings without an
168           argument will default to --timings=html. Specifying an output
169           format (rather than the default) is unstable and requires
170           -Zunstable-options. Valid output formats:
171
172html (unstable, requires -Zunstable-options): Write a
173               human-readable file cargo-timing.html to the
174               target/cargo-timings directory with a report of the
175               compilation. Also write a report to the same directory with a
176               timestamp in the filename if you want to look at older runs.
177               HTML output is suitable for human consumption only, and does
178               not provide machine-readable timing data.
179
180json (unstable, requires -Zunstable-options): Emit
181               machine-readable JSON information about timing information.
182
183   Output Options
184       --target-dir directory
185           Directory for all generated artifacts and intermediate files. May
186           also be specified with the CARGO_TARGET_DIR environment variable,
187           or the build.target-dir config value
188           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
189           to target in the root of the workspace.
190
191   Display Options
192       -v, --verbose
193           Use verbose output. May be specified twice for “very verbose”
194           output which includes extra output such as dependency warnings and
195           build script output. May also be specified with the term.verbose
196           config value
197           <https://doc.rust-lang.org/cargo/reference/config.html>.
198
199       -q, --quiet
200           Do not print cargo log messages. May also be specified with the
201           term.quiet config value
202           <https://doc.rust-lang.org/cargo/reference/config.html>.
203
204       --color when
205           Control when colored output is used. Valid values:
206
207auto (default): Automatically detect if color support is
208               available on the terminal.
209
210always: Always display colors.
211
212never: Never display colors.
213
214           May also be specified with the term.color config value
215           <https://doc.rust-lang.org/cargo/reference/config.html>.
216
217       --message-format fmt
218           The output format for diagnostic messages. Can be specified
219           multiple times and consists of comma-separated values. Valid
220           values:
221
222human (default): Display in a human-readable text format.
223               Conflicts with short and json.
224
225short: Emit shorter, human-readable text messages. Conflicts
226               with human and json.
227
228json: Emit JSON messages to stdout. See the reference
229               <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
230               for more details. Conflicts with human and short.
231
232json-diagnostic-short: Ensure the rendered field of JSON
233               messages contains the “short” rendering from rustc. Cannot be
234               used with human or short.
235
236json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
237               messages contains embedded ANSI color codes for respecting
238               rustc’s default color scheme. Cannot be used with human or
239               short.
240
241json-render-diagnostics: Instruct Cargo to not include rustc
242               diagnostics in JSON messages printed, but instead Cargo itself
243               should render the JSON diagnostics coming from rustc. Cargo’s
244               own JSON diagnostics and others coming from rustc are still
245               emitted. Cannot be used with human or short.
246
247   Manifest Options
248       --manifest-path path
249           Path to the Cargo.toml file. By default, Cargo searches for the
250           Cargo.toml file in the current directory or any parent directory.
251
252       --frozen, --locked
253           Either of these flags requires that the Cargo.lock file is
254           up-to-date. If the lock file is missing, or it needs to be updated,
255           Cargo will exit with an error. The --frozen flag also prevents
256           Cargo from attempting to access the network to determine if it is
257           out-of-date.
258
259           These may be used in environments where you want to assert that the
260           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
261           network access.
262
263       --offline
264           Prevents Cargo from accessing the network for any reason. Without
265           this flag, Cargo will stop with an error if it needs to access the
266           network and the network is not available. With this flag, Cargo
267           will attempt to proceed without the network if possible.
268
269           Beware that this may result in different dependency resolution than
270           online mode. Cargo will restrict itself to crates that are
271           downloaded locally, even if there might be a newer version as
272           indicated in the local copy of the index. See the cargo-fetch(1)
273           command to download dependencies before going offline.
274
275           May also be specified with the net.offline config value
276           <https://doc.rust-lang.org/cargo/reference/config.html>.
277
278   Common Options
279       +toolchain
280           If Cargo has been installed with rustup, and the first argument to
281           cargo begins with +, it will be interpreted as a rustup toolchain
282           name (such as +stable or +nightly). See the rustup documentation
283           <https://rust-lang.github.io/rustup/overrides.html> for more
284           information about how toolchain overrides work.
285
286       --config KEY=VALUE or PATH
287           Overrides a Cargo configuration value. The argument should be in
288           TOML syntax of KEY=VALUE, or provided as a path to an extra
289           configuration file. This flag may be specified multiple times. See
290           the command-line overrides section
291           <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
292           for more information.
293
294       -C PATH
295           Changes the current working directory before executing any
296           specified operations. This affects things like where cargo looks by
297           default for the project manifest (Cargo.toml), as well as the
298           directories searched for discovering .cargo/config.toml, for
299           example. This option must appear before the command name, for
300           example cargo -C path/to/my-project build.
301
302           This option is only available on the nightly channel
303           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
304           requires the -Z unstable-options flag to enable (see #10098
305           <https://github.com/rust-lang/cargo/issues/10098>).
306
307       -h, --help
308           Prints help information.
309
310       -Z flag
311           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
312           details.
313
314   Miscellaneous Options
315       -j N, --jobs N
316           Number of parallel jobs to run. May also be specified with the
317           build.jobs config value
318           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
319           to the number of logical CPUs. If negative, it sets the maximum
320           number of parallel jobs to the number of logical CPUs plus provided
321           value. If a string default is provided, it sets the value back to
322           defaults. Should not be 0.
323
324       --keep-going
325           Build as many crates in the dependency graph as possible, rather
326           than aborting the build on the first one that fails to build.
327
328           For example if the current package depends on dependencies fails
329           and works, one of which fails to build, cargo rustdoc -j1 may or
330           may not build the one that succeeds (depending on which one of the
331           two builds Cargo picked to run first), whereas cargo rustdoc -j1
332           --keep-going would definitely run both builds, even if the one run
333           first fails.
334

ENVIRONMENT

336       See the reference
337       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
338       for details on environment variables that Cargo reads.
339

EXIT STATUS

3410: Cargo succeeded.
342
343101: Cargo failed to complete.
344

EXAMPLES

346        1. Build documentation with custom CSS included from a given file:
347
348               cargo rustdoc --lib -- --extend-css extra.css
349

SEE ALSO

351       cargo(1), cargo-doc(1), rustdoc(1)
352
353
354
355                                                              CARGO-RUSTDOC(1)
Impressum