CARGO-RUSTDOC(1)

๐Ÿ“ฆ version 1.96.1, in ubuntu stonking

๐Ÿ’– CARGO-RUSTDOC ๐Ÿ’– โ€” the manual page, but make it a group chat

(from the General Commands Manual, bestie โ€” it's cargo-rustdoc, and yes she's iconic)


โœจ NAME โœจ

cargo-rustdoc โ€” build a package's documentation, using specified custom flags ๐ŸŽ€

๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

cargo rustdoc [options] [-- args]

๐ŸŒธ DESCRIPTION ๐ŸŒธ

okay so listen up. The target you picked for the current package โ€” or the package you named with -p if you went ahead and provided it โ€” is gonna get documented, and the args you specified get passed straight through to the final rustdoc invocation. slay. ๐Ÿ’…

Dependencies are not getting documented by this command. They're not invited. This is a solo main-character moment for your package, periodt.

but โ€” and this is important โ€” rustdoc will still unconditionally receive arguments like -L, --extern, and --crate-type, no matter what. Your specified args are simply added to the rustdoc invocation. it's giving "sprinkles on top," not "replacing the whole cake." ๐Ÿง

For the full lore on rustdoc flags, go look at <https://doc.rust-lang.org/rustdoc/index.html>. iykyk.

โš ๏ธ real talk: this command requires that only one target is being compiled when you provide additional arguments. If more than one target is available for the current package, you must use the filters --lib, --bin, etc, to pick which target gets compiled. no vibes-based guessing, okay?

If you wanna pass flags to all the rustdoc processes that Cargo spawns, use the RUSTDOCFLAGS environment variable <https://doc.rust-lang.org/cargo/reference/environment-variables.html> or the build.rustdocflags config value <https://doc.rust-lang.org/cargo/reference/config.html>. ๐Ÿ’–


๐ŸŒˆ OPTIONS ๐ŸŒˆ

๐Ÿ““ Documentation Options

๐Ÿ“ฆ Package Selection

By default, the package in the current working directory is the chosen one (main character behavior). The -p flag lets you pick a different package inside a workspace instead.

  • -p spec, --package spec โ€” the package to document ๐Ÿ“ฆ. See cargo-pkgid(1) for the SPEC format.

๐ŸŽฏ Target Selection

When you don't give any target selection options at all, cargo rustdoc will document all binary and library targets of the selected package. The binary gets skipped if its name is the same as the lib target. Binaries are also skipped if they have required-features that are missing. ๐Ÿ™ˆ

Pass target selection flags and you'll document only the specified targets.

๐Ÿ’ก note bestie: --bin, --example, --test and --bench flags also support common Unix glob patterns like *, ? and []. BUT โ€” to stop your shell from accidentally expanding those glob patterns before Cargo can handle them โ€” you must wrap each glob pattern in single quotes or double quotes. don't learn this the hard way ๐Ÿ˜ญ
  • --lib โ€” document the package's library ๐Ÿ“š
  • --bin *name*โ€ฆ โ€” document the specified binary. This flag may be specified multiple times and supports common Unix glob patterns โœจ
  • --bins โ€” document all binary targets ๐ŸŽ€
  • --example *name*โ€ฆ โ€” document the specified example. This flag may be specified multiple times and supports common Unix glob patterns ๐ŸŒธ
  • --examples โ€” document all example targets ๐Ÿฆ‹
  • --test *name*โ€ฆ โ€” document the specified integration test. This flag may be specified multiple times and supports common Unix glob patterns ๐Ÿงช
  • --tests โ€” document all targets that have the test = true manifest flag set. By default this includes the library and binaries built as unittests, and integration tests. Be aware that this will also build any required dependencies, so the lib target may be built twice (once as a unittest, and once as a dependency for binaries, integration tests, etc.). Targets may be enabled or disabled by setting the test flag in the manifest settings for the target. ๐Ÿ‘‘
  • --bench *name*โ€ฆ โ€” document the specified benchmark. This flag may be specified multiple times and supports common Unix glob patterns โฑ๏ธ
  • --benches โ€” document all targets that have the bench = true manifest flag set. By default this includes the library and binaries built as benchmarks, and bench targets. Be aware that this will also build any required dependencies, so the lib target may be built twice (once as a benchmark, and once as a dependency for binaries, benchmarks, etc.). Targets may be enabled or disabled by setting the bench flag in the manifest settings for the target. ๐Ÿ’€
  • --all-targets โ€” document all targets. This is equivalent to specifying --lib --bins --tests --benches --examples. literally everything, no crumbs left ๐Ÿ”ฅ

