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       --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.
139
140           This may also be specified with the build.target config value
141           <https://doc.rust-lang.org/cargo/reference/config.html>.
142
143           Note that specifying this flag makes Cargo run in a different mode
144           where the target artifacts are placed in a separate directory. See
145           the build cache
146           <https://doc.rust-lang.org/cargo/guide/build-cache.html>
147           documentation for more details.
148
149       --release
150           Document optimized artifacts with the release profile. See the
151           PROFILES section for details on how this affects profile selection.
152
153       --ignore-rust-version
154           Document the target even if the selected Rust compiler is older
155           than the required Rust version as configured in the project's
156           rust-version field.
157
158   Output Options
159       --target-dir directory
160           Directory for all generated artifacts and intermediate files. May
161           also be specified with the CARGO_TARGET_DIR environment variable,
162           or the build.target-dir config value
163           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
164           to target in the root of the workspace.
165
166   Display Options
167       -v, --verbose
168           Use verbose output. May be specified twice for "very verbose"
169           output which includes extra output such as dependency warnings and
170           build script output. May also be specified with the term.verbose
171           config value
172           <https://doc.rust-lang.org/cargo/reference/config.html>.
173
174       -q, --quiet
175           No output printed to stdout.
176
177       --color when
178           Control when colored output is used. Valid values:
179
180auto (default): Automatically detect if color support is
181               available on the terminal.
182
183always: Always display colors.
184
185never: Never display colors.
186
187           May also be specified with the term.color config value
188           <https://doc.rust-lang.org/cargo/reference/config.html>.
189
190       --message-format fmt
191           The output format for diagnostic messages. Can be specified
192           multiple times and consists of comma-separated values. Valid
193           values:
194
195human (default): Display in a human-readable text format.
196               Conflicts with short and json.
197
198short: Emit shorter, human-readable text messages. Conflicts
199               with human and json.
200
201json: Emit JSON messages to stdout. See the reference
202               <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
203               for more details. Conflicts with human and short.
204
205json-diagnostic-short: Ensure the rendered field of JSON
206               messages contains the "short" rendering from rustc. Cannot be
207               used with human or short.
208
209json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
210               messages contains embedded ANSI color codes for respecting
211               rustc's default color scheme. Cannot be used with human or
212               short.
213
214json-render-diagnostics: Instruct Cargo to not include rustc
215               diagnostics in in JSON messages printed, but instead Cargo
216               itself should render the JSON diagnostics coming from rustc.
217               Cargo's own JSON diagnostics and others coming from rustc are
218               still emitted. Cannot be used with human or short.
219
220   Manifest Options
221       --manifest-path path
222           Path to the Cargo.toml file. By default, Cargo searches for the
223           Cargo.toml file in the current directory or any parent directory.
224
225       --frozen, --locked
226           Either of these flags requires that the Cargo.lock file is
227           up-to-date. If the lock file is missing, or it needs to be updated,
228           Cargo will exit with an error. The --frozen flag also prevents
229           Cargo from attempting to access the network to determine if it is
230           out-of-date.
231
232           These may be used in environments where you want to assert that the
233           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
234           network access.
235
236       --offline
237           Prevents Cargo from accessing the network for any reason. Without
238           this flag, Cargo will stop with an error if it needs to access the
239           network and the network is not available. With this flag, Cargo
240           will attempt to proceed without the network if possible.
241
242           Beware that this may result in different dependency resolution than
243           online mode. Cargo will restrict itself to crates that are
244           downloaded locally, even if there might be a newer version as
245           indicated in the local copy of the index. See the cargo-fetch(1)
246           command to download dependencies before going offline.
247
248           May also be specified with the net.offline config value
249           <https://doc.rust-lang.org/cargo/reference/config.html>.
250
251   Common Options
252       +toolchain
253           If Cargo has been installed with rustup, and the first argument to
254           cargo begins with +, it will be interpreted as a rustup toolchain
255           name (such as +stable or +nightly). See the rustup documentation
256           <https://rust-lang.github.io/rustup/overrides.html> for more
257           information about how toolchain overrides work.
258
259       -h, --help
260           Prints help information.
261
262       -Z flag
263           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
264           details.
265
266   Miscellaneous Options
267       -j N, --jobs N
268           Number of parallel jobs to run. May also be specified with the
269           build.jobs config value
270           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
271           to the number of CPUs.
272

PROFILES

274       Profiles may be used to configure compiler options such as optimization
275       levels and debug settings. See the reference
276       <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
277       details.
278
279       Profile selection depends on the target and crate being built. By
280       default the dev or test profiles are used. If the --release flag is
281       given, then the release or bench profiles are used.
282
283
284       ┌────────────────────┬─────────────────┬───────────────────┐
285       │Target              │ Default Profile │ --release Profile │
286       ├────────────────────┼─────────────────┼───────────────────┤
287       │lib, bin, example   │ dev             release           
288       ├────────────────────┼─────────────────┼───────────────────┤
289       │test, bench, or any │ test            bench             
290       │target in "test" or │                 │                   │
291       │"bench" mode        │                 │                   │
292       └────────────────────┴─────────────────┴───────────────────┘
293
294       Dependencies use the dev/release profiles.
295

ENVIRONMENT

297       See the reference
298       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
299       for details on environment variables that Cargo reads.
300

EXIT STATUS

3020: Cargo succeeded.
303
304101: Cargo failed to complete.
305

EXAMPLES

307        1. Build documentation with custom CSS included from a given file:
308
309               cargo rustdoc --lib -- --extend-css extra.css
310

SEE ALSO

312       cargo(1), cargo-doc(1), rustdoc(1)
313
314
315
316                                                              CARGO-RUSTDOC(1)
Impressum