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.
40
41   Package Selection
42       By default, the package in the current working directory is selected.
43       The -p flag can be used to choose a different package in a workspace.
44
45       -p spec, --package spec
46           The package to document. See cargo-pkgid(1) for the SPEC format.
47
48   Target Selection
49       When no target selection options are given, cargo rustdoc will document
50       all binary and library targets of the selected package. The binary will
51       be skipped if its name is the same as the lib target. Binaries are
52       skipped if they have required-features that are missing.
53
54       Passing target selection flags will document only the specified
55       targets.
56
57       Note that --bin, --example, --test and --bench flags also support
58       common Unix glob patterns like *, ? and []. However, to avoid your
59       shell accidentally expanding glob patterns before Cargo handles them,
60       you must use single quotes or double quotes around each glob pattern.
61
62       --lib
63           Document the package's library.
64
65       --bin name...
66           Document the specified binary. This flag may be specified multiple
67           times and supports common Unix glob patterns.
68
69       --bins
70           Document all binary targets.
71
72       --example name...
73           Document the specified example. This flag may be specified multiple
74           times and supports common Unix glob patterns.
75
76       --examples
77           Document all example targets.
78
79       --test name...
80           Document the specified integration test. This flag may be specified
81           multiple times and supports common Unix glob patterns.
82
83       --tests
84           Document all targets in test mode that have the test = true
85           manifest flag set. By default this includes the library and
86           binaries built as unittests, and integration tests. Be aware that
87           this will also build any required dependencies, so the lib target
88           may be built twice (once as a unittest, and once as a dependency
89           for binaries, integration tests, etc.). Targets may be enabled or
90           disabled by setting the test flag in the manifest settings for the
91           target.
92
93       --bench name...
94           Document the specified benchmark. This flag may be specified
95           multiple times and supports common Unix glob patterns.
96
97       --benches
98           Document all targets in benchmark mode that have the bench = true
99           manifest flag set. By default this includes the library and
100           binaries built as benchmarks, and bench targets. Be aware that this
101           will also build any required dependencies, so the lib target may be
102           built twice (once as a benchmark, and once as a dependency for
103           binaries, benchmarks, etc.). Targets may be enabled or disabled by
104           setting the bench flag in the manifest settings for the target.
105
106       --all-targets
107           Document all targets. This is equivalent to specifying --lib --bins
108           --tests --benches --examples.
109
110   Feature Selection
111       The feature flags allow you to control which features are enabled. When
112       no feature options are given, the default feature is activated for
113       every selected package.
114
115       See the features documentation
116       <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>
117       for more details.
118
119       --features features
120           Space or comma separated list of features to activate. Features of
121           workspace members may be enabled with package-name/feature-name
122           syntax. This flag may be specified multiple times, which enables
123           all specified features.
124
125       --all-features
126           Activate all available features of all selected packages.
127
128       --no-default-features
129           Do not activate the default feature of the selected packages.
130
131   Compilation Options
132       --target triple
133           Document for the given architecture. The default is the host
134           architecture. The general format of the triple is
135           <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
136           a list of supported targets.
137
138           This may also be specified with the build.target config value
139           <https://doc.rust-lang.org/cargo/reference/config.html>.
140
141           Note that specifying this flag makes Cargo run in a different mode
142           where the target artifacts are placed in a separate directory. See
143           the build cache
144           <https://doc.rust-lang.org/cargo/guide/build-cache.html>
145           documentation for more details.
146
147       --release
148           Document optimized artifacts with the release profile. See the
149           PROFILES section for details on how this affects profile selection.
150
151   Output Options
152       --target-dir directory
153           Directory for all generated artifacts and intermediate files. May
154           also be specified with the CARGO_TARGET_DIR environment variable,
155           or the build.target-dir config value
156           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
157           to target in the root of the workspace.
158
159   Display Options
160       -v, --verbose
161           Use verbose output. May be specified twice for "very verbose"
162           output which includes extra output such as dependency warnings and
163           build script output. May also be specified with the term.verbose
164           config value
165           <https://doc.rust-lang.org/cargo/reference/config.html>.
166
167       -q, --quiet
168           No output printed to stdout.
169
170       --color when
171           Control when colored output is used. Valid values:
172
173auto (default): Automatically detect if color support is
174               available on the terminal.
175
176always: Always display colors.
177
178never: Never display colors.
179
180           May also be specified with the term.color config value
181           <https://doc.rust-lang.org/cargo/reference/config.html>.
182
183       --message-format fmt
184           The output format for diagnostic messages. Can be specified
185           multiple times and consists of comma-separated values. Valid
186           values:
187
188human (default): Display in a human-readable text format.
189               Conflicts with short and json.
190
191short: Emit shorter, human-readable text messages. Conflicts
192               with human and json.
193
194json: Emit JSON messages to stdout. See the reference
195               <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
196               for more details. Conflicts with human and short.
197
198json-diagnostic-short: Ensure the rendered field of JSON
199               messages contains the "short" rendering from rustc. Cannot be
200               used with human or short.
201
202json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
203               messages contains embedded ANSI color codes for respecting
204               rustc's default color scheme. Cannot be used with human or
205               short.
206
207json-render-diagnostics: Instruct Cargo to not include rustc
208               diagnostics in in JSON messages printed, but instead Cargo
209               itself should render the JSON diagnostics coming from rustc.
210               Cargo's own JSON diagnostics and others coming from rustc are
211               still emitted. Cannot be used with human or short.
212
213   Manifest Options
214       --manifest-path path
215           Path to the Cargo.toml file. By default, Cargo searches for the
216           Cargo.toml file in the current directory or any parent directory.
217
218       --frozen, --locked
219           Either of these flags requires that the Cargo.lock file is
220           up-to-date. If the lock file is missing, or it needs to be updated,
221           Cargo will exit with an error. The --frozen flag also prevents
222           Cargo from attempting to access the network to determine if it is
223           out-of-date.
224
225           These may be used in environments where you want to assert that the
226           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
227           network access.
228
229       --offline
230           Prevents Cargo from accessing the network for any reason. Without
231           this flag, Cargo will stop with an error if it needs to access the
232           network and the network is not available. With this flag, Cargo
233           will attempt to proceed without the network if possible.
234
235           Beware that this may result in different dependency resolution than
236           online mode. Cargo will restrict itself to crates that are
237           downloaded locally, even if there might be a newer version as
238           indicated in the local copy of the index. See the cargo-fetch(1)
239           command to download dependencies before going offline.
240
241           May also be specified with the net.offline config value
242           <https://doc.rust-lang.org/cargo/reference/config.html>.
243
244   Common Options
245       +toolchain
246           If Cargo has been installed with rustup, and the first argument to
247           cargo begins with +, it will be interpreted as a rustup toolchain
248           name (such as +stable or +nightly). See the rustup documentation
249           <https://rust-lang.github.io/rustup/overrides.html> for more
250           information about how toolchain overrides work.
251
252       -h, --help
253           Prints help information.
254
255       -Z flag
256           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
257           details.
258
259   Miscellaneous Options
260       -j N, --jobs N
261           Number of parallel jobs to run. May also be specified with the
262           build.jobs config value
263           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
264           to the number of CPUs.
265

PROFILES

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

ENVIRONMENT

290       See the reference
291       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
292       for details on environment variables that Cargo reads.
293

EXIT STATUS

2950: Cargo succeeded.
296
297101: Cargo failed to complete.
298

EXAMPLES

300        1. Build documentation with custom CSS included from a given file:
301
302               cargo rustdoc --lib -- --extend-css extra.css
303

SEE ALSO

305       cargo(1), cargo-doc(1), rustdoc(1)
306
307
308
309                                                              CARGO-RUSTDOC(1)
Impressum