๐Ÿงš Feature Selection

The feature flags are how you control which features get enabled. When no feature options are given, the default feature is activated for every selected package. ๐ŸŒŸ

See the features documentation <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options> for more details.

  • -F features, --features features โ€” space or comma separated list of features to activate โœจ. Features of workspace members may be enabled with package-name/feature-name syntax. This flag may be specified multiple times, which enables all specified features.
  • --all-features โ€” activate all available features of all selected packages ๐Ÿ’…
  • --no-default-features โ€” do not activate the default feature of the selected packages ๐Ÿ™…โ™€๏ธ

๐Ÿ› ๏ธ Compilation Options

  • --target triple โ€” document for the specified target architecture. This flag may be specified multiple times. The default is the host architecture. The general format of the triple is <arch><sub>-<vendor>-<sys>-<abi>. ๐ŸŒ

Possible values:

  • Any supported target in rustc --print target-list.
  • "host-tuple", which will internally be substituted by the host's target. This can be particularly useful if you're cross-compiling some crates, and don't want to specify your host's machine as a target (for instance, an xtask in a shared project that may be worked on by many hosts). ๐Ÿ‘ฏโ™€๏ธ
  • A path to a custom target specification. See Custom Target Lookup Path <https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-path> for more information.

This may also be specified with the build.target config value <https://doc.rust-lang.org/cargo/reference/config.html>.

๐Ÿ“Œ Note that specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. See the build cache documentation <https://doc.rust-lang.org/cargo/reference/build-cache.html> for more details.
  • -r, --release โ€” document optimized artifacts with the release profile ๐Ÿš€. See also the --profile option for choosing a specific profile by name.
  • --profile name โ€” document with the given profile. See the reference <https://doc.rust-lang.org/cargo/reference/profiles.html> for more details on profiles. ๐ŸŽš๏ธ
  • --timings โ€” output information about how long each compilation takes, and track concurrency information over time. โณ

A file cargo-timing.html will be written to the target/cargo-timings directory at the end of the build. An additional report with a timestamp in its filename is also written if you want to look at a previous run. These reports are suitable for human consumption only, and do not provide machine-readable timing data. (sorry robots ๐Ÿค–)

๐Ÿ“ Output Options

  • --target-dir directory โ€” directory for all generated artifacts and intermediate files ๐Ÿ“‚. May also be specified with the CARGO_TARGET_DIR environment variable, or the build.target-dir config value <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to target in the root of the workspace.

๐Ÿ‘€ Display Options

  • -v, --verbose โ€” use verbose output ๐Ÿ—ฃ๏ธ. May be specified twice for "very verbose" output, which includes extra output such as dependency warnings and build script output. May also be specified with the term.verbose config value <https://doc.rust-lang.org/cargo/reference/config.html>.
  • -q, --quiet โ€” do not print cargo log messages ๐Ÿคซ. May also be specified with the term.quiet config value <https://doc.rust-lang.org/cargo/reference/config.html>.
  • --color when โ€” control when colored output is used ๐ŸŽจ. Valid values:
    • auto (default): Automatically detect if color support is available on the terminal.
    • always: Always display colors.
    • never: Never display colors.

May also be specified with the term.color config value <https://doc.rust-lang.org/cargo/reference/config.html>.

  • --message-format fmt โ€” the output format for diagnostic messages ๐Ÿ’ฌ. Can be specified multiple times and consists of comma-separated values. Valid values:
    • human (default): Display in a human-readable text format. Conflicts with short and json.
    • short: Emit shorter, human-readable text messages. Conflicts with human and json.
    • json: Emit JSON messages to stdout. See the reference <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages> for more details. Conflicts with human and short.
    • json-diagnostic-short: Ensure the rendered field of JSON messages contains the "short" rendering from rustc. Cannot be used with human or short.
    • json-diagnostic-rendered-ansi: Ensure the rendered field of JSON messages contains embedded ANSI color codes for respecting rustc's default color scheme. Cannot be used with human or short.
    • json-render-diagnostics: Instruct Cargo to not include rustc diagnostics in JSON messages printed, but instead have Cargo itself render the JSON diagnostics coming from rustc. Cargo's own JSON diagnostics and others coming from rustc are still emitted. Cannot be used with human or short.

