CARGO-DOC(1)

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

✨ CARGO-DOC ✨

okay bestie, gather round πŸ’– this is the manual page for cargo-doc, straight out of the General Commands Manual, section 1. it's the command you reach for when you need docs built, and honestly? it ate. let's get into it. πŸŽ€

🌸 NAME 🌸

cargo-doc β€” build a package's documentation. that's it. that's the whole job. πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

cargo doc [options]

πŸ’œ DESCRIPTION πŸ’œ

So here's what it does: it builds the documentation for your local package and all of its dependencies. not just yours β€” the whole squad gets documented. 🫢

The output lands in target/doc, in rustdoc's usual format. that's the vibe. ✨


πŸŽ€ OPTIONS πŸŽ€

πŸ“– Documentation Options πŸ“–

  • --open β€” opens the docs in a browser after building them. it'll use your default browser unless you define another one in the BROWSER environment variable, or use the doc.browser config option (https://doc.rust-lang.org/cargo/reference/config.html#docbrowser). very "open the link, bestie" energy. 🌈
  • --no-deps β€” do not build documentation for dependencies. just yours. solo era. πŸ’…
  • --document-private-items β€” include non-public items in the documentation. this one gets enabled by default if you're documenting a binary target. πŸ‘‘

πŸ“¦ Package Selection πŸ“¦

So, by default β€” when you pass no package selection options β€” which packages get picked depends on the selected manifest file (which itself is based on the current working directory, unless you gave --manifest-path). If that manifest is the root of a workspace, then the workspace's default members get selected. Otherwise, only the package defined by that manifest gets selected. that's the whole rule, iykyk. 🧚

And the default members of a workspace can be set explicitly with the workspace.default-members key in the root manifest. If that's not set:

  • a virtual workspace includes all workspace members (equivalent to passing --workspace), and
  • a non-virtual workspace includes only the root crate itself.
  • -p spec…, --package spec… β€” document only the packages you specify. check cargo-pkgid(1) for the SPEC format. this flag may be specified multiple times, and it supports common Unix glob patterns like *, ? and []. BUT β€” and this part matters β€” to avoid your shell accidentally expanding those glob patterns before Cargo handles them, you must use single quotes or double quotes around each pattern. no cap. 😭
  • --workspace β€” document all members in the workspace. the entire group chat. 🫢
  • --all β€” deprecated alias for --workspace. it's giving legacy. πŸ’€
  • --exclude *SPEC*… β€” exclude the specified packages. must be used in conjunction with the --workspace flag. this flag may be specified multiple times and supports common Unix glob patterns like *, ? and []. same deal as before: to avoid your shell accidentally expanding glob patterns before Cargo handles them, you must use single quotes or double quotes around each pattern. πŸ™ˆ

🎯 Target Selection 🎯

When no target selection options are given, cargo doc 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. ✨

The default behavior can be changed by setting doc = false for the target in the manifest settings. But heads up bestie β€” using target selection options will ignore the doc flag and will always document the given target. periodt.

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

πŸŽ›οΈ 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 for more details: https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options

  • -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. slay. πŸ”₯
  • --all-features β€” activate all available features of all selected packages. all of them. every last one. πŸ‘‘
  • --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 for more details: https://doc.rust-lang.org/cargo/guide/build-cache.html
  • -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 for more details on profiles: https://doc.rust-lang.org/cargo/reference/profiles.html
  • --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 on 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 for more details: https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages. 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.
Beware that 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 πŸ’«

  • +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 for more information about how toolchain overrides work: https://rust-lang.github.io/rustup/overrides.html

  • --config KEY=VALUE or PATH β€” okay so this one overrides a Cargo configuration value πŸ’…. The argument has to be in TOML syntax as KEY=VALUE, or you can hand it a path to an extra config file instead. And the tea? you can pass this flag multiple times β€” stack them up bestie ✨. Peep the command-line overrides section at https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides for the whole lore.
  • -C PATH β€” this one changes the current working directory before any of the specified operations even run πŸŒ€. Which means it messes with 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. Heads up: this option has to appear before the command name, like cargo -C path/to/my-project build. Periodt πŸ’–.
Real talk: this option is only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and it needs the -Z unstable-options flag to even turn on (see issue #10098 at https://github.com/rust-lang/cargo/issues/10098). No stable vibes here, sorry bestie 😭.
  • -h, --help β€” prints help information. The classic 🫢. When in doubt, ask for help.
  • -Z flag β€” the unstable, nightly-only flags for Cargo 🧚. Run cargo -Z help for the details, iykyk.

✨ Miscellaneous Options ✨ πŸŽ€

  • -j N, --jobs N β€” how many parallel jobs to run πŸ”₯. You can also set this with the build.jobs config value (https://doc.rust-lang.org/cargo/reference/config.html). It 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 it (math girlie mathing πŸ’…). If a string default is provided, it sets the value back to defaults. Should not be 0 β€” literally do not, that's not the move πŸ’€.
  • --keep-going β€” this one says build as many crates in the dependency graph as possible, instead of aborting the whole build the second one of them fails to build 🌈. Resilient queen behaviour, honestly.

Like, picture it: your current package depends on dependencies that fail and work, and one of them fails to build. Then cargo doc -j1 may or may not build the one that succeeds (depends on which of the two builds Cargo picked to run first πŸ™ˆ), whereas cargo doc -j1 --keep-going would definitely run both builds, even if the one that runs first fails. Iconic and reliable ✨.


🌸 ENVIRONMENT 🌸

Cargo reads some environment variables, bestie β€” see the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for all the details on which ones πŸ¦‹.


πŸ’– EXIT STATUS πŸ’–

  • 0: Cargo succeeded. Slay πŸŽ‰πŸ‘‘
  • 101: Cargo failed to complete. Not slay πŸ˜­πŸ’€

⭐ EXAMPLES ⭐

  1. Build the local package documentation and its dependencies and output to target/doc πŸ“šβœ¨:
cargo doc

🫢 SEE ALSO 🫢

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


And that's the whole page, bestie πŸŽ€πŸ’œ β€” it's the CARGO-DOC(1) man page from the Cargo docs (source/version and date live in that footer line at the bottom of the real page, so go peep it there if you need the receipts πŸ“œβœ¨). Now go document something, you main character πŸ’…πŸŒŸ

πŸ“¦ where this page comes from