CARGO-CHECK(1)

πŸ“¦ version 1.77.2, in ubuntu jammy, ubuntu noble

🌸 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. see cargo-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 --workspace flag. 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, --test and --bench flags 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 the test = true manifest 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 the test flag 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 the bench = true manifest 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 the bench flag 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.

  • -F features, --features features β€” space or comma separated list of features to activate. features of workspace members may be enabled with package-name/feature-name syntax. 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

  • --target triple β€” check for the given architecture. the default is the host architecture. the general format of the triple is <arch><sub>-<vendor>-<sys>-<abi>. run rustc --print target-list for 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. your target/ folder will not be where you expect it, bestie, and that's on purpose 🌸
  • -r, --release β€” check optimized artifacts with the release profile. see also the --profile option for choosing a specific profile by name. optimized era 😌
  • --profile name β€” 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's rust-version field. 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; --timings without 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 file cargo-timing.html to the target/cargo-timings directory 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-dir directory β€” directory for all generated artifacts and intermediate files. may also be specified with the CARGO_TARGET_DIR environment variable, or the build.target-dir config value <https://doc.rust-lang.org/cargo/reference/config.html>. defaults to target in 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 the term.verbose config 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 the term.quiet config value <https://doc.rust-lang.org/cargo/reference/config.html>. silence, but make it intentional 🀫
  • --color when β€” 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-format fmt β€” 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 with short and json.
    • short: emit shorter, human-readable text messages. conflicts with human and json.
    • 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 with human and short.
    • json-diagnostic-short: ensure the rendered field of JSON messages contains the "short" rendering from rustc. cannot be used with human or short.
    • json-diagnostic-rendered-ansi: ensure the rendered field of JSON messages contains embedded ANSI color codes for respecting rustc's default color scheme. cannot be used with human or short.
    • 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 with human or short.
so many options and so many conflicts, it's giving "choose one and commit" energy πŸ’€

🌸 Manifest Options

  • --manifest-path path β€” path to the Cargo.toml file. by default, Cargo searches for the Cargo.toml file 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 "the Cargo.lock file 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 --frozen is 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 to cargo starts with +, it gets interpreted as a rustup toolchain name (think +stable or +nightly). Wanna know how toolchain overrides actually work? The rustup documentation (https://rust-lang.github.io/rustup/overrides.html) has you covered. 🌸
  • --config KEY=VALUE or PATH β€” overrides a Cargo configuration value. The argument should be TOML syntax of KEY=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. Run cargo -Z help for the details. πŸ”₯

🌈 Miscellaneous Options 🌈

  • -j N, --jobs N β€” number of parallel jobs to run. May also be specified with the build.jobs config 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 string default is provided, it sets the value back to defaults. And it should not be 0. 🚫
  • --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 πŸ¦‹

  1. Check the local package for errors:
cargo check
  1. Check all targets, including unit tests:
cargo check --all-targets --profile=test

πŸ‘‘ SEE ALSO πŸ‘‘

cargo(1), cargo-build(1)


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