๐Ÿ“œ Manifest Options

  • --manifest-path path โ€” path to the Cargo.toml file ๐Ÿ“. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.
  • --ignore-rust-version โ€” ignore rust-version specification in packages ๐Ÿ™ˆ
  • --locked โ€” asserts that the exact same dependencies and versions are used as when the existing Cargo.lock file was originally generated ๐Ÿ”’. Cargo will exit with an error when either of the following scenarios arises:
    • The lock file is missing.
    • Cargo attempted to change the lock file due to a different dependency resolution.

It may be used in environments where deterministic builds are desired, such as in CI pipelines. ๐Ÿ—๏ธ

  • --offline โ€” prevents Cargo from accessing the network for any reason ๐Ÿ“ต. Without this flag, Cargo will stop with an error if it needs to access the network and the network is not available. With this flag, Cargo will attempt to proceed without the network if possible.

Beware, bestie โ€” this can give you a different dependency resolution than online mode. Cargo will restrict itself to crates that are downloaded locally, even if there might be a newer version as indicated in the local copy of the index. See the cargo-fetch(1) command to download dependencies before going offline. ๐Ÿซถ

May also be specified with the net.offline config value at https://doc.rust-lang.org/cargo/reference/config.html

  • --frozen โ€” Equivalent to specifying both --locked and --offline. Two-for-one, iconic behavior. ๐Ÿ‘‘

โœจ Common Options โœจ

  • +toolchain โ€” If Cargo has been installed with rustup, and the first argument to cargo begins with +, it will be interpreted as a rustup toolchain name (such as +stable or +nightly). See the rustup documentation at https://rust-lang.github.io/rustup/overrides.html for more information about how toolchain overrides work. Lowkey magic. ๐Ÿช„
  • --config KEY=VALUE or PATH โ€” Overrides a Cargo configuration value. The argument should be in TOML syntax of KEY=VALUE, or provided as a path to an extra configuration file. This flag may be specified multiple times. See the command-line overrides section at https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides for more information. Stack it, bestie, it loves being repeated. ๐Ÿ’…
  • -C PATH โ€” Changes the current working directory before executing any specified operations. This affects things like where cargo looks by default for the project manifest (Cargo.toml), as well as the directories searched for discovering .cargo/config.toml, for example. This option must appear before the command name, for example cargo -C path/to/my-project build. Order matters, no cap. ๐ŸŽ€

This option is only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the -Z unstable-options flag to enable (see #10098 at https://github.com/rust-lang/cargo/issues/10098).

  • -h, --help โ€” Prints help information. Your girl when you're lost. ๐Ÿ™ˆ
  • -Z flag โ€” Unstable (nightly-only) flags to Cargo. Run cargo -Z help for details. Nightly girlies only. ๐ŸŒ™

๐ŸŒธ Miscellaneous Options ๐ŸŒธ

  • -j N, --jobs N โ€” Number of parallel jobs to run. May also be specified with the build.jobs config value at https://doc.rust-lang.org/cargo/reference/config.html. Defaults to the number of logical CPUs. If negative, it sets the maximum number of parallel jobs to the number of logical CPUs plus provided value. If a string default is provided, it sets the value back to defaults. Should not be 0. Not zero, bestie, fr fr. ๐Ÿ’€
  • --keep-going โ€” Build as many crates in the dependency graph as possible, rather than aborting the build on the first one that fails to build.

For example if the current package depends on dependencies fails and works, one of which fails to build, cargo rustdoc -j1 may or may not build the one that succeeds (depending on which one of the two builds Cargo picked to run first), whereas cargo rustdoc -j1 --keep-going would definitely run both builds, even if the one run first fails. She keeps going. Resilient queen. ๐Ÿ’–

This option is only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the -Z unstable-options flag to enable.


๐ŸŒˆ ENVIRONMENT ๐ŸŒˆ

See the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for details on environment variables that Cargo reads. It's giving "go read the docs, they're right there." ๐Ÿ“–


โญ EXIT STATUS โญ

  • 0: Cargo succeeded. Slay. ๐ŸŽ‰
  • 101: Cargo failed to complete. Oop. ๐Ÿ˜ญ

๐Ÿฆ‹ EXAMPLES ๐Ÿฆ‹

  1. Build documentation with custom CSS included from a given file:
cargo rustdoc --lib -- --extend-css extra.css

๐Ÿ’œ SEE ALSO ๐Ÿ’œ

cargo(1), cargo-doc(1), rustdoc(1)


And that's the whole page, bestie!! ๐Ÿซถ This one lives under the name CARGO-RUSTDOC(1) โ€” that's the page name plus section number, iykyk โ€” and that footer line is just the source/version and date stamp doing its little signature thing. Go forth and document your crates, main character. ๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from