CARGO-CHECK(1)
πΈ cargo-check π β check the current package
okay so, first things first: this whole thing is the manual page for cargo-check β that's cargo-check(1) in General Commands Manual speak. sit down, grab a boba, we're doing this π§β¨
π« NAME
cargo-check β check the current package π«Ά
β¨ SYNOPSIS
cargo check [options]
π¦ DESCRIPTION
so what this does is: it checks a local package and all of its dependencies for errors. that's it, that's the whole vibe.
the way it works is lowkey iconic β it basically compiles your packages but stops right before the final step of code generation, which means it's faster than running cargo build. no cap. π
and it's not wasteful either β the compiler saves metadata files to disk so future runs just reuse them, as long as the source hasn't been modified. recycling queen π
but bestie, hear me on this one: some diagnostics and errors are only emitted during code generation, so they inherently won't be reported with cargo check. it's giving "mostly complete picture" not "full picture". periodt. π
π OPTIONS
π Package Selection
okay so by default, when you don't give any package selection options, the packages selected depend on the selected manifest file (which is based on the current working directory if --manifest-path isn't given). if the manifest is the root of a workspace then the workspace's default members get selected, otherwise only the package defined by the manifest gets selected. slay, that's the rule β¨
and the default members of a workspace can be set explicitly with the workspace.default-members key in the root manifest. if that's not set:
- a virtual workspace will include all workspace members (equivalent to passing
--workspace) - a non-virtual workspace will include only the root crate itself
-p*spec*β¦,--package*spec*β¦ β check 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. yes really. quote your globs, bestie π--workspaceβ check all members in the workspace. the whole squad π«Ά--allβ deprecated alias for--workspace. it's giving legacy, use the other one π--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. (same rule, every time, no exceptions π )
π Target Selection
when no target selection options are given, cargo check will check all binary and library targets of the selected packages. binaries get skipped if they have required-features that are missing. fair enough β¨
passing target selection flags will check only the specified targets.
heads up:--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. yes. again. it's a whole thing π
--libβ check the package's library.--bin*name*β¦ β check the specified binary. this flag may be specified multiple times and supports common Unix glob patterns.--binsβ check all binary targets.--example*name*β¦ β check the specified example. this flag may be specified multiple times and supports common Unix glob patterns.--examplesβ check all example targets.--test*name*β¦ β check the specified integration test. this flag may be specified multiple times and supports common Unix glob patterns.--testsβ check 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. yeah, twice. it's doing the most π--bench*name*β¦ β check the specified benchmark. this flag may be specified multiple times and supports common Unix glob patterns.--benchesβ check 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β check all targets. this is equivalent to specifying--lib --bins --tests --benches --examples. everything, everywhere, all at once π₯
π 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. cute, consistent, iconic β¨
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 up π§--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. minimalism era π
β‘ Compilation Options
--targettriple β check 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/guide/build-cache.html>documentation for more details. yourtarget/folder will not be where you expect it, bestie, and that's on purpose πΈ
-r,--releaseβ check optimized artifacts with thereleaseprofile. see also the--profileoption for choosing a specific profile by name. optimized era π--profilename β check with the given profile.
as a special case, specifying the test profile will also enable checking in test mode which will enable checking tests and enable the test cfg option. see rustc tests <https://doc.rust-lang.org/rustc/tests/index.html> for more detail.
see the reference <https://doc.rust-lang.org/cargo/reference/profiles.html> for more details on profiles.
--ignore-rust-versionβ check the target even if the selected Rust compiler is older than the required Rust version as configured in the project'srust-versionfield. living dangerously, I respect it π--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. three ways to say the same thing, pick your fighter π
π¦ 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 and give it to the next person π-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>. silence, but make it intentional π€«--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>. rainbow mode: enabled π
--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 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.
so many options and so many conflicts, it's giving "choose one and commit" energy π
πΈ Manifest Options
--manifest-pathpath β path to theCargo.tomlfile. by default, Cargo searches for theCargo.tomlfile in the current directory or any parent directory. it will find it. it always finds it πβ¨
okay bestie, that's a whole lot of options and we're not even done π
--frozen,--lockedβ bestie, either one of these is you being like "theCargo.lockfile BETTER be up-to-date or I'm leaving." If the lock file is missing, or it needs updating, Cargo exits with an error, no discussion. And--frozenis the extra-strict one: it ALSO stops Cargo from even touching the network to figure out if things are out-of-date. π
Use these when you wanna assert that Cargo.lock is up-to-date (like, say, in a CI build π) or when you just want zero network access. Periodt.
--offlineβ blocks Cargo from accessing the network for ANY reason whatsoever. Without this flag, Cargo just gives up with an error if it needs the network and the network isn't there. With it? Cargo will try to carry on without the network if it possibly can. π«Ά
Careful though β this can give you different dependency resolution than online mode. Cargo restricts itself to crates that are downloaded locally, even if the local copy of the index says a newer version exists. If you wanna download your deps before going offline, go see cargo-fetch(1).
May also be specified with the net.offline config value (https://doc.rust-lang.org/cargo/reference/config.html).
β¨ Common Options β¨
+toolchainβ if Cargo got installed with rustup, and the first argument tocargostarts with+, it gets interpreted as a rustup toolchain name (think+stableor+nightly). Wanna know how toolchain overrides actually work? The rustup documentation (https://rust-lang.github.io/rustup/overrides.html) has you covered. πΈ--config KEY=VALUEorPATHβ overrides a Cargo configuration value. The argument should be TOML syntax ofKEY=VALUE, or you can hand it a path to an extra configuration file. You can specify this flag as many times as you want, no cap. 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 executing any of the specified operations. This affects stuff like where cargo looks by default for the project manifest (Cargo.toml), plus the directories it searches for discovering.cargo/config.toml. π«
This option must appear before the command name, like so:
cargo -C path/to/my-project build
Heads up: this option is only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and it needs the -Z unstable-options flag to be enabled (see #10098 β https://github.com/rust-lang/cargo/issues/10098).
-h,--helpβ prints help information. iconic behaviour honestly.-Z flagβ unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor the details. π₯
π Miscellaneous Options π
-j N,--jobs Nβ number of parallel jobs to run. May also be specified 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 provided. If a stringdefaultis provided, it sets the value back to defaults. And it should not be0. π«--keep-goingβ builds as many crates in the dependency graph as possible instead of aborting the build the moment one fails.
Like, for example: if the current package depends on two dependencies that fail and work, and one of them fails to build, cargo check -j1 may or may not build the one that succeeds (depends on which of the two builds Cargo picked to run first π), whereas cargo check -j1 --keep-going would definitely run both builds, even if the one run first fails. THAT'S the difference bestie.
--future-incompat-reportβ displays a future-incompat report for any future-incompatible warnings produced during execution of this command.
See cargo-report(1).
π ENVIRONMENT π
See the reference (https://doc.rust-lang.org/cargo/reference/environment-variables.html) for details on environment variables that Cargo reads.
β EXIT STATUS β
0: Cargo succeeded. slay π101: Cargo failed to complete. π
π¦ EXAMPLES π¦
- Check the local package for errors:
cargo check
- Check all targets, including unit tests:
cargo check --all-targets --profile=test
π SEE ALSO π
and that's the whole page, bestie!! this one is from CARGO-CHECK(1), part of the Cargo source (that's where it lives), and it's dated in the page footer β go check the header for the exact version and date, iykyk π β¨
π¦ where this page comes from
- ubuntu jammy: cargo-1.77 1.77.2+dfsg1ubuntu1~bpo0-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.77 1.77.2+dfsg1ubuntu1-0ubuntu0.24.04.1 Β· 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