CARGO-CHECK(1)

๐Ÿ“ฆ version 1.92.0, in ubuntu resolute

CARGO-CHECK(1) ๐Ÿ’…

okay so bestie, welcome to the cargo-check manual page โ€” General Commands Manual energy, but make it cute. let's get into it ๐Ÿซถ


โœจ 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. The way it works is it basically compiles the packages but โœ‹ stops right before the final step of code generation, which is why it's faster than running cargo build. Lowkey iconic for when you just want to know if things are broken without the full build vibe.

The compiler will save metadata files to disk so that future runs can reuse them if the source hasn't been modified. Reuse queen ๐Ÿ‘‘

โš ๏ธ but heads up bestie: some diagnostics and errors are only emitted during code generation, so they inherently won't be reported with cargo check. Not everything shows up here, no cap. ๐Ÿ’€

โœจ OPTIONS โœจ

๐ŸŒธ Package Selection ๐ŸŒธ

By default, when no package selection options are given, the packages selected depend on the selected manifest file (based on the current working directory if --manifest-path is not 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 this is not set, a virtual workspace will include all workspace members (equivalent to passing --workspace), and a non-virtual workspace will include only the root crate itself. the way it just decides for you... main character energy fr โœจ

  • -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. protect the globs, bestie ๐Ÿฅบ
  • --workspace โ€” Check all members in the workspace. the whole squad ๐Ÿซถ
  • --all โ€” Deprecated alias for --workspace. it's giving legacy, we don't really use it anymore ๐Ÿ’€
  • --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. not like other girls (packages) ๐Ÿ™ˆ

๐ŸŽฏ Target Selection ๐ŸŽฏ

When no target selection options are given, cargo check will check all binary and library targets of the selected packages. Binaries are skipped if they have required-features that are missing. bye to the ones that don't qualify โœŒ๏ธ

Passing target selection flags will check only the specified targets.

๐Ÿ“Œ Note that --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. quote ur globs or the shell will do crimes ๐Ÿ˜ญ
  • --lib โ€” Check the package's library. the library, the moment, the icon ๐ŸŽ€
  • --bin nameโ€ฆ โ€” Check the specified binary. This flag may be specified multiple times and supports common Unix glob patterns.
  • --bins โ€” Check all binary targets. all of them, no crumbs ๐Ÿ“
  • --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 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. double-building the lib? it's doing the most, but respectfully ๐Ÿ’…
  • --bench nameโ€ฆ โ€” Check the specified benchmark. This flag may be specified multiple times and supports common Unix glob patterns.
  • --benches โ€” Check all targets 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. same double-build situation, she's committed ๐Ÿ”ฅ
  • --all-targets โ€” Check all targets. This is equivalent to specifying --lib --bins --tests --benches --examples. literally everything, all at once, obsessed ๐ŸŒˆ

๐ŸŒท Feature Selection ๐ŸŒท

The feature flags allow you to control which features are enabled. When no feature options are given, the default feature is activated for every selected package. defaults stay winning, periodt ๐Ÿ‘‘

See the features documentation for more details: https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options

  • -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 them like bracelets โœจ
  • --all-features โ€” Activate all available features of all selected packages. full send ๐Ÿ”ฅ
  • --no-default-features โ€” Do not activate the default feature of the selected packages. we're going off-script ๐Ÿ’€

๐Ÿ› ๏ธ Compilation Options ๐Ÿ› ๏ธ

  • --target triple โ€” Check for the specified target architecture. 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, an xtask in a shared project that may be worked on by many hosts). very "i contain multitudes" of it ๐Ÿฆ‹
  • A path to a custom target specification. See Custom Target Lookup Path for more information: https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-path

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 for more details: https://doc.rust-lang.org/cargo/reference/build-cache.html

  • -r, --release โ€” Check optimized artifacts with the release profile. See also the --profile option for choosing a specific profile by name. optimized and unbothered ๐Ÿ’…
  • --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 for more detail: https://doc.rust-lang.org/rustc/tests/index.html

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

  • --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. cute to look at, not for 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: https://doc.rust-lang.org/cargo/reference/config.html. Defaults to target in the root of the workspace. home sweet target ๐Ÿ 

๐Ÿ’ฌ 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. twice?? very verbose, very demure ๐ŸŽ€
  • -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. 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: 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 for more details: https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages. 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.

part 1 done bestie, there's more coming so don't go anywhere ๐Ÿ’œ

Manifest Options ๐Ÿ“œโœจ

  • --manifest-path path โ€” tells Cargo exactly where your Cargo.toml lives. No flag? Then Cargo goes hunting for the Cargo.toml file in the current directory, or literally any parent directory above it. ๐Ÿ•ต๏ธโ€โ™€๏ธ
  • --ignore-rust-version โ€” pretends the rust-version spec in your packages simply does not exist. It's giving "I don't see it so it can't hurt me" ๐Ÿ’€
  • --locked โ€” pinky-promises that the exact same dependencies and versions get used as when the existing Cargo.lock file was originally generated. Cargo will bail with an error when either of these happens:
    • The lock file is missing.
    • Cargo tried to change the lock file because dependency resolution came out different.

Perfect for environments that want deterministic builds, like CI pipelines. Queen of consistency ๐Ÿ‘‘

  • --offline โ€” Cargo is not allowed to touch the network for any reason. Without this flag, if Cargo needs the network and there's no network, it just stops with an error. With this flag, it'll try to keep going without the network if it possibly can. โœˆ๏ธ
Beware bestie: this can give you different dependency resolution than online mode. Cargo limits itself to crates already downloaded locally, even if a newer version exists according to the local copy of the index. And if you wanna go offline properly, hit up cargo-fetch(1) to download your dependencies first. ๐Ÿ’…

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

  • --frozen โ€” the two-for-one special: exactly the same as passing both --locked and --offline. ๐ŸงŠ
  • --lockfile-path PATH โ€” moves the lockfile from its default spot (<workspace_root>/Cargo.lock) over to PATH. And PATH must end with Cargo.lock (like --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Heads up: giving --lockfile-path makes Cargo ignore any existing lockfile at the default path, and instead it'll either use the lockfile at PATH, or write a brand new lockfile into the PATH you provided if nothing's there. This flag is the moment for running most commands inside read-only directories, writing the lockfile into the PATH you gave. ๐Ÿ”
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 turned on to enable it (see #14421 <https://github.com/rust-lang/cargo/issues/14421>).

Common Options ๐Ÿซถ

  • +toolchain โ€” if Cargo got installed with rustup, and the very first argument to cargo starts with +, it gets read as a rustup toolchain name (think +stable or +nightly). Peep the rustup docs <https://rust-lang.github.io/rustup/overrides.html> for the whole tea on how toolchain overrides work. โ˜•
  • --config KEY=VALUE or PATH โ€” overrides a Cargo configuration value. The argument is either TOML syntax in KEY=VALUE form, or a path to an extra config file. You can stack this flag as many times as you want. See the command-line overrides section <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides> for more. ๐ŸŽ€
  • -C PATH โ€” changes the current working directory before running any of the operations you asked for. This affects stuff like where cargo looks by default for the project manifest (Cargo.toml), and which directories get searched when discovering .cargo/config.toml, for example. This option must come before the command name, like cargo -C path/to/my-project build. ๐Ÿ“
Also nightly-only <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html>, and it needs -Z unstable-options enabled (see #10098 <https://github.com/rust-lang/cargo/issues/10098>).
  • -h, --help โ€” prints help information. Classic, beloved, never misses. ๐Ÿ’–
  • -Z flag โ€” the unstable (nightly-only) flags for Cargo. Run cargo -Z help for the details. ๐Ÿงช

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 maximum number of parallel jobs to the number of logical CPUs plus the value you gave. 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 it possibly can, instead of aborting the whole build the second one of them fails. ๐Ÿ’ช

For example, if the current package depends on dependencies that fail and work, one of which 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 that ran first fails.

  • --future-incompat-report โ€” displays a future-incompat report for any future-incompatible warnings that got produced while this command was executing. ๐Ÿ”ฎ

See cargo-report(1).


๐ŸŒ ENVIRONMENT ๐ŸŒ

See the reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for the deets 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, no cap โ€” this was the CARGO-CHECK(1) manual page from the Cargo docs (that's the source and version line doing its little footer moment at the bottom of the original ๐ŸŽ€), dated with its own little timestamp, and you read every single word of it. Obsessed with you fr fr ๐Ÿ’…๐Ÿฆ‹๐Ÿ’–

๐Ÿ“ฆ where this page comes from