CARGO-CHECK(1)

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

✨ CARGO-CHECK(1) ✨

okay bestie, welcome to cargo-check β€” it's a whole manual page and it's lowkey iconic πŸ’…


🌸 NAME 🌸

cargo-check β€” check the current package. that's it. that's the whole vibe. 🫢


πŸŽ€ SYNOPSIS πŸŽ€

cargo check [options]

πŸ’– DESCRIPTION πŸ’–

so what it does: it checks a local package and all of its dependencies for errors. no cap. it's basically compiling the packages without doing the final step of code generation, which makes it faster than running cargo build. slay. πŸ”₯

the compiler will save metadata files to disk, so future runs reuse them if the source hasn't been modified. bestie it's literally remembering things for you, main character energy.

⚠️ important caveat alert ⚠️ some diagnostics and errors are only emitted during code generation, so they inherently won't be reported with cargo check. it's giving "not a full build" and you gotta respect that. 😭

πŸ‘‘ OPTIONS πŸ‘‘

🧺 Package Selection

by default, when you don't give any package selection options, the packages that get selected depend on the selected manifest file (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 are selected, otherwise only the package defined by the manifest will be selected.

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, then a virtual workspace will include all workspace members (equivalent to passing --workspace), and a non-virtual workspace will include only the root crate itself. iykyk.

  • -p *spec*…, --package *spec*… β€” check only the specified packages. peep cargo-pkgid(1) for the SPEC format. this flag may be specified multiple times and supports common Unix glob patterns like *, ? and []. BUT β€” and this is the part everyone messes up β€” to avoid your shell accidentally expanding glob patterns before Cargo handles them, you must use single quotes or double quotes around each pattern. periodt. πŸ™ˆ
  • --workspace β€” check all members in the workspace. the whole squad. πŸ’œ
  • --all β€” deprecated alias for --workspace. it's giving legacy, ngl.
  • --exclude *SPEC*… β€” exclude the specified packages. must be used in conjunction with the --workspace flag (they're a package deal, fr fr). 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.

🎯 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. bye felicia. πŸ‘‹

passing target selection flags will check only the specified targets.

πŸ“Œ note: --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. protect your globs bestie 🫢
  • --lib β€” check the package's library. πŸ“š
  • --bin *name*… β€” check the specified binary. may be specified multiple times and supports common Unix glob patterns.
  • --bins β€” check all binary targets. all of them. every single one. πŸ’…
  • --example *name*… β€” check the specified example. may be specified multiple times and supports common Unix glob patterns.
  • --examples β€” check all example targets. ✨
  • --test *name*… β€” check the specified integration test. 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. heads up tho: 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.
  • --bench *name*… β€” check the specified benchmark. 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. again, warning: 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. the full combo meal πŸ“

🌈 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. πŸ“–

  • -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. literally everything, no holding back. πŸ”₯
  • --no-default-features β€” do not activate the default feature of the selected packages. sometimes you gotta say no πŸ’…

πŸ› οΈ 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 at https://doc.rust-lang.org/cargo/reference/config.html.

note: 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 at https://doc.rust-lang.org/cargo/reference/build-cache.html for more details. different mode, different directory, different energy ✨
  • -r, --release β€” check optimized artifacts with the release profile. see also the --profile option for choosing a specific profile by name. πŸš€
  • --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 at https://doc.rust-lang.org/rustc/tests/index.html for more detail.

see the reference at https://doc.rust-lang.org/cargo/reference/profiles.html for more details on profiles.

  • --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; --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. it's giving "for the girlies, not the robots" πŸ’…
    • json (unstable, requires -Zunstable-options): emit machine-readable JSON information about timing information. for the robots. πŸ€–

πŸ“¦ 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 at https://doc.rust-lang.org/cargo/reference/config.html. defaults to target in 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 the term.verbose config value at https://doc.rust-lang.org/cargo/reference/config.html. two -vs is giving detective mode πŸ”
  • -q, --quiet β€” do not print cargo log messages. may also be specified with the term.quiet config value at https://doc.rust-lang.org/cargo/reference/config.html. shhh 🀫
  • --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 at https://doc.rust-lang.org/cargo/reference/config.html.

  • --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 at 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.

πŸ“œ 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'll find it, bestie, it always does πŸ¦‹
  • --ignore-rust-version β€” ignore rust-version specification in packages. living dangerously, we love that for you πŸ™ˆ
  • --locked β€” asserts that the exact same dependencies and versions are used as when the existing Cargo.lock file 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. πŸ’€

That bit about deterministic builds? It's lowkey the whole point of that flag in some setups β€” CI pipelines love it, because a build that does the same thing every single time is a build you can trust. ✨


  • --offline β€” bestie, this one puts Cargo on airplane mode. ✈️ It stops Cargo from touching the network for any reason, periodt. Without it, if Cargo needs the network and there isn't one, it just gives up with an error. With it, Cargo will try to keep going without the network if it possibly can.
Heads up though: this can genuinely change how your dependencies resolve compared to online mode. Cargo will only use crates that are already downloaded locally, even if the local copy of the index says a newer version exists. So if you're planning to go offline, run cargo-fetch(1) first to grab your dependencies. 🫢

You can also set this with the net.offline config value: https://doc.rust-lang.org/cargo/reference/config.html

  • --frozen β€” the combo meal: it's exactly the same as passing both --locked and --offline together. πŸ“
  • --lockfile-path PATH β€” moves the lockfile from its default spot (<workspace_root>/Cargo.lock) to PATH. And yes, PATH must end with Cargo.lock (like --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Important detail: if you pass --lockfile-path, Cargo ignores any existing lockfile at the default path and instead either uses the lockfile at PATH or writes a brand new one there if it doesn't exist. The whole reason this exists? So you can run most commands in read-only directories while Cargo writes the lockfile off into PATH. πŸ’…
This one is nightly only and needs the -Z unstable-options flag to turn on. It's tracked in issue #14421: https://github.com/rust-lang/cargo/issues/14421 Nightly channel info: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html

✨ Common Options ✨

  • +toolchain β€” if you installed Cargo through rustup and the very first argument to cargo starts with +, Cargo reads it as a rustup toolchain name (think +stable or +nightly). The rustup docs explain how toolchain overrides work: https://rust-lang.github.io/rustup/overrides.html
  • --config KEY=VALUE or PATH β€” overrides a Cargo configuration value. You can hand it TOML in KEY=VALUE form, or give it a path to an extra config file instead. You can pass this flag as many times as you want. More deets in the command-line overrides section: https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides
  • -C PATH β€” switches the current working directory before doing anything else. This changes stuff like where Cargo looks for your project manifest (Cargo.toml) by default, and which directories it searches when hunting for .cargo/config.toml. ⚠️ It has to come before the command name, like cargo -C path/to/my-project build.
Nightly-only again, and it needs -Z unstable-options to enable. Tracked in #10098: https://github.com/rust-lang/cargo/issues/10098 Nightly channel info: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
  • -h, --help β€” prints the help information. The classic. πŸ™ˆ
  • -Z flag β€” unstable, nightly-only flags for Cargo. Run cargo -Z help to see what's on the menu.

🌈 Miscellaneous Options 🌈

  • -j N, --jobs N β€” how many parallel jobs to run. You can also set this 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 max number of parallel jobs to the number of logical CPUs plus the value you gave. If you pass the string default, it resets back to the defaults. And fr fr, it should not be 0. πŸ’€
  • --keep-going β€” builds as many crates in the dependency graph as it possibly can, instead of bailing the moment one of them fails. πŸ”₯

Say your current package depends on two deps, one broken and one fine. cargo check -j1 may or may not build the one that works β€” it all depends on which of the two builds Cargo happened to pick first. But cargo check -j1 --keep-going would definitely run both builds, even if the first one it ran fails.

  • --future-incompat-report β€” shows you a future-incompat report for any future-incompatible warnings that popped up while this command ran. πŸ‘‘

See cargo-report(1).


🌸 ENVIRONMENT 🌸

Cargo reads environment variables, and the full list lives in the reference: https://doc.rust-lang.org/cargo/reference/environment-variables.html


⭐ EXIT STATUS ⭐

  • 0: Cargo succeeded. πŸŽ‰
  • 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)


That's the whole page, bestie β€” CARGO-CHECK(1), you ate and left no crumbs. πŸ’…βœ¨ Go forth and check those crates. πŸ¦‹

πŸ“¦ where this page comes from