CARGO-DOC(1)
๐ CARGO-DOC(1) ๐ โ the manual, bestie! โจ
okay so like, this is the manual page for cargo doc, and it's literally everything you need to know to build docs without losing your mind ๐
โจ NAME โจ
cargo-doc โ Build a packageโs documentation ๐ฆ
๐ธ SYNOPSIS ๐ธ
cargo doc [options]
๐ DESCRIPTION ๐
okay bestie, so cargo doc builds the documentation for your local package and all its dependencies. The output goes into target/doc in rustdocโs usual format. no cap, it's that simple โจ
Note: Documentation generation is cumulative: existing doc files in the target directory are preserved across differentcargo docinvocations. To remove existing generated docs, pass--doctocargo-clean(1). ๐ don't say I didn't warn you.
๐ OPTIONS ๐
๐ Documentation Options ๐
--openโ Open the docs in a browser after building them. This will use 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. bye felicia ๐--document-private-itemsโ Include non-public items in the documentation. This will be enabled by default if documenting a binary target. ๐ฅ
๐ฆ Package Selection ๐ฆ
By default, when no package selection options are given, the packages selected depend on the selected manifest file (based on the current working directory if --manifest-path is not given). If the manifest is the root of a workspace then the workspaces default members are selected, otherwise only the package defined by the manifest will be selected.
The default members of a workspace can be set explicitly with the workspace.default-members key in the root manifest. If this is not set, a virtual workspace will include all workspace members (equivalent to passing --workspace), and a non-virtual workspace will include only the root crate itself. ๐
-p specโฆ,--package specโฆโ Document only the specified packages. Seecargo-pkgid(1)for the SPEC format. This flag may be specified multiple times and supports common Unix glob patterns like*,?and[]. However, to avoid your shell accidentally expanding glob patterns before Cargo handles them, you must use single quotes or double quotes around each pattern. ๐--workspaceโ Document all members in the workspace. ๐--allโ Deprecated alias for--workspace. ๐--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[]. However, 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. 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 allow you to 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 withpackage-name/feature-namesyntax. This flag may be specified multiple times, which enables all specified features. ๐ฅ--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 (
https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-path) for more information. ๐บ๏ธ
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 (https://doc.rust-lang.org/cargo/reference/build-cache.html) documentation for more details. ๐ฆ
-r,--releaseโ Document optimized artifacts with the release profile. See also the--profileoption 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โ Output information 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. ๐
๐ 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). ๐ฃ๏ธ-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). ๐คซ--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 theterm.colorconfig 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 (https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages) for more details. 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. โ๏ธ
โจ Common Options โจ
+toolchainโ bestie, if Cargo got installed through rustup and the very first argument you hand tocargostarts with a+, Cargo treats that whole thing as a rustup toolchain name (think+stableor+nightly). Wanna know how toolchain overrides actually work? Go read the rustup docs, they got you:https://rust-lang.github.io/rustup/overrides.html๐--config KEY=VALUEorPATHโ this one overrides a Cargo configuration value, no cap. The argument is either TOML syntax in the formKEY=VALUE, or a path pointing to an extra configuration file. You can pass this flag as many times as you want, it's not a one-and-done situation. More deets live in the command-line overrides section:https://doc.rust-lang.org/cargo/reference/config.html#command-line-overridesโจ-C PATHโ changes the current working directory before it runs 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 which directories get searched when discovering.cargo/config.toml, for example. โ ๏ธ Important: this option has to show up before the command name, like this:
cargo -C path/to/my-project build
Also it's only a thing on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and it needs the -Z unstable-options flag to switch on (peep issue #10098: https://github.com/rust-lang/cargo/issues/10098). ๐
-h,--helpโ prints help information. Your lil "what do I even do" button. ๐ซถ-Z flagโ these are the unstable, nightly-only flags for Cargo. Curious what's in there? Runcargo -Z helpand it'll spill everything. ๐ฅ
๐ 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). Left alone, it defaults to the number of logical CPUs. If you give it a negative value, it sets the maximum number of parallel jobs to the number of logical CPUs plus whatever value you provided. If you pass the stringdefault, it sets the value back to defaults. And listen โ it should not be0. Don't do it. ๐--keep-goingโ build as many crates in the dependency graph as it possibly can, instead of aborting the whole build the moment one of them fails to build. It's giving "we don't stop for nobody." ๐
For example, say the current package depends on dependencies fails and works, and one of them fails to build. In that case cargo doc -j1 may or may not build the one that succeeds (it all 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 it ran first fails.
--output-formatโ the output type for the documentation that gets emitted. Valid values, here we go:html(default): emits the documentation in HTML format.json: emits the documentation in the experimental JSON format (https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc_json_types).
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. ๐
๐ ENVIRONMENT ๐
Cargo reads environment variables, yes it does โ and the reference has all the details on exactly which ones: https://doc.rust-lang.org/cargo/reference/environment-variables.html ๐
๐ฆ EXIT STATUS ๐ฆ
0: Cargo succeeded. Slay. ๐101: Cargo failed to complete. ๐ญ
๐ 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 a wrap on the CARGO-DOC(1) page, bestie!! ๐ซถโจ you just read the whole thing, and yeah it's CARGO-DOC(1) โ go forth and document your crates, you absolute icon. ๐
๐๐ฆ
๐ฆ where this page comes from
- centos-stream 10: cargo 1.99.1-1.el10 ยท (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- centos-stream 9: cargo 1.99.1-1.el9 ยท (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- fedora 43: cargo 1.99.0-1.fc43
- fedora 43: cargo 1.99.1-2.fc43 ยท (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- fedora 44: cargo 1.99.0-1.fc44
- fedora 44: cargo 1.99.1-2.fc44 ยท (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms