CARGO-RUSTDOC(1)

πŸ“¦ version 1.88.0, in ubuntu questing

πŸ’– cargo-rustdoc β€” the vibe-coded manual page πŸ’–

CARGO-RUSTDOC(1) β€” like, the General Commands Manual energy, but make it cute. Part 1, bestie, buckle up πŸŽ€


✨ NAME ✨

cargo-rustdoc β€” build a package's documentation, using specified custom flags πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

cargo rustdoc [options] [-- args]

🌸 DESCRIPTION 🌸

okay so here's the tea β˜• β€” the specified target for the current package (or the package you picked with -p, if you did that) gets documented, and whatever args you hand over get passed straight to the final rustdoc invocation. Dependencies do NOT get documented as part of this command, no ma'am. But heads up: rustdoc will still unconditionally receive arguments like -L, --extern, and --crate-type, and your args just get added on top of that. It's giving "we're building on top of the basics, bestie" ✨

for the full lore on rustdoc flags, go look at <https://doc.rust-lang.org/rustdoc/index.html> πŸ“š

this command requires that only ONE target is being compiled when additional arguments are provided. like, one. singular. if more than one target is available for the current package, you must use the filters --lib, --bin, etc. to select which target is compiled. no choosing chaos today 🫢

if you wanna pass flags to all rustdoc processes spawned by Cargo, 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>. obsessed with a global setting, ngl πŸ’œ


πŸ‘‘ OPTIONS πŸ‘‘

πŸŽ€ Documentation Options

πŸ“ Package Selection

by default, the package in the current working directory is selected. the -p flag can be used to choose a different package in a workspace. pick your fave, it's your world ✨

  • -p spec, --package spec β€” the package to document. see cargo-pkgid(1) for the SPEC format πŸ“–

🌈 Target Selection

when no target selection options are given, cargo rustdoc will document all binary and library targets of the selected package. the binary will be skipped if its name is the same as the lib target. binaries are skipped if they have required-features that are missing. (rude of them but okay πŸ™ˆ)

passing target selection flags will document only the specified targets. so like, you're in charge now πŸ’…

note: --bin, --example, --test and --bench flags also support common Unix glob patterns like *, ? and []. however, to avoid your shell accidentally expanding glob patterns before Cargo handles them, you must use single quotes or double quotes around each glob pattern. quote it, bestie, or the shell will eat it alive 😭
  • --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. yes, double the build, double the drama πŸ’€
  • --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. again with the double build, it's a whole thing 😭
  • --all-targets β€” document all targets. this is equivalent to specifying --lib --bins --tests --benches --examples. the everything-bagel of flags πŸ₯―

πŸ’œ Feature Selection

the feature flags let you control which features are enabled. when no feature options are given, the default feature is activated for every selected package. defaults are the blueprint, bestie ✨

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. stack 'em, slay 'em πŸ‘‘
  • --all-features β€” activate all available features of all selected packages. everything, everywhere, all at once πŸ”₯
  • --no-default-features β€” do not activate the default feature of the selected packages. no defaults for you 🚫

⭐ Compilation Options

  • --target triple β€” document for the given architecture. the default is the host architecture. the general format of the triple is <arch><sub>-<vendor>-<sys>-<abi>. run rustc --print target-list for a list of supported targets. this flag may be specified multiple times πŸ”

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 <https://doc.rust-lang.org/cargo/reference/build-cache.html> documentation for more details. different mode, different directory, same chaotic energy πŸŒ€

  • -r, --release β€” document optimized artifacts with the release profile. see also the --profile option for choosing a specific profile by name. optimized = glow up πŸ’…
  • --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=fmts β€” output information how long each compilation takes, and track concurrency information over time ⏱️ accepts an optional comma-separated list of output formats; --timings without an argument will default to --timings=html. specifying an output format (rather than the default) is unstable and requires -Zunstable-options. valid output formats:
    • html (unstable, requires -Zunstable-options): write a human-readable file cargo-timing.html to the target/cargo-timings directory with a report of the compilation. also write a report to the same directory with a timestamp in the filename if you want to look at older runs. HTML output is suitable for human consumption only, and does not provide machine-readable timing data πŸ“Š
    • json (unstable, requires -Zunstable-options): emit machine-readable JSON information about timing information πŸ€–

πŸ¦‹ 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. home sweet build folder 🏠

