CARGO-DOC(1)

πŸ“¦ version 1.97.1, in ubuntu stonking

🌸 NAME 🌸

cargo-doc β€” Build a package's documentation ✨

okay so this is the CARGO-DOC(1) page from the General Commands Manual, and bestie, it's literally the whole guide to making your docs. iykyk πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

cargo doc [options]

πŸ’– DESCRIPTION πŸ’–

So what it does is: it builds the docs for your local package and all its dependencies 🫢. The output lands in target/doc, in rustdoc's usual format. iconic, no notes.

⚠️ Note: doc generation is cumulative β€” existing doc files in the target directory are preserved across different cargo doc invocations. like, it does NOT wipe the slate clean for you 😭. To remove existing generated docs, pass --doc to cargo-clean(1). that's the move.

✨ OPTIONS ✨

πŸŽ€ Documentation Options πŸŽ€

  • --open β€” open the docs in a browser once they're built. it uses your default browser unless you define another one in the BROWSER environment variable, or use the doc.browser configuration option: <https://doc.rust-lang.org/cargo/reference/config.html#docbrowser> 🌈
  • --no-deps β€” do not build documentation for dependencies. just yours, bestie.
  • --document-private-items β€” include non-public items in the documentation πŸ‘€. this gets enabled by default if you're documenting a binary target. slay.

🧚 Package Selection 🧚

By default, when you don't give any package selection options, which packages get selected depends on the selected manifest file (based on the current working directory if --manifest-path isn't given). If the manifest is the root of a workspace, then the workspace's default members are selected. otherwise, only the package defined by the manifest is selected. fr fr.

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 will include all workspace members (equivalent to passing --workspace), and a non-virtual workspace</mark> will include only the root crate itself.

  • -p spec…, --package spec… β€” document only the specified packages. check cargo-pkgid(1) for the SPEC format. this flag may be specified multiple times, and it supports common Unix glob patterns like *, ? and []. however β€” and this part matters, bestie β€” to avoid your shell accidentally expanding glob patterns before Cargo even gets to handle them, you must use single quotes or double quotes around each pattern πŸ™ˆ
  • --workspace β€” document all members in the workspace πŸ‘‘
  • --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 []. but again, to avoid your shell 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. no cap.

The default behavior can be changed by setting doc = false for the target in the manifest settings. 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. so many features, so little time ✨
  • --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. 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 for more information: <https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-path>

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/reference/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>
  • --timings β€” output information on 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. no cap, humans only πŸ™ˆ


🌸 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>. the way that twice is a whole different vibe 😭
  • -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 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. πŸ”
  • --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 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>

  • --frozen β€” equivalent to specifying both --locked and --offline. two flags in a trench coat πŸ§₯✨

✨ Common Options ✨

  • +toolchain β€” bestie, if Cargo got installed through rustup and the very first argument you hand to cargo starts with +, Cargo is gonna read that as a rustup toolchain name (think +stable or +nightly). Wanna know how toolchain overrides actually work? Go peek at the rustup documentation at https://rust-lang.github.io/rustup/overrides.html. πŸ’…
  • --config KEY=VALUE or --config PATH β€” overrides a Cargo configuration value. The argument is either TOML syntax shaped like KEY=VALUE, or a path pointing at an extra config file. You can drop this flag as many times as you want, she's flexible like that ✨. More deets live in the command-line overrides section at https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides.
  • -C PATH β€” changes the current working directory before running any of the operations you asked for. So it messes with stuff like where cargo goes looking for the project manifest (Cargo.toml) by default, and also the directories it searches when discovering .cargo/config.toml. Lowkey important: this option has to show up before the command name, like cargo -C path/to/my-project build. 🫢
Heads up bestie 😭 this one 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 β€” check issue #10098 at https://github.com/rust-lang/cargo/issues/10098.
  • -h, --help β€” prints help information. The classic. The comfort blanket. πŸ’–
  • -Z flag β€” unstable, nightly-only flags for Cargo. Wanna see them all? Run cargo -Z help for the details.

πŸ¦‹ 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). Defaults to the number of logical CPUs. If it's negative, it sets the max parallel jobs to the number of logical CPUs plus the value you gave. If you pass a string default, it sets the value back to defaults. And it should not be 0. Like, ever. 🚫
  • --keep-going β€” builds as many crates in the dependency graph as it possibly can, instead of aborting the whole build the moment one of them fails. Periodt.

Real talk, here's the example: say the current package depends on the dependencies fails and works, and one of them fails to build. Then cargo doc -j1 may or may not build the one that succeeds β€” it depends on which of the two builds Cargo picked to run first, it's giving chaos honestly πŸ™ˆ β€” whereas cargo doc -j1 --keep-going would definitely run both builds, even if the one it ran first fails. Iconic behavior.


🌈 ENVIRONMENT 🌈

Cargo reads a whole bunch of environment variables. The full rundown lives in the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html. Go read it, iykyk. πŸ‘‘


πŸ’€ 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 vibe, bestie 🫢 this page came from the CARGO-DOC(1) source and it's dated 2026-01-27 β€” go forth and document your crates, mwah πŸ’…πŸ’–

πŸ“¦ where this page comes from