CARGO-RUSTDOC(1)
π cargo-rustdoc β the vibe-coded manual page π
CARGO-RUSTDOC(1) β like, the General Commands Manual energy, but make it cute. Part 1, bestie, buckle up π
β¨ NAME β¨
cargo-rustdoc β build a package's documentation, using specified custom flags π
π¦ SYNOPSIS π¦
cargo rustdoc [options] [-- args]
πΈ DESCRIPTION πΈ
okay so here's the tea β β the specified target for the current package (or the package you picked with -p, if you did that) gets documented, and whatever args you hand over get passed straight to the final rustdoc invocation. Dependencies do NOT get documented as part of this command, no ma'am. But heads up: rustdoc will still unconditionally receive arguments like -L, --extern, and --crate-type, and your args just get added on top of that. It's giving "we're building on top of the basics, bestie" β¨
for the full lore on rustdoc flags, go look at <https://doc.rust-lang.org/rustdoc/index.html> π
this command requires that only ONE target is being compiled when additional arguments are provided. like, one. singular. if more than one target is available for the current package, you must use the filters --lib, --bin, etc. to select which target is compiled. no choosing chaos today π«Ά
if you wanna pass flags to all rustdoc processes spawned by Cargo, 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>. obsessed with a global setting, ngl π
π 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.browser<https://doc.rust-lang.org/cargo/reference/config.html#docbrowser> configuration option. main character browser energy.
π Package Selection
by default, the package in the current working directory is selected. the -p flag can be used to choose a different package in a workspace. pick your fave, it's your world β¨
-pspec,--packagespec β the package to document. seecargo-pkgid(1)for the SPEC format π
π Target Selection
when no target selection options are given, cargo rustdoc 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. (rude of them but okay π)
passing target selection flags will document only the specified targets. so like, you're in charge now π
note:--bin,--example,--testand--benchflags also support 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 glob pattern. quote it, bestie, or the shell will eat it alive π
--libβ document the package's library π--binnameβ¦ β document the specified binary. this flag may be specified multiple times and supports common Unix glob patterns π§--binsβ document all binary targets π―--examplenameβ¦ β document the specified example. this flag may be specified multiple times and supports common Unix glob patterns β¨--examplesβ document all example targets π--testnameβ¦ β document the specified integration test. this flag may be specified multiple times and 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, and integration tests. be aware that this will also build any required dependencies, so the lib target may be built twice (once as a unittest, and once as a dependency for binaries, integration tests, etc.). targets may be enabled or disabled by setting thetestflag in the manifest settings for the target. yes, double the build, double the drama π--benchnameβ¦ β document the specified benchmark. this flag may be specified multiple times and 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, and bench targets. be aware that this will also build 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 may be enabled or disabled by setting thebenchflag in the manifest settings for the target. again with the double build, it's a whole thing π--all-targetsβ document all targets. this is equivalent to specifying--lib --bins --tests --benches --examples. the everything-bagel of flags π₯―
π 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. defaults are the blueprint, bestie β¨
see the features documentation <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options> for more details π
-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. stack 'em, slay 'em π--all-featuresβ activate all available features of all selected packages. everything, everywhere, all at once π₯--no-default-featuresβ do not activate the default feature of the selected packages. no defaults for you π«
β 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 <https://doc.rust-lang.org/cargo/reference/build-cache.html> documentation for more details. different mode, different directory, same chaotic energy π
-r,--releaseβ document optimized artifacts with thereleaseprofile. see also the--profileoption for choosing a specific profile by name. optimized = glow up π--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 information 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. home sweet build folder π
π«Ά 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>. double it for the extra lore π£οΈ-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 π€«--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 fromrustc. cannot be used withhumanorshort. π©³json-diagnostic-rendered-ansi: ensure therenderedfield of JSON messages contains embedded ANSI color codes for respectingrustc's default color scheme. cannot be used withhumanorshort. πjson-render-diagnostics: instruct Cargo to not includerustcdiagnostics in JSON messages printed, but instead Cargo itself should render the JSON diagnostics coming fromrustc. Cargo's own JSON diagnostics and others coming fromrustcare 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. it'll find it, don't worry π΅οΈ--ignore-rust-versionβ ignorerust-versionspecification in packages. who even needs version checks π--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. deterministic queen behavior π
--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. airplane mode but make it builds βοΈ
to be continued, bestieβ¦ part 2 incoming π
β οΈ ok bestie, real talk before you flip this on: going offline can give you different dependency resolution than online mode. Cargo will only touch crates you've already got downloaded locally, even if the local copy of the index is screaming that a newer version exists. So if you want the fresh stuff, run cargo-fetch(1) first to pull your deps down, and then go offline. no cap. π
You can also turn this on with the net.offline config value β docs live at https://doc.rust-lang.org/cargo/reference/config.html. π¦
--frozenβ this is literally just--lockedand--offlineat the same time. Same thing, one flag, iconic behaviour. β¨--lockfile-path PATHβ changes where the lockfile hangs out, from the default (<workspace_root>/Cargo.lock) over toPATH. Two things:PATHmust end withCargo.lock(so like--lockfile-path /tmp/temporary-lockfile/Cargo.lock), and when you pass this flag Cargo straight-up ignores any existing lockfile at the default path β it'll either use the lockfile sitting atPATH, or write a brand new one intoPATHif nothing's there yet. The glow-up here is that you can run most commands inside read-only directories and just yeet the lockfile intoPATH. π
π¨ nightly only, bestie!! 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-optionsflag to be enabled (see #14421 βhttps://github.com/rust-lang/cargo/issues/14421).
π«Ά Common Options π«Ά
+toolchainβ if Cargo got installed via rustup, and the very first argument tocargostarts with+, Cargo reads it as a rustup toolchain name (think+stableor+nightly). The rustup docs athttps://rust-lang.github.io/rustup/overrides.htmlhave the full tea on how toolchain overrides work. π--config KEY=VALUEorPATHβ overrides a Cargo configuration value. Give it TOML syntax asKEY=VALUE, or hand it a path to an extra configuration file. You can pass this flag as many times as you want (obsessed). More deets in the command-line overrides section:https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides. β¨-C PATHβ swaps the current working directory before running any of the operations you asked for. That changes stuff like where cargo looks by default for the project manifest (Cargo.toml), and which directories get searched when discovering.cargo/config.toml. Important!! This one has to come before the command name β likecargo -C path/to/my-project build. π¦
π¨ nightly only again!! This option is only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the-Z unstable-optionsflag (see #10098 βhttps://github.com/rust-lang/cargo/issues/10098).
-h,--helpβ prints help information. the classic. when in doubt, ask the man page itself. π-Z flagβ unstable (nightly-only) flags for Cargo. Runcargo -Z helpand it'll spill all the details. β
π 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 max number of parallel jobs to the number of logical CPUs plus the value you gave. If you pass the stringdefault, it resets the value back to the defaults. And it should not be 0 β fr fr, don't do that. π--keep-goingβ builds as many crates in the dependency graph as it possibly can, instead of aborting the whole build the second one of them fails. main character energy: keep going. π
Example so it clicks: say the current package depends on two deps, fails and works, and one of them fails to build. Then cargo rustdoc -j1 may or may not build the one that succeeds (it depends on which of the two Cargo picked to run first π), whereas cargo rustdoc -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 are: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).
π¨ nightly only!! This option is 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 πΈ
Wanna know which environment variables Cargo actually reads? Go read the reference, bestie: https://doc.rust-lang.org/cargo/reference/environment-variables.html. All the details are over there. π
β¨ EXIT STATUS β¨
0: Cargo succeeded. π₯³ slay.101: Cargo failed to complete. π
π 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!! this is CARGO-RUSTDOC(1) from the Cargo manual pages β the source and version and date all live in that little footer line at the bottom of the real page, so go peek there if you need the exact stamp. now go build some docs, you ate. πβ¨π¦
π¦ where this page comes from
- ubuntu jammy: cargo-1.89 1.89.0+dfsg~24.04-0ubuntu0.22.04.2 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.89 1.89.0+dfsg~24.04-0ubuntu0.24.04.2 Β· Apache-2.0 WITH LLVM exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms