1CARGO-DOC(1) General Commands Manual CARGO-DOC(1)
2
3
4
6 cargo-doc - Build a package's documentation
7
9 cargo doc [options]
10
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
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.
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 -r, --release
132 Document optimized artifacts with the release profile. See also the
133 --profile option for choosing a specific profile by name.
134
135 --profile name
136 Document with the given profile. See the the reference
137 <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
138 details on profiles.
139
140 --ignore-rust-version
141 Document the target even if the selected Rust compiler is older
142 than the required Rust version as configured in the project's
143 rust-version field.
144
145 --timings=fmts
146 Output information how long each compilation takes, and track
147 concurrency information over time. Accepts an optional
148 comma-separated list of output formats; --timings without an
149 argument will default to --timings=html. Specifying an output
150 format (rather than the default) is unstable and requires
151 -Zunstable-options. Valid output formats:
152
153 • html: Write a human-readable file cargo-timing.html to the
154 target/cargo-timings directory with a report of the
155 compilation. Also write a report to the same directory with a
156 timestamp in the filename if you want to look at older runs.
157 HTML output is suitable for human consumption only, and does
158 not provide machine-readable timing data.
159
160 • json (unstable, requires -Zunstable-options): Emit
161 machine-readable JSON information about timing information.
162
163 Output Options
164 --target-dir directory
165 Directory for all generated artifacts and intermediate files. May
166 also be specified with the CARGO_TARGET_DIR environment variable,
167 or the build.target-dir config value
168 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
169 to target in the root of the workspace.
170
171 Display Options
172 -v, --verbose
173 Use verbose output. May be specified twice for "very verbose"
174 output which includes extra output such as dependency warnings and
175 build script output. May also be specified with the term.verbose
176 config value
177 <https://doc.rust-lang.org/cargo/reference/config.html>.
178
179 -q, --quiet
180 Do not print cargo log messages. May also be specified with the
181 term.quiet config value
182 <https://doc.rust-lang.org/cargo/reference/config.html>.
183
184 --color when
185 Control when colored output is used. Valid values:
186
187 • auto (default): Automatically detect if color support is
188 available on the terminal.
189
190 • always: Always display colors.
191
192 • never: Never display colors.
193
194 May also be specified with the term.color config value
195 <https://doc.rust-lang.org/cargo/reference/config.html>.
196
197 --message-format fmt
198 The output format for diagnostic messages. Can be specified
199 multiple times and consists of comma-separated values. Valid
200 values:
201
202 • human (default): Display in a human-readable text format.
203 Conflicts with short and json.
204
205 • short: Emit shorter, human-readable text messages. Conflicts
206 with human and json.
207
208 • json: Emit JSON messages to stdout. See the reference
209 <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
210 for more details. Conflicts with human and short.
211
212 • json-diagnostic-short: Ensure the rendered field of JSON
213 messages contains the "short" rendering from rustc. Cannot be
214 used with human or short.
215
216 • json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
217 messages contains embedded ANSI color codes for respecting
218 rustc's default color scheme. Cannot be used with human or
219 short.
220
221 • json-render-diagnostics: Instruct Cargo to not include rustc
222 diagnostics in in JSON messages printed, but instead Cargo
223 itself should render the JSON diagnostics coming from rustc.
224 Cargo's own JSON diagnostics and others coming from rustc are
225 still emitted. Cannot be used with human or short.
226
227 Manifest Options
228 --manifest-path path
229 Path to the Cargo.toml file. By default, Cargo searches for the
230 Cargo.toml file in the current directory or any parent directory.
231
232 --frozen, --locked
233 Either of these flags requires that the Cargo.lock file is
234 up-to-date. If the lock file is missing, or it needs to be updated,
235 Cargo will exit with an error. The --frozen flag also prevents
236 Cargo from attempting to access the network to determine if it is
237 out-of-date.
238
239 These may be used in environments where you want to assert that the
240 Cargo.lock file is up-to-date (such as a CI build) or want to avoid
241 network access.
242
243 --offline
244 Prevents Cargo from accessing the network for any reason. Without
245 this flag, Cargo will stop with an error if it needs to access the
246 network and the network is not available. With this flag, Cargo
247 will attempt to proceed without the network if possible.
248
249 Beware that this may result in different dependency resolution than
250 online mode. Cargo will restrict itself to crates that are
251 downloaded locally, even if there might be a newer version as
252 indicated in the local copy of the index. See the cargo-fetch(1)
253 command to download dependencies before going offline.
254
255 May also be specified with the net.offline config value
256 <https://doc.rust-lang.org/cargo/reference/config.html>.
257
258 Common Options
259 +toolchain
260 If Cargo has been installed with rustup, and the first argument to
261 cargo begins with +, it will be interpreted as a rustup toolchain
262 name (such as +stable or +nightly). See the rustup documentation
263 <https://rust-lang.github.io/rustup/overrides.html> for more
264 information about how toolchain overrides work.
265
266 -h, --help
267 Prints help information.
268
269 -Z flag
270 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
271 details.
272
273 Miscellaneous Options
274 -j N, --jobs N
275 Number of parallel jobs to run. May also be specified with the
276 build.jobs config value
277 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
278 to the number of CPUs.
279
280 --keep-going
281 Build as many crates in the dependency graph as possible, rather
282 than aborting the build on the first one that fails to build.
283 Unstable, requires -Zunstable-options.
284
286 See the reference
287 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
288 for details on environment variables that Cargo reads.
289
291 • 0: Cargo succeeded.
292
293 • 101: Cargo failed to complete.
294
296 1. Build the local package documentation and its dependencies and
297 output to target/doc.
298
299 cargo doc
300
302 cargo(1), cargo-rustdoc(1), rustdoc(1)
303
304
305
306 CARGO-DOC(1)