1CARGO-RUSTDOC(1) CARGO-RUSTDOC(1)
2
3
4
6 cargo-rustdoc - Build a package's documentation, using specified custom
7 flags
8
10 cargo rustdoc [OPTIONS] [-- ARGS]
11
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. To pass flags to all rustdoc
27 processes spawned by Cargo, use the RUSTDOCFLAGS environment variable
28 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
29 or the build.rustdocflags config value
30 <https://doc.rust-lang.org/cargo/reference/config.html>.
31
33 Documentation Options
34 --open
35 Open the docs in a browser after building them. This will use your
36 default browser unless you define another one in the BROWSER
37 environment variable.
38
39 Package Selection
40 By default, the package in the current working directory is selected.
41 The -p flag can be used to choose a different package in a workspace.
42
43 -p SPEC, --package SPEC
44 The package to document. See cargo-pkgid(1) for the SPEC format.
45
46 Target Selection
47 When no target selection options are given, cargo rustdoc will document
48 all binary and library targets of the selected package. The binary will
49 be skipped if its name is the same as the lib target. Binaries are
50 skipped if they have required-features that are missing.
51
52 Passing target selection flags will document only the specified
53 targets.
54
55 --lib
56 Document the package’s library.
57
58 --bin NAME...
59 Document the specified binary. This flag may be specified multiple
60 times.
61
62 --bins
63 Document all binary targets.
64
65 --example NAME...
66 Document the specified example. This flag may be specified multiple
67 times.
68
69 --examples
70 Document all example targets.
71
72 --test NAME...
73 Document the specified integration test. This flag may be specified
74 multiple times.
75
76 --tests
77 Document all targets in test mode that have the test = true
78 manifest flag set. By default this includes the library and
79 binaries built as unittests, and integration tests. Be aware that
80 this will also build any required dependencies, so the lib target
81 may be built twice (once as a unittest, and once as a dependency
82 for binaries, integration tests, etc.). Targets may be enabled or
83 disabled by setting the test flag in the manifest settings for the
84 target.
85
86 --bench NAME...
87 Document the specified benchmark. This flag may be specified
88 multiple times.
89
90 --benches
91 Document all targets in benchmark mode that have the bench = true
92 manifest flag set. By default this includes the library and
93 binaries built as benchmarks, and bench targets. Be aware that this
94 will also build any required dependencies, so the lib target may be
95 built twice (once as a benchmark, and once as a dependency for
96 binaries, benchmarks, etc.). Targets may be enabled or disabled by
97 setting the bench flag in the manifest settings for the target.
98
99 --all-targets
100 Document all targets. This is equivalent to specifying --lib --bins
101 --tests --benches --examples.
102
103 Feature Selection
104 The feature flags allow you to control the enabled features for the
105 "current" package. The "current" package is the package in the current
106 directory, or the one specified in --manifest-path. If running in the
107 root of a virtual workspace, then the default features are selected for
108 all workspace members, or all features if --all-features is specified.
109
110 When no feature options are given, the default feature is activated for
111 every selected package.
112
113 --features FEATURES
114 Space or comma separated list of features to activate. These
115 features only apply to the current directory’s package. Features of
116 direct dependencies may be enabled with <dep-name>/<feature-name>
117 syntax. This flag may be specified multiple times, which enables
118 all specified features.
119
120 --all-features
121 Activate all available features of all selected packages.
122
123 --no-default-features
124 Do not activate the default feature of the current directory’s
125 package.
126
127 Compilation Options
128 --target TRIPLE
129 Document for the given architecture. The default is the host
130 architecture. The general format of the triple is
131 <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
132 a list of supported targets.
133
134 This may also be specified with the build.target config value
135 <https://doc.rust-lang.org/cargo/reference/config.html>.
136
137 Note that specifying this flag makes Cargo run in a different mode
138 where the target artifacts are placed in a separate directory. See
139 the build cache
140 <https://doc.rust-lang.org/cargo/guide/build-cache.html>
141 documentation for more details.
142
143 --release
144 Document optimized artifacts with the release profile. See the
145 PROFILES section for details on how this affects profile selection.
146
147 Output Options
148 --target-dir DIRECTORY
149 Directory for all generated artifacts and intermediate files. May
150 also be specified with the CARGO_TARGET_DIR environment variable,
151 or the build.target-dir config value
152 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
153 to target in the root of the workspace.
154
155 Display Options
156 -v, --verbose
157 Use verbose output. May be specified twice for "very verbose"
158 output which includes extra output such as dependency warnings and
159 build script output. May also be specified with the term.verbose
160 config value
161 <https://doc.rust-lang.org/cargo/reference/config.html>.
162
163 -q, --quiet
164 No output printed to stdout.
165
166 --color WHEN
167 Control when colored output is used. Valid values:
168
169 · auto (default): Automatically detect if color support is
170 available on the terminal.
171
172 · always: Always display colors.
173
174 · never: Never display colors.
175
176 May also be specified with the term.color config value
177 <https://doc.rust-lang.org/cargo/reference/config.html>.
178
179 --message-format FMT
180 The output format for diagnostic messages. Can be specified
181 multiple times and consists of comma-separated values. Valid
182 values:
183
184 · human (default): Display in a human-readable text format.
185
186 · short: Emit shorter, human-readable text messages.
187
188 · json: Emit JSON messages to stdout. See the reference
189 <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
190 for more details.
191
192 · json-diagnostic-short: Ensure the rendered field of JSON
193 messages contains the "short" rendering from rustc.
194
195 · json-diagnostic-rendered-ansi: Ensure the rendered field of
196 JSON messages contains embedded ANSI color codes for respecting
197 rustc’s default color scheme.
198
199 · json-render-diagnostics: Instruct Cargo to not include rustc
200 diagnostics in in JSON messages printed, but instead Cargo
201 itself should render the JSON diagnostics coming from rustc.
202 Cargo’s own JSON diagnostics and others coming from rustc are
203 still emitted.
204
205 Manifest Options
206 --manifest-path PATH
207 Path to the Cargo.toml file. By default, Cargo searches for the
208 Cargo.toml file in the current directory or any parent directory.
209
210 --frozen, --locked
211 Either of these flags requires that the Cargo.lock file is
212 up-to-date. If the lock file is missing, or it needs to be updated,
213 Cargo will exit with an error. The --frozen flag also prevents
214 Cargo from attempting to access the network to determine if it is
215 out-of-date.
216
217 These may be used in environments where you want to assert that the
218 Cargo.lock file is up-to-date (such as a CI build) or want to avoid
219 network access.
220
221 --offline
222 Prevents Cargo from accessing the network for any reason. Without
223 this flag, Cargo will stop with an error if it needs to access the
224 network and the network is not available. With this flag, Cargo
225 will attempt to proceed without the network if possible.
226
227 Beware that this may result in different dependency resolution than
228 online mode. Cargo will restrict itself to crates that are
229 downloaded locally, even if there might be a newer version as
230 indicated in the local copy of the index. See the cargo-fetch(1)
231 command to download dependencies before going offline.
232
233 May also be specified with the net.offline config value
234 <https://doc.rust-lang.org/cargo/reference/config.html>.
235
236 Common Options
237 -h, --help
238 Prints help information.
239
240 -Z FLAG...
241 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
242 details.
243
244 Miscellaneous Options
245 -j N, --jobs N
246 Number of parallel jobs to run. May also be specified with the
247 build.jobs config value
248 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
249 to the number of CPUs.
250
252 Profiles may be used to configure compiler options such as optimization
253 levels and debug settings. See the reference
254 <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
255 details.
256
257 Profile selection depends on the target and crate being built. By
258 default the dev or test profiles are used. If the --release flag is
259 given, then the release or bench profiles are used.
260
261 ┌────────────────────┬─────────────────┬───────────────────┐
262 │ │ │ │
263 │Target │ Default Profile │ --release Profile │
264 ├────────────────────┼─────────────────┼───────────────────┤
265 │ │ │ │
266 │lib, bin, example │ dev │ release │
267 ├────────────────────┼─────────────────┼───────────────────┤
268 │ │ │ │
269 │test, bench, or any │ test │ bench │
270 │target │ │ │
271 │in "test" or │ │ │
272 │"bench" mode │ │ │
273 └────────────────────┴─────────────────┴───────────────────┘
274
275 Dependencies use the dev/release profiles.
276
278 See the reference
279 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
280 for details on environment variables that Cargo reads.
281
283 0
284 Cargo succeeded.
285
286 101
287 Cargo failed to complete.
288
290 1. Build documentation with custom CSS included from a given file:
291
292 cargo rustdoc --lib -- --extend-css extra.css
293
295 cargo(1), cargo-doc(1), rustdoc(1)
296
297
298
299 2020-02-06 CARGO-RUSTDOC(1)