🫢 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>. double it for the extra lore πŸ—£οΈ
  • -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>. shhh 🀫
  • --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 Cargo itself should 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. it'll find it, don't worry πŸ•΅οΈ
  • --ignore-rust-version β€” ignore rust-version specification in packages. who even needs version checks πŸ™ˆ
  • --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. deterministic queen behavior πŸ‘‘

  • --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. airplane mode but make it builds ✈️

to be continued, bestie… part 2 incoming πŸ’–

⚠️ ok bestie, real talk before you flip this on: going offline can give you different dependency resolution than online mode. Cargo will only touch crates you've already got downloaded locally, even if the local copy of the index is screaming that a newer version exists. So if you want the fresh stuff, run cargo-fetch(1) first to pull your deps down, and then go offline. no cap. πŸ’…

You can also turn this on with the net.offline config value β€” docs live at https://doc.rust-lang.org/cargo/reference/config.html. πŸ¦‹

  • --frozen β€” this is literally just --locked and --offline at the same time. Same thing, one flag, iconic behaviour. ✨
  • --lockfile-path PATH β€” changes where the lockfile hangs out, from the default (<workspace_root>/Cargo.lock) over to PATH. Two things: PATH must end with Cargo.lock (so like --lockfile-path /tmp/temporary-lockfile/Cargo.lock), and when you pass this flag Cargo straight-up ignores any existing lockfile at the default path β€” it'll either use the lockfile sitting at PATH, or write a brand new one into PATH if nothing's there yet. The glow-up here is that you can run most commands inside read-only directories and just yeet the lockfile into PATH. πŸŽ€
🚨 nightly only, bestie!! This option is only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and it requires the -Z unstable-options flag to be enabled (see #14421 β€” https://github.com/rust-lang/cargo/issues/14421).

🫢 Common Options 🫢

  • +toolchain β€” if Cargo got installed via rustup, and the very first argument to cargo starts with +, Cargo reads it as a rustup toolchain name (think +stable or +nightly). The rustup docs at https://rust-lang.github.io/rustup/overrides.html have the full tea on how toolchain overrides work. πŸ’œ
  • --config KEY=VALUE or PATH β€” overrides a Cargo configuration value. Give it TOML syntax as KEY=VALUE, or hand it a path to an extra configuration file. You can pass this flag as many times as you want (obsessed). More deets in the command-line overrides section: https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides. ✨
  • -C PATH β€” swaps the current working directory before running any of the operations you asked for. That changes stuff like where cargo looks by default for the project manifest (Cargo.toml), and which directories get searched when discovering .cargo/config.toml. Important!! This one has to come before the command name β€” like cargo -C path/to/my-project build. πŸ¦‹
🚨 nightly only again!! 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 (see #10098 β€” https://github.com/rust-lang/cargo/issues/10098).
  • -h, --help β€” prints help information. the classic. when in doubt, ask the man page itself. πŸ™ˆ
  • -Z flag β€” unstable (nightly-only) flags for Cargo. Run cargo -Z help and it'll spill all the details. ⭐

πŸŽ€ Miscellaneous Options πŸŽ€

  • -j N, --jobs N β€” how many parallel jobs to run. Can also be set with the build.jobs config value (https://doc.rust-lang.org/cargo/reference/config.html). Defaults to the number of logical CPUs. If it's negative, it sets the max number of parallel jobs to the number of logical CPUs plus the value you gave. If you pass the string default, it resets the value back to the defaults. And it should not be 0 β€” fr fr, don't do that. πŸ’€
  • --keep-going β€” builds as many crates in the dependency graph as it possibly can, instead of aborting the whole build the second one of them fails. main character energy: keep going. πŸ‘‘

Example so it clicks: say the current package depends on two deps, fails and works, and one of them fails to build. Then cargo rustdoc -j1 may or may not build the one that succeeds (it depends on which of the two Cargo picked to run first πŸ™ƒ), whereas cargo rustdoc -j1 --keep-going would definitely run both builds, even if the one it ran first fails. 🌈

🚨 nightly only!! 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 be enabled.

🌸 ENVIRONMENT 🌸

Wanna know which environment variables Cargo actually reads? Go read the reference, bestie: https://doc.rust-lang.org/cargo/reference/environment-variables.html. All the details are over there. πŸ’–


✨ EXIT STATUS ✨

  • 0: Cargo succeeded. πŸ₯³ slay.
  • 101: Cargo failed to complete. 😭

πŸ“ 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 is CARGO-RUSTDOC(1) from the Cargo manual pages β€” the source and version and date all live in that little footer line at the bottom of the real page, so go peek there if you need the exact stamp. now go build some docs, you ate. πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from