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

PROFILES

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

ENVIRONMENT

279       See the reference
280       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
281       for details on environment variables that Cargo reads.
282

EXIT STATUS

2840: Cargo succeeded.
285
286101: Cargo failed to complete.
287

EXAMPLES

289        1. Build the local package documentation and its dependencies and
290           output to target/doc.
291
292               cargo doc
293

SEE ALSO

295       cargo(1), cargo-rustdoc(1), rustdoc(1)
296
297
298
299                                                                  CARGO-DOC(1)
Impressum