CARGO-RUSTDOC(1)
๐ CARGO-RUSTDOC ๐ โ the manual page, but make it a group chat
(from the General Commands Manual, bestie โ it's cargo-rustdoc, and yes she's iconic)
โจ NAME โจ
cargo-rustdoc โ build a package's documentation, using specified custom flags ๐
๐ฆ SYNOPSIS ๐ฆ
cargo rustdoc [options] [-- args]
๐ธ DESCRIPTION ๐ธ
okay so listen up. The target you picked for the current package โ or the package you named with -p if you went ahead and provided it โ is gonna get documented, and the args you specified get passed straight through to the final rustdoc invocation. slay. ๐
Dependencies are not getting documented by this command. They're not invited. This is a solo main-character moment for your package, periodt.
but โ and this is important โ rustdoc will still unconditionally receive arguments like -L, --extern, and --crate-type, no matter what. Your specified args are simply added to the rustdoc invocation. it's giving "sprinkles on top," not "replacing the whole cake." ๐ง
For the full lore on rustdoc flags, go look at <https://doc.rust-lang.org/rustdoc/index.html>. iykyk.
โ ๏ธ real talk: this command requires that only one target is being compiled when you provide additional arguments. If more than one target is available for the current package, you must use the filters--lib,--bin, etc, to pick which target gets compiled. no vibes-based guessing, okay?
If you wanna pass flags to all the rustdoc processes that Cargo spawns, 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 ๐ฆ. 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>.
๐ฆ Package Selection
By default, the package in the current working directory is the chosen one (main character behavior). The -p flag lets you pick a different package inside a workspace instead.
-pspec,--packagespec โ the package to document ๐ฆ. Seecargo-pkgid(1)for the SPEC format.
๐ฏ Target Selection
When you don't give any target selection options at all, cargo rustdoc will document 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. ๐
Pass target selection flags and you'll document only the specified targets.
๐ก note bestie:--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 must wrap each glob pattern in single quotes or double quotes. don't learn this the hard way ๐ญ
--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 ๐ฆ--test*name*โฆ โ 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. ๐--bench*name*โฆ โ 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. ๐--all-targetsโ document all targets. This is equivalent to specifying--lib --bins --tests --benches --examples. literally everything, no crumbs left ๐ฅ
๐ง Feature Selection
The feature flags are how you control which features get 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.
-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.--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. This 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 documentation <https://doc.rust-lang.org/cargo/reference/build-cache.html> 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โ output information about 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. (sorry robots ๐ค)
๐ 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 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 have Cargo itself 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.--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, bestie โ this can give you a 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 at https://doc.rust-lang.org/cargo/reference/config.html
--frozenโ Equivalent to specifying both--lockedand--offline. Two-for-one, iconic behavior. ๐
โจ Common Options โจ
+toolchainโ If Cargo has been installed with rustup, and the first argument tocargobegins with+, it will be interpreted as a rustup toolchain name (such as+stableor+nightly). See the rustup documentation at https://rust-lang.github.io/rustup/overrides.html for more information about how toolchain overrides work. Lowkey magic. ๐ช--config KEY=VALUEorPATHโ Overrides a Cargo configuration value. The argument should be in TOML syntax ofKEY=VALUE, or provided as a path to an extra configuration file. This flag may be specified multiple times. See the command-line overrides section at https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides for more information. Stack it, bestie, it loves being repeated. ๐-C PATHโ Changes the current working directory before executing any specified operations. This affects things like where cargo looks by default for the project manifest (Cargo.toml), as well as the directories searched for discovering.cargo/config.toml, for example. This option must appear before the command name, for examplecargo -C path/to/my-project build. Order matters, no cap. ๐
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-options flag to enable (see #10098 at https://github.com/rust-lang/cargo/issues/10098).
-h,--helpโ Prints help information. Your girl when you're lost. ๐-Zflag โ Unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor details. Nightly girlies only. ๐
๐ธ Miscellaneous Options ๐ธ
-jN,--jobsN โ Number of parallel jobs to run. May also be specified with thebuild.jobsconfig value at https://doc.rust-lang.org/cargo/reference/config.html. Defaults to the number of logical CPUs. If negative, it sets the maximum number of parallel jobs to the number of logical CPUs plus provided value. If a stringdefaultis provided, it sets the value back to defaults. Should not be0. Not zero, bestie, fr fr. ๐--keep-goingโ Build as many crates in the dependency graph as possible, rather than aborting the build on the first one that fails to build.
For example if the current package depends on dependencies fails and works, one of which fails to build, cargo rustdoc -j1 may or may not build the one that succeeds (depending on which one of the two builds Cargo picked to run first), whereas cargo rustdoc -j1 --keep-going would definitely run both builds, even if the one run first fails. She keeps going. Resilient queen. ๐
--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 at 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 requires the -Z unstable-options flag to enable.
๐ ENVIRONMENT ๐
See the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for details on environment variables that Cargo reads. It's giving "go read the docs, they're right there." ๐
โญ EXIT STATUS โญ
0: Cargo succeeded. Slay. ๐101: Cargo failed to complete. Oop. ๐ญ
๐ฆ 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 one lives under the name CARGO-RUSTDOC(1) โ that's the page name plus section number, iykyk โ and that footer line is just the source/version and date stamp doing its little signature thing. Go forth and document your crates, main character. ๐ โจ
๐ฆ 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