CARGO-RUSTDOC(1)

πŸ“¦ version 1.85.1, in ubuntu jammy, ubuntu noble, ubuntu questing

CARGO-RUSTDOC πŸ’–

cargo-rustdoc β€” like, build your package's docs but with your own custom flags, bestie. It's a section 1 (General Commands Manual) moment, so grab a snack πŸ“


✨ 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 named with -p if you did that) gets documented, and whatever args you pass get handed straight to the final rustdoc invocation. Dependencies do NOT get documented as part of this command, periodt. And just so you know: rustdoc will still unconditionally receive arguments like -L, --extern, and --crate-type no matter what β€” your args just get added on top of those. πŸ’…

For the full rundown 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 you provide additional arguments. So if your current package has more than one target available, you've gotta use the filters --lib, --bin, etc, to pick which target gets compiled. no skipping this step fr fr 😭

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 one selected. The -p flag lets you choose a different package in a workspace. πŸŽ€

  • -p spec, --package spec β€” The package to document. Peep 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 also skipped if they have required-features that are missing. πŸ’€

Passing target selection flags will document only the targets you specified. ✨

Note that --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 gets to handle them, you must use single quotes or double quotes around each glob pattern. πŸ™ˆ
  • --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. the whole menu, no cap 🍽️

🌈 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. everything, all at once, iconic ✨
  • --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/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=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. πŸŽ€

πŸ—£οΈ 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 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. πŸ”
  • --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. ✈️

ok so continuing from the --offline of it all β€” because bestie, going offline is a whole mood and it comes with lore:

⚠️ be careful, because offline mode can give you a different dependency resolution than online mode. Cargo will restrict itself to crates that are downloaded locally, even if there's a newer version just sitting there indicated in your local copy of the index. πŸ‘€ so if you want your deps already on deck before you yeet yourself offline, go look at the cargo-fetch(1) command first.

this can also be set with the net.offline config value (https://doc.rust-lang.org/cargo/reference/config.html).

  • --frozen β€” literally just the same as specifying both --locked and --offline at the same time. two-for-one, slay. πŸ’…
  • --lockfile-path PATH β€” moves the lockfile's path away from the default (<workspace_root>/Cargo.lock) and over to PATH. PATH must end with Cargo.lock (like, for example, --lockfile-path /tmp/temporary-lockfile/Cargo.lock). heads up though: giving --lockfile-path makes Cargo ignore any existing lockfile at the default path, and instead it'll either use the lockfile from PATH, or write a brand new lockfile into the PATH you gave it if nothing's there yet. the whole point? it lets you run most commands in read-only directories by writing the lockfile into the PATH you provided. no cap, iconic behavior. ✨
🚨 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 enable (see #14421 β€” https://github.com/rust-lang/cargo/issues/14421).

🫢 Common Options 🫢

  • +toolchain β€” if Cargo got installed with rustup, and the first argument to cargo starts with +, then Cargo reads it as a rustup toolchain name (think +stable or +nightly). want the whole story on how toolchain overrides work? it's in the rustup documentation: https://rust-lang.github.io/rustup/overrides.html
  • --config KEY=VALUE or PATH β€” overrides a Cargo configuration value, bestie. the argument needs to be in TOML syntax as KEY=VALUE, or you can hand it a path to an extra configuration file. you can pass this flag multiple times, so go off. more deets in the command-line overrides section: https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides
  • -C PATH β€” switches up the current working directory before it executes any of the operations you asked for. this affects stuff like where cargo looks by default for the project manifest (Cargo.toml), and also the directories it searches to discover .cargo/config.toml, for example. this option has to appear before the command name, like this:
cargo -C path/to/my-project build
🚨 again β€” nightly channel only (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and it requires the -Z unstable-options flag to enable (see #10098 β€” https://github.com/rust-lang/cargo/issues/10098).
  • -h, --help β€” prints help information. the classic. the icon. πŸ’–
  • -Z flag β€” the unstable, nightly-only flags for Cargo. run cargo -Z help for the tea. β˜•

🌈 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. and if you pass the string default, it sets the value back to defaults. πŸŒ€ oh and β€” it should not be 0.
  • --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 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, and one of them fails to build, then cargo rustdoc -j1 may or may not build the one that succeeds (it depends 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 it ran first fails. consistent queen. πŸ‘‘

🚨 yep, you guessed it β€” this one 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 enable.

🌸 ENVIRONMENT 🌸

want the full list of environment variables that Cargo reads? it's all in the reference, bestie: https://doc.rust-lang.org/cargo/reference/environment-variables.html


⭐ EXIT STATUS ⭐

  • 0: Cargo succeeded. πŸŽ‰ we love a happy ending.
  • 101: Cargo failed to complete. πŸ’€ it's giving tragedy.

πŸŽ€ 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, periodt. πŸ’– this was CARGO-RUSTDOC(1) β€” the source/version and the date it was generated are chilling down in the footer of your local copy, so peek there for the receipts. now go document something and be the main character of your own build. βœ¨πŸ¦‹πŸ‘‘

πŸ“¦ where this page comes from