CARGO-RUSTDOC(1)
π cargo-rustdoc
hiii bestie, this is the manual page for cargo-rustdoc, straight outta the General Commands Manual (section 1). it's giving "build your docs, but make it custom." let's get into it β¨
πΈ NAME
cargo-rustdoc β build a package's documentation, using specified custom flags π
β¨ SYNOPSIS
cargo rustdoc [options] [-- args]
π¦ DESCRIPTION
okay so. the target you picked for the current package (or the package you named with -p if you provided it) gets documented, and whatever you put in args gets passed straight into the final rustdoc invocation. dependencies do NOT get documented as part of this command β not their moment, not their era. π
but real talk: rustdoc still unconditionally receives arguments like -L, --extern, and --crate-type, and your specified args just get added to the rustdoc invocation on top of that. π
for the full tea on rustdoc flags, go read https://doc.rust-lang.org/rustdoc/index.html π«Ά
also!! this command requires that only one target is being compiled when you pass additional arguments. if more than one target is available for the current package, you must use the filters --lib, --bin, etc. to select which target gets compiled. pick a lane, queen π
and if you want flags passed to every single rustdoc process 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). π
π OPTIONS
π Documentation Options
--openβ opens the docs in a browser after they're built. it'll 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). so cute, so convenient π«Ά
π¦ Package Selection
by default, the package in the current working directory is the chosen one. the -p flag lets you pick a different package in a workspace. main character swap β¨
-pspec,--packagespec β the package to document. seecargo-pkgid(1)for the SPEC format. iykyk π
π― Target Selection
when you give no target selection options, 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. and binaries get skipped if they have required-features that are missing. π
passing target selection flags means only the specified targets get documented. periodt.
note that--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. no cap, this one bites people π¨
--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 in test mode 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.--benchnameβ¦ β document the specified benchmark. this flag may be specified multiple times and supports common Unix glob patterns.--benchesβ document all targets in benchmark mode 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. it ate, honestly π₯
πΈ 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 at 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. go big or go home π--no-default-featuresβ do not activate the default feature of the selected packages.
π§ 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 documentation (https://doc.rust-lang.org/cargo/guide/build-cache.html) for more details.
-r,--releaseβ document optimized artifacts with the release profile. 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.--ignore-rust-versionβ document the target even if the selected Rust compiler is older than the required Rust version as configured in the project'srust-versionfield. breaking the rules, respectfully π«Ά--timings=fmts β output information about 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. π
π 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). 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.--frozen,--lockedβ either of these flags requires that theCargo.lockfile is up-to-date. if the lock file is missing, or it needs to be updated, Cargo will exit with an error. the--frozenflag also prevents Cargo from attempting to access the network to determine if it is out-of-date.
these may be used in environments where you want to assert that the Cargo.lock file is up-to-date (such as a CI build) or want to avoid network access.
--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 compile βοΈ
okay that's the first half bestie, keep scrolling, there's more where that came from π
Bestie, beware β this can give you 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. β¨ plan ahead, queen β¨
May also be specified with the net.offline config value https://doc.rust-lang.org/cargo/reference/config.html.
π οΈ 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 documentationhttps://rust-lang.github.io/rustup/overrides.htmlfor more information about how toolchain overrides work. tl;dr: pick your toolchain, pick your era π--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 sectionhttps://doc.rust-lang.org/cargo/reference/config.html#command-line-overridesfor more information.-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, bestie, don't test me π
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 https://github.com/rust-lang/cargo/issues/10098).
-h,--helpβ prints help information. when in doubt, ask for help π-Z flagβ unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor details.
π Miscellaneous Options π
-j N,--jobs Nβ number of parallel jobs to run. May also be specified with thebuild.jobsconfig valuehttps://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. zero jobs is not a vibe, it's a paradox π--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. resilience era β¨
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.
--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 formathttps://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 https://doc.rust-lang.org/cargo/reference/environment-variables.html for details on environment variables that Cargo reads. yes, it reads the vibes you set in your shell π«Ά
π EXIT STATUS π
0β Cargo succeeded. we love a win π101β Cargo failed to complete. oof. it's giving tragedy π
π¦ EXAMPLES π¦
- Build documentation with custom CSS included from a given file:
cargo rustdoc --lib -- --extend-css extra.css
custom css? serving looks, literally π
πΈ SEE ALSO πΈ
cargo(1), cargo-doc(1), rustdoc(1)
And that's the whole page, bestie β this was the CARGO-RUSTDOC(1) manual, straight from the Cargo crew, no date stamp needed because it's timeless fr fr. Go build something iconic. π β¨π¦
π¦ where this page comes from
- ubuntu jammy: cargo-1.78 1.78.0+dfsg1ubuntu1~bpo0-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.78 1.78.0+dfsg1ubuntu1-0ubuntu0.24.04.2 Β· 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