CARGO-RUSTDOC(1)

πŸ“¦ version 1.77.2, in ubuntu jammy, ubuntu noble

πŸŽ€ NAME πŸŽ€

cargo-rustdoc β€” bestie, this builds your package's docs, but with your custom flags. πŸ’–


🌸 SYNOPSIS 🌸

cargo rustdoc [options] [-- args]

✨ DESCRIPTION ✨

okay so here's the vibe: Cargo takes the target you picked for the current package (or the package you named with -p, if you did that) and documents it, and those args you tacked on get handed straight to the final rustdoc invocation. slay.

⚠️ but listen β€” dependencies do not get documented as part of this command. like, at all. nope.

also, heads up: rustdoc will still unconditionally receive arguments like -L, --extern, and --crate-type, no matter what you do. your specified args just get added on top of the rustdoc invocation. it's giving "plus, not instead". 🫢

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

πŸ’€ 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 of --lib, --bin, etc., to select which target gets compiled. no cap.

if you wanna pass flags to all rustdoc processes spawned by Cargo (not just this one), 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 sitting in your current working directory is the one that gets selected. the -p flag lets you choose a different package in a workspace. main character energy, but for packages.

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

🎯 Target Selection 🎯

when you give no 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 skipped if they have required-features that are missing. (rude, but fair.)

passing target selection flags means you document only the specified targets. periodt.

ngl, this part is important: --bin, --example, --test and --bench flags also support common Unix glob patterns like *, ? and []. BUT β€” to avoid your shell accidentally expanding glob patterns before Cargo can handle them β€” you must use single quotes or double quotes around each glob pattern. quote your globs, bestie. πŸ™ˆ

  • --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 in test mode 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 in benchmark mode 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. the "just do everything" button. πŸ’…

🌈 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. πŸ’–

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. go big or go home.
  • --no-default-features β€” do not activate the default feature of the selected packages.

πŸ”₯ 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 documentation <https://doc.rust-lang.org/cargo/guide/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.
  • --ignore-rust-version β€” document the target even if the selected Rust compiler is older than the required Rust version as configured in the project's rust-version field. (living dangerously, love that for you.)
  • --timings=fmts β€” output information about 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. 🎯

πŸ’¬ 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>. (shhhh mode 🀫)
  • --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. πŸ”
  • --frozen, --locked β€” either of these flags requires that the Cargo.lock file is up-to-date. if the lock file is missing, or it needs to be updated, Cargo will exit with an error. the --frozen flag also prevents Cargo from attempting to access the network to determine if it is out-of-date.

these may be used in environments where you want to assert that the Cargo.lock file is up-to-date (such as a CI build) or want to avoid network access. 🧊

  • --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. ✈️

...so bestie, back to --offline for one sec, because there's a lil plot twist 🫣

⚠️ Beware: this may result in 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 https://doc.rust-lang.org/cargo/reference/config.html.


🫢 Common Options 🫢

These are the lil besties that show up everywhere, no matter which cargo command you're running. Slay.

  • +toolchain β€” okay so if Cargo got installed with rustup, and the first argument to cargo starts with +, it gets read as a rustup toolchain name (like +stable or +nightly). Wanna know how toolchain overrides work? The rustup docs got you: https://rust-lang.github.io/rustup/overrides.html. πŸ’…
  • --config KEY=VALUE or PATH β€” overrides a Cargo configuration value. The argument should be in TOML syntax of KEY=VALUE, or handed over as a path to an extra configuration file. This flag may be specified multiple times (iconic, honestly). See the command-line overrides section at https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides for more. ✨
  • -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.
πŸŒ™ Heads up: 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 https://github.com/rust-lang/cargo/issues/10098).
  • -h, --help β€” prints help information. The og "what do I do now" button. πŸ™ˆ
  • -Z flag β€” unstable (nightly-only) flags to Cargo. Run cargo -Z help for details. Living on the edge fr fr πŸ’€

πŸŽ€ Miscellaneous Options πŸŽ€

The grab-bag. Random but make it useful.

  • -j N, --jobs N β€” number of parallel jobs to run. May also be specified with the build.jobs config value 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. 🚫
  • --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. It's giving "we don't stop, we keep going" energy.

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. periodt.

πŸŒ™ 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. iykyk πŸ’œ


⭐ EXIT STATUS ⭐

  • 0: Cargo succeeded. πŸŽ‰ main character moment.
  • 101: Cargo failed to complete. 😭 we've all been there bestie.

πŸ’– EXAMPLES πŸ’–

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

Look at her go. Custom CSS? We love a stylized queen. πŸ’…βœ¨


πŸ¦‹ SEE ALSO πŸ¦‹

cargo(1), cargo-doc(1), rustdoc(1) β€” the whole friend group, together at last 🫢


And that's a wrap on the cargo-rustdoc(1) page, babes! This lil legend lives in the Cargo manual (that's the source), and it's dated 2026-01-15 β€” so if you're reading this way later, go double check you're not on a stale copy. Now go build something gorgeous and read the docs. bye bestie πŸ’–πŸŽ€πŸŒΈ

πŸ“¦ where this page comes from