|
| 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.y.0 (hash date) |
| 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 --version -v |
| 51 | +rustdoc 1.y.0 (hash date) |
| 52 | +binary: rustdoc |
| 53 | +commit-hash: hash |
| 54 | +commit-date: date |
| 55 | +host: host-triple |
| 56 | +release: 1.y.0 |
| 57 | +LLVM version: x.y |
| 58 | +``` |
| 59 | + |
| 60 | +stable(optopt("r", "input-format", "the input type of the specified file", |
| 61 | + "[rust]")), |
| 62 | +## `-r`/`--input-format`: input format |
| 63 | + |
| 64 | +This flag is currently ignored; the idea is that `rustdoc` would support various |
| 65 | +input formats, and you could specify them via this flag. |
| 66 | + |
| 67 | +Rustdoc only supports Rust source code and Markdown input formats. If the |
| 68 | +file ends in `.md` or `.markdown`, `rustdoc` treats it as a Markdown file. |
| 69 | +Otherwise, it assumes that the input file is Rust. |
| 70 | + |
| 71 | + |
| 72 | +stable(optopt("w", "output-format", "the output type to write", |
| 73 | + "[html]")), |
| 74 | +## `-w`/`--output-format`: output format |
| 75 | + |
| 76 | +This flag is currently ignored; the idea is that `rustdoc` would support |
| 77 | +various output formats, and you could specify them via this flag. |
| 78 | + |
| 79 | +Rustdoc only supports HTML output, and so this flag is redundant today. |
| 80 | + |
| 81 | +## `-o`/`--output`: output path |
| 82 | + |
| 83 | +Using this flag looks like this: |
| 84 | + |
| 85 | +```bash |
| 86 | +$ rustdoc src/lib.rs -o target\\doc |
| 87 | +$ rustdoc src/lib.rs --output target\\doc |
| 88 | +``` |
| 89 | + |
| 90 | +By default, `rustdoc`'s output appears in a directory named `doc` in |
| 91 | +the current working directory. With this flag, it will place all output |
| 92 | +into the directory you specify. |
| 93 | + |
| 94 | + |
| 95 | +stable(optopt("", "crate-name", "specify the name of this crate", "NAME")), |
| 96 | +## `--crate-name`: controlling the name of the crate |
| 97 | + |
| 98 | +Using this flag looks like this: |
| 99 | + |
| 100 | +```bash |
| 101 | +$ rustdoc src/lib.rs --crate-name mycrate |
| 102 | +``` |
| 103 | + |
| 104 | +By default, `rustodc` assumes that the name of your crate is the same name |
| 105 | +as the `.rs` file. `--crate-name` lets you override this assumption with |
| 106 | +whatever name you choose. |
| 107 | + |
| 108 | +stable(optmulti("L", "library-path", "directory to add to crate search path", |
| 109 | + "DIR")), |
| 110 | +## `-L`/`--library-path`: |
| 111 | + |
| 112 | +Using this flag looks like this: |
| 113 | + |
| 114 | +```bash |
| 115 | +$ rustdoc src/lib.rs -L target/debug/deps |
| 116 | +$ rustdoc src/lib.rs --library-path target/debug/deps |
| 117 | +``` |
| 118 | + |
| 119 | +If your crate has dependencies, `rustdoc` needs to know where to find them. |
| 120 | +Passing `--library-path` gives `rustdoc` a list of places to look for these |
| 121 | +dependencies. |
| 122 | + |
| 123 | +This flag takes any number of directories as its argument, and will use all of |
| 124 | +them when searching. |
| 125 | + |
| 126 | + |
| 127 | +## `--cfg`: passing configuration flags |
| 128 | + |
| 129 | +Using this flag looks like this: |
| 130 | + |
| 131 | +```bash |
| 132 | +$ rustdoc src/lib.rs --cfg feature="foo" |
| 133 | +``` |
| 134 | + |
| 135 | +This flag accepts the same values as `rustc --cfg`, and uses it to configure |
| 136 | +compilation. The example above uses `feature`, but any of the `cfg` values |
| 137 | +are acceptable. |
| 138 | + |
| 139 | +## `--extern`: specify a dependency's location |
| 140 | + |
| 141 | +Using this flag looks like this: |
| 142 | + |
| 143 | +```bash |
| 144 | +$ rustdoc src/lib.rs --extern lazy-static=/path/to/lazy-static |
| 145 | +``` |
| 146 | + |
| 147 | +Similar to `--library-path`, `--extern` is about specifying the location |
| 148 | +of a dependency. `--library-path` provides directories to search in, `--extern` |
| 149 | +instead lets you specify exactly which dependency is located where. |
| 150 | + |
| 151 | + |
| 152 | +## `--plugin-path`: loading plugins |
| 153 | + |
| 154 | +Using this flag looks like this: |
| 155 | + |
| 156 | +```bash |
| 157 | +$ rustdoc src/lib.rs --plugin-path=/path/to/plugins |
| 158 | +``` |
| 159 | + |
| 160 | +Similar to `--library-path`, but for plugins. For more, see |
| 161 | +the [chapter on plugins](plugins.html). |
| 162 | + |
| 163 | +See also: `--plugins`. |
| 164 | + |
| 165 | +## `--passes`: add more rustdoc passes |
| 166 | + |
| 167 | +Using this flag looks like this: |
| 168 | + |
| 169 | +```bash |
| 170 | +$ rustdoc --passes list |
| 171 | +$ rustdoc src/lib.rs --passes strip-priv-imports |
| 172 | +``` |
| 173 | + |
| 174 | +An argument of "list" will print a list of possible "rustdoc passes", and other |
| 175 | +arguments will be the name of which passes to run in addition to the defaults. |
| 176 | + |
| 177 | +For more details on passes, see [the chapter on them](passes.html). |
| 178 | + |
| 179 | +See also `--no-defaults`. |
| 180 | + |
| 181 | +## `--plugins`: |
| 182 | + |
| 183 | +Using this flag looks like this: |
| 184 | + |
| 185 | +```bash |
| 186 | +$ rustdoc src/lib.rs --plugins foo bar |
| 187 | +``` |
| 188 | + |
| 189 | +For more, see the [chapter on plugins](plugins.html). |
| 190 | + |
| 191 | +See also: `--plugin-path`. |
| 192 | + |
| 193 | +## `--no-defaults`: don't run default passes |
| 194 | + |
| 195 | +Using this flag looks like this: |
| 196 | + |
| 197 | +```bash |
| 198 | +$ rustdoc src/lib.rs --no-defaults |
| 199 | +``` |
| 200 | + |
| 201 | +By default, `rustdoc` will run several passes over your code. This |
| 202 | +removes those defaults, allowing you to use `--passes` to specify |
| 203 | +exactly which passes you want. |
| 204 | + |
| 205 | +For more details on passes, see [the chapter on them](passes.html). |
| 206 | + |
| 207 | +See also `--passes`. |
| 208 | + |
| 209 | +## `--test`: run code examples as tests |
| 210 | + |
| 211 | +Using this flag looks like this: |
| 212 | + |
| 213 | +```bash |
| 214 | +$ rustdoc src/lib.rs --test |
| 215 | +``` |
| 216 | + |
| 217 | +This flag will run your code examples as tests. For more, see [the chapter |
| 218 | +on documentation tests](documentation-tests.html). |
| 219 | + |
| 220 | +See also `--test-args`. |
| 221 | + |
| 222 | +stable(optmulti("", "test-args", "arguments to pass to the test runner", |
| 223 | + "ARGS")), |
| 224 | +## `--test-args`: |
| 225 | + |
| 226 | +Using this flag looks like this: |
| 227 | + |
| 228 | +```bash |
| 229 | +$ rustdoc src/lib.rs --test --test-args ignored |
| 230 | +``` |
| 231 | + |
| 232 | +This flag will pass options to the test runner when running documentation tests. |
| 233 | +For more, see [the chapter on documentation tests](documentation-tests.html). |
| 234 | + |
| 235 | +See also `--test`. |
| 236 | + |
| 237 | +stable(optopt("", "target", "target triple to document", "TRIPLE")), |
| 238 | +## `--target`: |
| 239 | + |
| 240 | +Using this flag looks like this: |
| 241 | + |
| 242 | +```bash |
| 243 | +$ rustdoc src/lib.rs --target x86_64-pc-windows-gnu |
| 244 | +``` |
| 245 | + |
| 246 | +Similar to the `--target` flag for `rustc`, this generates documentation |
| 247 | +for a target triple that's different than your host triple. |
| 248 | + |
| 249 | +All of the usual caveats of cross-compiling code apply. |
| 250 | + |
| 251 | +## `--markdown-css`: include more CSS files when rendering markdown |
| 252 | + |
| 253 | +Using this flag looks like this: |
| 254 | + |
| 255 | +```bash |
| 256 | +$ rustdoc README.md --markdown-css foo.css |
| 257 | +``` |
| 258 | + |
| 259 | +When rendering Markdown files, this will create a `<link>` element in the |
| 260 | +`<head>` section of the generated HTML. For example, with the invocation above, |
| 261 | + |
| 262 | +```html |
| 263 | +<link rel="stylesheet" type="text/css" href="foo.css"> |
| 264 | +``` |
| 265 | + |
| 266 | +will be added. |
| 267 | + |
| 268 | +When rendering Rust files, this flag is ignored. |
| 269 | + |
| 270 | +## `--html-in-header`: include more HTML in <head> |
| 271 | + |
| 272 | +Using this flag looks like this: |
| 273 | + |
| 274 | +```bash |
| 275 | +$ rustdoc src/lib.rs --html-in-header header.html |
| 276 | +$ rustdoc README.md --html-in-header header.html |
| 277 | +``` |
| 278 | + |
| 279 | +This flag takes a list of files, and inserts them into the `<head>` section of |
| 280 | +the rendered documentation. |
| 281 | + |
| 282 | +## `--html-before-content`: include more HTML before the content |
| 283 | + |
| 284 | +Using this flag looks like this: |
| 285 | + |
| 286 | +```bash |
| 287 | +$ rustdoc src/lib.rs --html-before-content extra.html |
| 288 | +$ rustdoc README.md --html-before-content extra.html |
| 289 | +``` |
| 290 | + |
| 291 | +This flag takes a list of files, and inserts them inside the `<body>` tag but |
| 292 | +before the other content `rustodc` would normally produce in the rendered |
| 293 | +documentation. |
| 294 | + |
| 295 | +## `--html-after-content`: include more HTML after the content |
| 296 | + |
| 297 | +Using this flag looks like this: |
| 298 | + |
| 299 | +```bash |
| 300 | +$ rustdoc src/lib.rs --html-after-content extra.html |
| 301 | +$ rustdoc README.md --html-after-content extra.html |
| 302 | +``` |
| 303 | + |
| 304 | +This flag takes a list of files, and inserts them before the `</body>` tag but |
| 305 | +after the other content `rustodc` would normally produce in the rendered |
| 306 | +documentation. |
| 307 | + |
| 308 | + |
| 309 | +## `--markdown-playground-url`: control the location of the playground |
| 310 | + |
| 311 | +Using this flag looks like this: |
| 312 | + |
| 313 | +```bash |
| 314 | +$ rustdoc README.md --markdown-playground-url https://play.rust-lang.org/ |
| 315 | +``` |
| 316 | + |
| 317 | +When rendering a Markdown file, this flag gives the base URL of the Rust |
| 318 | +Playround, to use for generating `Run` buttons. |
| 319 | + |
| 320 | + |
| 321 | +## `--markdown-no-toc`: don't generate a table of contents |
| 322 | + |
| 323 | +Using this flag looks like this: |
| 324 | + |
| 325 | +```bash |
| 326 | +$ rustdoc README.md --markdown-no-toc |
| 327 | +``` |
| 328 | + |
| 329 | +When generating documentation from a Markdown file, by default, `rustdoc` will |
| 330 | +generate a table of contents. This flag supresses that, and no TOC will be |
| 331 | +generated. |
| 332 | + |
| 333 | + |
| 334 | +## `-e`/`--extend-css`: extend rustdoc's CSS |
| 335 | + |
| 336 | +Using this flag looks like this: |
| 337 | + |
| 338 | +```bash |
| 339 | +$ rustdoc src/lib.rs -e extra.css |
| 340 | +$ rustdoc src/lib.rs --extend-css extra.css |
| 341 | +``` |
| 342 | + |
| 343 | +With this flag, the contents of the files you pass are included at the bottom |
| 344 | +of Rustdoc's `theme.css` file. |
| 345 | + |
| 346 | +While this flag is stable, the contents of `theme.css` are not, so be careful! |
| 347 | +Updates may break your theme extensions. |
| 348 | + |
| 349 | +## `--sysroot`: override the system root |
| 350 | + |
| 351 | +Using this flag looks like this: |
| 352 | + |
| 353 | +```bash |
| 354 | +$ rustdoc src/lib.rs --sysroot /path/to/sysroot |
| 355 | +``` |
| 356 | + |
| 357 | +Similar to `rustc --sysroot`, this lets you change the sysroot `rustdoc` uses |
| 358 | +when compiling your code. |
0 commit comments