]> git.lizzy.rs Git - rust.git/blob - src/doc/rustdoc/src/command-line-arguments.md
Rollup merge of #80323 - camelid:codegen-base-docs, r=nagisa
[rust.git] / src / doc / rustdoc / src / command-line-arguments.md
1 # Command-line arguments
2
3 Here's the list of arguments you can pass to `rustdoc`:
4
5 ## `-h`/`--help`: help
6
7 Using this flag looks like this:
8
9 ```bash
10 $ rustdoc -h
11 $ rustdoc --help
12 ```
13
14 This will show `rustdoc`'s built-in help, which largely consists of
15 a list of possible command-line flags.
16
17 Some of `rustdoc`'s flags are unstable; this page only shows stable
18 options, `--help` will show them all.
19
20 ## `-V`/`--version`: version information
21
22 Using this flag looks like this:
23
24 ```bash
25 $ rustdoc -V
26 $ rustdoc --version
27 ```
28
29 This will show `rustdoc`'s version, which will look something
30 like this:
31
32 ```text
33 rustdoc 1.17.0 (56124baa9 2017-04-24)
34 ```
35
36 ## `-v`/`--verbose`: more verbose output
37
38 Using this flag looks like this:
39
40 ```bash
41 $ rustdoc -v src/lib.rs
42 $ rustdoc --verbose src/lib.rs
43 ```
44
45 This enables "verbose mode", which means that more information will be written
46 to standard out. What is written depends on the other flags you've passed in.
47 For example, with `--version`:
48
49 ```text
50 $ rustdoc --verbose --version
51 rustdoc 1.17.0 (56124baa9 2017-04-24)
52 binary: rustdoc
53 commit-hash: hash
54 commit-date: date
55 host: host-triple
56 release: 1.17.0
57 LLVM version: 3.9
58 ```
59
60 ## `-r`/`--input-format`: input format
61
62 This flag is currently ignored; the idea is that `rustdoc` would support various
63 input formats, and you could specify them via this flag.
64
65 Rustdoc only supports Rust source code and Markdown input formats. If the
66 file ends in `.md` or `.markdown`, `rustdoc` treats it as a Markdown file.
67 Otherwise, it assumes that the input file is Rust.
68
69
70 ## `-w`/`--output-format`: output format
71
72 This flag is currently ignored; the idea is that `rustdoc` would support
73 various output formats, and you could specify them via this flag.
74
75 Rustdoc only supports HTML output, and so this flag is redundant today.
76
77 ## `-o`/`--output`: output path
78
79 Using this flag looks like this:
80
81 ```bash
82 $ rustdoc src/lib.rs -o target/doc
83 $ rustdoc src/lib.rs --output target/doc
84 ```
85
86 By default, `rustdoc`'s output appears in a directory named `doc` in
87 the current working directory. With this flag, it will place all output
88 into the directory you specify.
89
90
91 ## `--crate-name`: controlling the name of the crate
92
93 Using this flag looks like this:
94
95 ```bash
96 $ rustdoc src/lib.rs --crate-name mycrate
97 ```
98
99 By default, `rustdoc` assumes that the name of your crate is the same name
100 as the `.rs` file. `--crate-name` lets you override this assumption with
101 whatever name you choose.
102
103 ## `-L`/`--library-path`: where to look for dependencies
104
105 Using this flag looks like this:
106
107 ```bash
108 $ rustdoc src/lib.rs -L target/debug/deps
109 $ rustdoc src/lib.rs --library-path target/debug/deps
110 ```
111
112 If your crate has dependencies, `rustdoc` needs to know where to find them.
113 Passing `--library-path` gives `rustdoc` a list of places to look for these
114 dependencies.
115
116 This flag takes any number of directories as its argument, and will use all of
117 them when searching.
118
119
120 ## `--cfg`: passing configuration flags
121
122 Using this flag looks like this:
123
124 ```bash
125 $ rustdoc src/lib.rs --cfg feature="foo"
126 ```
127
128 This flag accepts the same values as `rustc --cfg`, and uses it to configure
129 compilation. The example above uses `feature`, but any of the `cfg` values
130 are acceptable.
131
132 ## `--extern`: specify a dependency's location
133
134 Using this flag looks like this:
135
136 ```bash
137 $ rustdoc src/lib.rs --extern lazy-static=/path/to/lazy-static
138 ```
139
140 Similar to `--library-path`, `--extern` is about specifying the location
141 of a dependency. `--library-path` provides directories to search in, `--extern`
142 instead lets you specify exactly which dependency is located where.
143
144 ## `-C`/`--codegen`: pass codegen options to rustc
145
146 Using this flag looks like this:
147
148 ```bash
149 $ rustdoc src/lib.rs -C target_feature=+avx
150 $ rustdoc src/lib.rs --codegen target_feature=+avx
151
152 $ rustdoc --test src/lib.rs -C target_feature=+avx
153 $ rustdoc --test src/lib.rs --codegen target_feature=+avx
154
155 $ rustdoc --test README.md -C target_feature=+avx
156 $ rustdoc --test README.md --codegen target_feature=+avx
157 ```
158
159 When rustdoc generates documentation, looks for documentation tests, or executes documentation
160 tests, it needs to compile some rust code, at least part-way. This flag allows you to tell rustdoc
161 to provide some extra codegen options to rustc when it runs these compilations. Most of the time,
162 these options won't affect a regular documentation run, but if something depends on target features
163 to be enabled, or documentation tests need to use some additional options, this flag allows you to
164 affect that.
165
166 The arguments to this flag are the same as those for the `-C` flag on rustc. Run `rustc -C help` to
167 get the full list.
168
169 ## `--passes`: add more rustdoc passes
170
171 Using this flag looks like this:
172
173 ```bash
174 $ rustdoc --passes list
175 $ rustdoc src/lib.rs --passes strip-priv-imports
176 ```
177
178 An argument of "list" will print a list of possible "rustdoc passes", and other
179 arguments will be the name of which passes to run in addition to the defaults.
180
181 For more details on passes, see [the chapter on them](passes.md).
182
183 See also `--no-defaults`.
184
185 ## `--no-defaults`: don't run default passes
186
187 Using this flag looks like this:
188
189 ```bash
190 $ rustdoc src/lib.rs --no-defaults
191 ```
192
193 By default, `rustdoc` will run several passes over your code. This
194 removes those defaults, allowing you to use `--passes` to specify
195 exactly which passes you want.
196
197 For more details on passes, see [the chapter on them](passes.md).
198
199 See also `--passes`.
200
201 ## `--test`: run code examples as tests
202
203 Using this flag looks like this:
204
205 ```bash
206 $ rustdoc src/lib.rs --test
207 ```
208
209 This flag will run your code examples as tests. For more, see [the chapter
210 on documentation tests](documentation-tests.md).
211
212 See also `--test-args`.
213
214 ## `--test-args`: pass options to test runner
215
216 Using this flag looks like this:
217
218 ```bash
219 $ rustdoc src/lib.rs --test --test-args ignored
220 ```
221
222 This flag will pass options to the test runner when running documentation tests.
223 For more, see [the chapter on documentation tests](documentation-tests.md).
224
225 See also `--test`.
226
227 ## `--target`: generate documentation for the specified target triple
228
229 Using this flag looks like this:
230
231 ```bash
232 $ rustdoc src/lib.rs --target x86_64-pc-windows-gnu
233 ```
234
235 Similar to the `--target` flag for `rustc`, this generates documentation
236 for a target triple that's different than your host triple.
237
238 All of the usual caveats of cross-compiling code apply.
239
240 ## `--default-theme`: set the default theme
241
242 Using this flag looks like this:
243
244 ```bash
245 $ rustdoc src/lib.rs --default-theme=ayu
246 ```
247
248 Sets the default theme (for users whose browser has not remembered a
249 previous theme selection from the on-page theme picker).
250
251 The supplied value should be the lowercase version of the theme name.
252 The set of available themes can be seen in the theme picker in the
253 generated output.
254
255 Note that the set of available themes - and their appearance - is not
256 necessarily stable from one rustdoc version to the next.  If the
257 requested theme does not exist, the builtin default (currently
258 `light`) is used instead.
259
260 ## `--markdown-css`: include more CSS files when rendering markdown
261
262 Using this flag looks like this:
263
264 ```bash
265 $ rustdoc README.md --markdown-css foo.css
266 ```
267
268 When rendering Markdown files, this will create a `<link>` element in the
269 `<head>` section of the generated HTML. For example, with the invocation above,
270
271 ```html
272 <link rel="stylesheet" type="text/css" href="foo.css">
273 ```
274
275 will be added.
276
277 When rendering Rust files, this flag is ignored.
278
279 ## `--html-in-header`: include more HTML in <head>
280
281 Using this flag looks like this:
282
283 ```bash
284 $ rustdoc src/lib.rs --html-in-header header.html
285 $ rustdoc README.md --html-in-header header.html
286 ```
287
288 This flag takes a list of files, and inserts them into the `<head>` section of
289 the rendered documentation.
290
291 ## `--html-before-content`: include more HTML before the content
292
293 Using this flag looks like this:
294
295 ```bash
296 $ rustdoc src/lib.rs --html-before-content extra.html
297 $ rustdoc README.md --html-before-content extra.html
298 ```
299
300 This flag takes a list of files, and inserts them inside the `<body>` tag but
301 before the other content `rustdoc` would normally produce in the rendered
302 documentation.
303
304 ## `--html-after-content`: include more HTML after the content
305
306 Using this flag looks like this:
307
308 ```bash
309 $ rustdoc src/lib.rs --html-after-content extra.html
310 $ rustdoc README.md --html-after-content extra.html
311 ```
312
313 This flag takes a list of files, and inserts them before the `</body>` tag but
314 after the other content `rustdoc` would normally produce in the rendered
315 documentation.
316
317
318 ## `--markdown-playground-url`: control the location of the playground
319
320 Using this flag looks like this:
321
322 ```bash
323 $ rustdoc README.md --markdown-playground-url https://play.rust-lang.org/
324 ```
325
326 When rendering a Markdown file, this flag gives the base URL of the Rust
327 Playground, to use for generating `Run` buttons.
328
329
330 ## `--markdown-no-toc`: don't generate a table of contents
331
332 Using this flag looks like this:
333
334 ```bash
335 $ rustdoc README.md --markdown-no-toc
336 ```
337
338 When generating documentation from a Markdown file, by default, `rustdoc` will
339 generate a table of contents. This flag suppresses that, and no TOC will be
340 generated.
341
342
343 ## `-e`/`--extend-css`: extend rustdoc's CSS
344
345 Using this flag looks like this:
346
347 ```bash
348 $ rustdoc src/lib.rs -e extra.css
349 $ rustdoc src/lib.rs --extend-css extra.css
350 ```
351
352 With this flag, the contents of the files you pass are included at the bottom
353 of Rustdoc's `theme.css` file.
354
355 While this flag is stable, the contents of `theme.css` are not, so be careful!
356 Updates may break your theme extensions.
357
358 ## `--sysroot`: override the system root
359
360 Using this flag looks like this:
361
362 ```bash
363 $ rustdoc src/lib.rs --sysroot /path/to/sysroot
364 ```
365
366 Similar to `rustc --sysroot`, this lets you change the sysroot `rustdoc` uses
367 when compiling your code.
368
369 ### `--edition`: control the edition of docs and doctests
370
371 Using this flag looks like this:
372
373 ```bash
374 $ rustdoc src/lib.rs --edition 2018
375 $ rustdoc --test src/lib.rs --edition 2018
376 ```
377
378 This flag allows `rustdoc` to treat your rust code as the given edition. It will compile doctests with
379 the given edition as well. As with `rustc`, the default edition that `rustdoc` will use is `2015`
380 (the first edition).
381
382 ## `--theme`: add a theme to the documentation output
383
384 Using this flag looks like this:
385
386 ```bash
387 $ rustdoc src/lib.rs --theme /path/to/your/custom-theme.css
388 ```
389
390 `rustdoc`'s default output includes two themes: `light` (the default) and
391 `dark`. This flag allows you to add custom themes to the output. Giving a CSS
392 file to this flag adds it to your documentation as an additional theme choice.
393 The theme's name is determined by its filename; a theme file named
394 `custom-theme.css` will add a theme named `custom-theme` to the documentation.
395
396 ## `--check-theme`: verify custom themes against the default theme
397
398 Using this flag looks like this:
399
400 ```bash
401 $ rustdoc --check-theme /path/to/your/custom-theme.css
402 ```
403
404 While `rustdoc`'s HTML output is more-or-less consistent between versions, there
405 is no guarantee that a theme file will have the same effect. The `--theme` flag
406 will still allow you to add the theme to your documentation, but to ensure that
407 your theme works as expected, you can use this flag to verify that it implements
408 the same CSS rules as the official `light` theme.
409
410 `--check-theme` is a separate mode in `rustdoc`. When `rustdoc` sees the
411 `--check-theme` flag, it discards all other flags and only performs the CSS rule
412 comparison operation.
413
414 ### `--crate-version`: control the crate version
415
416 Using this flag looks like this:
417
418 ```bash
419 $ rustdoc src/lib.rs --crate-version 1.3.37
420 ```
421
422 When `rustdoc` receives this flag, it will print an extra "Version (version)" into the sidebar of
423 the crate root's docs. You can use this flag to differentiate between different versions of your
424 library's documentation.