CARGO-DOC(1)
πΈ 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 differentcargo docinvocations. like, it does NOT wipe the slate clean for you π. To remove existing generated docs, pass--doctocargo-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 theBROWSERenvironment variable, or use thedoc.browserconfiguration 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. checkcargo-pkgid(1)for theSPECformat. 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--workspaceflag. 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 withpackage-name/feature-namesyntax. 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, anxtaskin 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 thereleaseprofile. See also the--profileoption 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 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>. the way that twice is a whole different vibe π-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>. 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 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-path pathβ path to theCargo.tomlfile. By default, Cargo searches for theCargo.tomlfile in the current directory or any parent directory. π--ignore-rust-versionβ ignorerust-versionspecification in packages. π--lockedβ asserts that the exact same dependencies and versions are used as when the existingCargo.lockfile 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--lockedand--offline. two flags in a trench coat π§₯β¨
β¨ Common Options β¨
+toolchainβ bestie, if Cargo got installed through rustup and the very first argument you hand tocargostarts with+, Cargo is gonna read that as a rustup toolchain name (think+stableor+nightly). Wanna know how toolchain overrides actually work? Go peek at the rustup documentation athttps://rust-lang.github.io/rustup/overrides.html. π--config KEY=VALUEor--config PATHβ overrides a Cargo configuration value. The argument is either TOML syntax shaped likeKEY=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 athttps://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, likecargo -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-optionsflag to even turn on β check issue #10098 athttps://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? Runcargo -Z helpfor the details.
π¦ Miscellaneous Options π¦
-j N,--jobs Nβ how many parallel jobs to run. You can also set this with thebuild.jobsconfig 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 π
- 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
- ubuntu stonking: cargo-1.97 1.97.1+dfsg-0ubuntu1 Β· 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