CARGO-DOC(1)
β¨ 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 theBROWSERenvironment variable, or use thedoc.browserconfig 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.
-pspecβ¦,--packagespecβ¦ β document only the packages you specify. checkcargo-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--workspaceflag. 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
-Ffeatures,--featuresfeatures β space or comma separated list of features to activate. features of workspace members may be enabled withpackage-name/feature-namesyntax. 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 βοΈ
--targettriple β document for the given architecture. the default is the host architecture. the general format of the triple is<arch><sub>-<vendor>-<sys>-<abi>. runrustc --print target-listfor 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--profileoption for choosing a specific profile by name. π₯--profilename β 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'srust-versionfield. 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;--timingswithout 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 filecargo-timing.htmlto thetarget/cargo-timingsdirectory 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-dirdirectory β directory for all generated artifacts and intermediate files. may also be specified with theCARGO_TARGET_DIRenvironment variable, or thebuild.target-dirconfig value (https://doc.rust-lang.org/cargo/reference/config.html). defaults totargetin 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 theterm.verboseconfig value (https://doc.rust-lang.org/cargo/reference/config.html). π-q,--quietβ do not print cargo log messages. may also be specified with theterm.quietconfig value (https://doc.rust-lang.org/cargo/reference/config.html). π€«--colorwhen β 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-formatfmt β 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 withshortandjson.short: emit shorter, human-readable text messages. conflicts withhumanandjson.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 withhumanandshort.json-diagnostic-short: ensure therenderedfield of JSON messages contains the "short" rendering from rustc. cannot be used withhumanorshort.json-diagnostic-rendered-ansi: ensure therenderedfield of JSON messages contains embedded ANSI color codes for respecting rustc's default color scheme. cannot be used withhumanorshort.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 withhumanorshort.
π Manifest Options π
--manifest-pathpath β path to theCargo.tomlfile. by default, Cargo searches for theCargo.tomlfile in the current directory or any parent directory. π--frozen,--lockedβ either of these flags requires that theCargo.lockfile is up-to-date. if the lock file is missing, or it needs to be updated, Cargo will exit with an error. the--frozenflag 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+stableor+nightly). see the rustup documentation for more information about how toolchain overrides work:https://rust-lang.github.io/rustup/overrides.html
--configKEY=VALUE or PATH β okay so this one overrides a Cargo configuration value π . The argument has to be in TOML syntax asKEY=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 athttps://doc.rust-lang.org/cargo/reference/config.html#command-line-overridesfor the whole lore.-CPATH β 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, likecargo -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-optionsflag to even turn on (see issue #10098 athttps://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.-Zflag β the unstable, nightly-only flags for Cargo π§. Runcargo -Z helpfor the details, iykyk.
β¨ Miscellaneous Options β¨ π
-jN,--jobsN β how many parallel jobs to run π₯. You can also set this with thebuild.jobsconfig 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 stringdefaultis provided, it sets the value back to defaults. Should not be0β 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 β
- 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
- ubuntu jammy: cargo-1.78 1.78.0+dfsg1ubuntu1~bpo0-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.78 1.78.0+dfsg1ubuntu1-0ubuntu0.24.04.2 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms