CARGO-RUSTDOC(1)
π cargo-rustdoc β straight from the General Commands Manual β¨
okay bestie, sit down, hydrate, because this one is a whole command and we're gonna get through it together π«Ά
π NAME
cargo-rustdoc β build a package's documentation, using specified custom flags π
πΈ SYNOPSIS
cargo rustdoc [options] [-- args]
π¦ DESCRIPTION
so here's the tea π: the target you pick for the current package (or the package you point at with -p if you gave one) gets documented, and whatever args you pass ride along into the final rustdoc invocation. Dependencies do not get documented as part of this command, bestie. And heads up β rustdoc is still gonna receive arguments like -L, --extern, and --crate-type no matter what you do; your args just get added on top of that. no cap.
if you want the full lore on rustdoc flags, it's over at <https://doc.rust-lang.org/rustdoc/index.html> β¨
π real talk: this command needs only one target being compiled when you're passing extra arguments. if your current package has more than one target available, you must use the filters like--lib,--bin, etc. to pick which target actually gets compiled. not me warning you twice, but like, I'm warning you twice.
and if you wanna pass flags to all the rustdoc processes Cargo spawns (main character energy, honestly π), use the RUSTDOCFLAGS environment variable <https://doc.rust-lang.org/cargo/reference/environment-variables.html> or the build.rustdocflags config value <https://doc.rust-lang.org/cargo/reference/config.html>.
β¨ OPTIONS β¨
π Documentation Options
--openβ open the docs in a browser after building them π¦. it'll use your default browser, unless you set another one in theBROWSERenvironment variable or use thedoc.browser<https://doc.rust-lang.org/cargo/reference/config.html#docbrowser> configuration option.
π¦ Package Selection
by default, the package in the current working directory is the one selected. the -p flag lets you choose a different package inside a workspace π
-pspec,--packagespec β the package to document. peepcargo-pkgid(1)for the SPEC format, iykyk.
π― Target Selection
when you don't give any target selection options, cargo rustdoc documents all binary and library targets of the selected package. the binary gets skipped if its name is the same as the lib target π. binaries are also skipped if they have required-features that are missing.
passing target selection flags means only the specified targets get documented, periodt.
π little note:--bin,--example,--testand--benchflags also support common Unix glob patterns like*,?and[]. but to stop your shell from accidentally expanding those glob patterns before Cargo can handle them, you gotta wrap each glob pattern in single quotes or double quotes. learned that the hard way fr fr π
--libβ document the package's library.--binnameβ¦ β document the specified binary. this flag can be specified multiple times and supports common Unix glob patterns.--binsβ document all binary targets.--examplenameβ¦ β document the specified example. can be specified multiple times, supports common Unix glob patterns.--examplesβ document all example targets.--testnameβ¦ β document the specified integration test. can be specified multiple times, supports common Unix glob patterns.--testsβ document all targets that have thetest = truemanifest flag set. by default this includes the library and binaries built as unittests, plus integration tests. be aware it'll also build any required dependencies, so the lib target may get built twice (once as a unittest, and once as a dependency for binaries, integration tests, etc.). targets can be enabled or disabled by setting thetestflag in the manifest settings for the target.--benchnameβ¦ β document the specified benchmark. can be specified multiple times, supports common Unix glob patterns.--benchesβ document all targets that have thebench = truemanifest flag set. by default this includes the library and binaries built as benchmarks, plus bench targets. heads up that this also builds any required dependencies, so the lib target may be built twice (once as a benchmark, and once as a dependency for binaries, benchmarks, etc.). targets can be enabled or disabled by setting thebenchflag in the manifest settings for the target.--all-targetsβ document all targets. this is equivalent to specifying--lib --bins --tests --benches --examplesπ«
ποΈ Feature Selection
the feature flags let you control which features are enabled. when no feature options are given, the default feature gets activated for every selected package.
more details live in the features documentation <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options> if you wanna deep dive π
-Ffeatures,--featuresfeatures β space or comma separated list of features to activate. features of workspace members may be enabled withpackage-name/feature-namesyntax. this flag can be specified multiple times, which enables all the 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
--targettriple β 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 wanna 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 info.
this may also be specified with the build.target config value <https://doc.rust-lang.org/cargo/reference/config.html>.
π«Ά note: 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 thereleaseprofile. see also the--profileoption for choosing a specific profile by name.--profilename β document with the given profile. see the reference <https://doc.rust-lang.org/cargo/reference/profiles.html> for more details on profiles.--timings=fmtsβ output info 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 writes a report to the same directory with a timestamp in the filename if you wanna 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 <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 the JSON messages printed, but instead have Cargo itself 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.--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, like CI pipelines. Bestie, if your CI is out here saying "idk, it resolved differently today π€·" you need this flag, no cap.
--offlineβ Cargo is on airplane mode, fr fr. This stops Cargo from touching the network for any reason. Without it, if Cargo needs the network and the network said "not today", Cargo just stops with an error. With it? Cargo tries its very best to proceed without the network. βοΈ
β οΈ Beware, babe β this can give you a different dependency resolution than online mode. Cargo restricts itself to crates that are already downloaded locally, even if the local copy of the index says a newer version exists. Want to go offline the right way? See cargo-fetch(1) to download your dependencies before you disconnect. π«Ά
Can also be set with the net.offline config value: https://doc.rust-lang.org/cargo/reference/config.html
--frozenβ The "both, please" combo meal π. Equivalent to specifying both--lockedand--offlineat once.--lockfile-path PATHβ Moves the lockfile from its default home (<workspace_root>/Cargo.lock) to PATH. And listen β PATH must end withCargo.lock(like--lockfile-path /tmp/temporary-lockfile/Cargo.lock, okay?). Heads up: if you pass--lockfile-path, the existing lockfile at the default path is ignored β Cargo will either use the lockfile from PATH, or write a fresh new lockfile into the PATH you gave it if there isn't one there already. This flag is the moment for running most commands inside read-only directories, writing the lockfile into the PATH you provided. π
π§ 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 be enabled (see #14421:https://github.com/rust-lang/cargo/issues/14421).
π Common Options π
+toolchainβ If Cargo got installed with rustup, and the first argument to cargo starts with+, it gets read as a rustup toolchain name (think+stableor+nightly). Curious how toolchain overrides work? The rustup docs have you:https://rust-lang.github.io/rustup/overrides.html--config KEY=VALUEorPATHβ Overrides a Cargo configuration value. The argument is either TOML syntax asKEY=VALUE, or a path to an extra config file. Yes, you can pass this flag multiple times β stack them, queen π. More deets 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 running any of the operations you specified. This affects stuff like where cargo looks by default for the project manifest (Cargo.toml), and which directories it searches to discover.cargo/config.toml, for example. β οΈ This one has to appear before the command name, likecargo -C path/to/my-project build.
π Nightly-only, and it needs the-Z unstable-optionsflag enabled (see #10098:https://github.com/rust-lang/cargo/issues/10098).
-h,--helpβ Prints help information. The classic. When in doubt, ask for help, bestie. π-Z flagβ Unstable (nightly-only) flags for Cargo. Runcargo -Z helpfor the details. It's giving secret menu. π€«
π¦ Miscellaneous Options π¦
-j N,--jobs Nβ How many parallel jobs to run. Can also be set 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 maximum number of parallel jobs to the number of logical CPUs plus the value you gave. If a stringdefaultis provided, it sets the value back to defaults. And it should not be 0 β just don't, okay? π--keep-goingβ Build as many crates in the dependency graph as possible instead of aborting the whole build on the first one that fails. Because one flop shouldn't cancel the entire show. π
For example, if the current package depends on the dependencies fails and works, and one of them fails to build, cargo rustdoc -j1 may or may not build the one that succeeds (depends on which of the two builds Cargo picked to run first). But cargo rustdoc -j1 --keep-going would definitely run both builds, even if the one run first fails.
--output-formatβ The output type for the documentation emitted. Valid values:html(default): Emit the documentation in HTML format.json: Emit the documentation in the experimental JSON format:https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc_json_types
π Only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the-Z unstable-optionsflag to be enabled.
πΈ ENVIRONMENT πΈ
Cargo reads environment variables, and all the details live in the reference: https://doc.rust-lang.org/cargo/reference/environment-variables.html
β¨ EXIT STATUS β¨
0: Cargo succeeded. π we ate.101: Cargo failed to complete. π it's not giving.
π EXAMPLES π
- Build documentation with custom CSS included from a given file:
cargo rustdoc --lib -- --extend-css extra.css
π SEE ALSO π
cargo(1), cargo-doc(1), rustdoc(1)
And that's the whole page, bestie β cargo-rustdoc(1) from the Cargo manual pages, and yeah the footer down there is just the source and date stamp that every manpage wears like a little name tag. Now go forth and document your crates, you absolute icon. π
β¨π¦
π¦ where this page comes from
- ubuntu jammy: cargo-1.91 1.91.1+dfsg~22.04-0ubuntu0.22.04.3 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.91 1.91.1+dfsg~24.04-0ubuntu0.24.04.2 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.91 1.91.1+dfsg~24.04-0ubuntu0.24.04.3 Β· Apache-2.0 WITH LLVM exception
- ubuntu questing: cargo-1.91 1.91.1+dfsg-0ubuntu3~25.10.1
- ubuntu resolute: cargo-1.91 1.91.1+dfsg-0ubuntu3 Β· 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