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

NAME

6       cargo-doc — Build a package’s documentation
7

SYNOPSIS

9       cargo doc [options]
10

DESCRIPTION

12       Build the documentation for the local package and all dependencies. The
13       output is placed in target/doc in rustdoc’s usual format.
14

OPTIONS

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

ENVIRONMENT

318       See the reference
319       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
320       for details on environment variables that Cargo reads.
321

EXIT STATUS

3230: Cargo succeeded.
324
325101: Cargo failed to complete.
326

EXAMPLES

328        1. Build the local package documentation and its dependencies and
329           output to target/doc.
330
331               cargo doc
332

SEE ALSO

334       cargo(1), cargo-rustdoc(1), rustdoc(1)
335
336
337
338                                                                  CARGO-DOC(1)
Impressum