1CARGO-CHECK(1) General Commands Manual CARGO-CHECK(1)
2
3
4
6 cargo-check - Check the current package
7
9 cargo check [options]
10
12 Check a local package and all of its dependencies for errors. This will
13 essentially compile the packages without performing the final step of
14 code generation, which is faster than running cargo build. The compiler
15 will save metadata files to disk so that future runs will reuse them if
16 the source has not been modified. Some diagnostics and errors are only
17 emitted during code generation, so they inherently won't be reported
18 with cargo check.
19
21 Package Selection
22 By default, when no package selection options are given, the packages
23 selected depend on the selected manifest file (based on the current
24 working directory if --manifest-path is not given). If the manifest is
25 the root of a workspace then the workspaces default members are
26 selected, otherwise only the package defined by the manifest will be
27 selected.
28
29 The default members of a workspace can be set explicitly with the
30 workspace.default-members key in the root manifest. If this is not set,
31 a virtual workspace will include all workspace members (equivalent to
32 passing --workspace), and a non-virtual workspace will include only the
33 root crate itself.
34
35 -p spec..., --package spec...
36 Check only the specified packages. See cargo-pkgid(1) for the SPEC
37 format. This flag may be specified multiple times and supports
38 common Unix glob patterns like *, ? and []. However, to avoid your
39 shell accidentally expanding glob patterns before Cargo handles
40 them, you must use single quotes or double quotes around each
41 pattern.
42
43 --workspace
44 Check all members in the workspace.
45
46 --all
47 Deprecated alias for --workspace.
48
49 --exclude SPEC...
50 Exclude the specified packages. Must be used in conjunction with
51 the --workspace flag. This flag may be specified multiple times and
52 supports common Unix glob patterns like *, ? and []. However, to
53 avoid your shell accidentally expanding glob patterns before Cargo
54 handles them, you must use single quotes or double quotes around
55 each pattern.
56
57 Target Selection
58 When no target selection options are given, cargo check will check all
59 binary and library targets of the selected packages. Binaries are
60 skipped if they have required-features that are missing.
61
62 Passing target selection flags will check only the specified targets.
63
64 Note that --bin, --example, --test and --bench flags also support
65 common Unix glob patterns like *, ? and []. However, to avoid your
66 shell accidentally expanding glob patterns before Cargo handles them,
67 you must use single quotes or double quotes around each glob pattern.
68
69 --lib
70 Check the package's library.
71
72 --bin name...
73 Check the specified binary. This flag may be specified multiple
74 times and supports common Unix glob patterns.
75
76 --bins
77 Check all binary targets.
78
79 --example name...
80 Check the specified example. This flag may be specified multiple
81 times and supports common Unix glob patterns.
82
83 --examples
84 Check all example targets.
85
86 --test name...
87 Check the specified integration test. This flag may be specified
88 multiple times and supports common Unix glob patterns.
89
90 --tests
91 Check all targets in test mode that have the test = true manifest
92 flag set. By default this includes the library and binaries built
93 as unittests, and integration tests. Be aware that this will also
94 build any required dependencies, so the lib target may be built
95 twice (once as a unittest, and once as a dependency for binaries,
96 integration tests, etc.). Targets may be enabled or disabled by
97 setting the test flag in the manifest settings for the target.
98
99 --bench name...
100 Check the specified benchmark. This flag may be specified multiple
101 times and supports common Unix glob patterns.
102
103 --benches
104 Check all targets in benchmark mode that have the bench = true
105 manifest flag set. By default this includes the library and
106 binaries built as benchmarks, and bench targets. Be aware that this
107 will also build any required dependencies, so the lib target may be
108 built twice (once as a benchmark, and once as a dependency for
109 binaries, benchmarks, etc.). Targets may be enabled or disabled by
110 setting the bench flag in the manifest settings for the target.
111
112 --all-targets
113 Check all targets. This is equivalent to specifying --lib --bins
114 --tests --benches --examples.
115
116 Feature Selection
117 The feature flags allow you to control which features are enabled. When
118 no feature options are given, the default feature is activated for
119 every selected package.
120
121 See the features documentation
122 <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>
123 for more details.
124
125 --features features
126 Space or comma separated list of features to activate. Features of
127 workspace members may be enabled with package-name/feature-name
128 syntax. This flag may be specified multiple times, which enables
129 all specified features.
130
131 --all-features
132 Activate all available features of all selected packages.
133
134 --no-default-features
135 Do not activate the default feature of the selected packages.
136
137 Compilation Options
138 --target triple
139 Check for the given architecture. The default is the host
140 architecture. The general format of the triple is
141 <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
142 a list of supported targets.
143
144 This may also be specified with the build.target config value
145 <https://doc.rust-lang.org/cargo/reference/config.html>.
146
147 Note that specifying this flag makes Cargo run in a different mode
148 where the target artifacts are placed in a separate directory. See
149 the build cache
150 <https://doc.rust-lang.org/cargo/guide/build-cache.html>
151 documentation for more details.
152
153 --release
154 Check optimized artifacts with the release profile. See the
155 PROFILES section for details on how this affects profile selection.
156
157 --profile name
158 Changes check behavior. Currently only test is supported, which
159 will check with the #[cfg(test)] attribute enabled. This is useful
160 to have it check unit tests which are usually excluded via the cfg
161 attribute. This does not change the actual profile used.
162
163 Output Options
164 --target-dir directory
165 Directory for all generated artifacts and intermediate files. May
166 also be specified with the CARGO_TARGET_DIR environment variable,
167 or the build.target-dir config value
168 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
169 to target in the root of the workspace.
170
171 Display Options
172 -v, --verbose
173 Use verbose output. May be specified twice for "very verbose"
174 output which includes extra output such as dependency warnings and
175 build script output. May also be specified with the term.verbose
176 config value
177 <https://doc.rust-lang.org/cargo/reference/config.html>.
178
179 -q, --quiet
180 No output printed to stdout.
181
182 --color when
183 Control when colored output is used. Valid values:
184
185 · auto (default): Automatically detect if color support is
186 available on the terminal.
187
188 · always: Always display colors.
189
190 · never: Never display colors.
191
192 May also be specified with the term.color config value
193 <https://doc.rust-lang.org/cargo/reference/config.html>.
194
195 --message-format fmt
196 The output format for diagnostic messages. Can be specified
197 multiple times and consists of comma-separated values. Valid
198 values:
199
200 · human (default): Display in a human-readable text format.
201
202 · short: Emit shorter, human-readable text messages.
203
204 · json: Emit JSON messages to stdout. See the reference
205 <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
206 for more details.
207
208 · json-diagnostic-short: Ensure the rendered field of JSON
209 messages contains the "short" rendering from rustc.
210
211 · json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
212 messages contains embedded ANSI color codes for respecting
213 rustc's default color scheme.
214
215 · json-render-diagnostics: Instruct Cargo to not include rustc
216 diagnostics in in JSON messages printed, but instead Cargo
217 itself should render the JSON diagnostics coming from rustc.
218 Cargo's own JSON diagnostics and others coming from rustc are
219 still emitted.
220
221 Manifest Options
222 --manifest-path path
223 Path to the Cargo.toml file. By default, Cargo searches for the
224 Cargo.toml file in the current directory or any parent directory.
225
226 --frozen, --locked
227 Either of these flags requires that the Cargo.lock file is
228 up-to-date. If the lock file is missing, or it needs to be updated,
229 Cargo will exit with an error. The --frozen flag also prevents
230 Cargo from attempting to access the network to determine if it is
231 out-of-date.
232
233 These may be used in environments where you want to assert that the
234 Cargo.lock file is up-to-date (such as a CI build) or want to avoid
235 network access.
236
237 --offline
238 Prevents Cargo from accessing the network for any reason. Without
239 this flag, Cargo will stop with an error if it needs to access the
240 network and the network is not available. With this flag, Cargo
241 will attempt to proceed without the network if possible.
242
243 Beware that this may result in different dependency resolution than
244 online mode. Cargo will restrict itself to crates that are
245 downloaded locally, even if there might be a newer version as
246 indicated in the local copy of the index. See the cargo-fetch(1)
247 command to download dependencies before going offline.
248
249 May also be specified with the net.offline config value
250 <https://doc.rust-lang.org/cargo/reference/config.html>.
251
252 Common Options
253 +toolchain
254 If Cargo has been installed with rustup, and the first argument to
255 cargo begins with +, it will be interpreted as a rustup toolchain
256 name (such as +stable or +nightly). See the rustup documentation
257 <https://rust-lang.github.io/rustup/overrides.html> for more
258 information about how toolchain overrides work.
259
260 -h, --help
261 Prints help information.
262
263 -Z flag
264 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
265 details.
266
267 Miscellaneous Options
268 -j N, --jobs N
269 Number of parallel jobs to run. May also be specified with the
270 build.jobs config value
271 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
272 to the number of CPUs.
273
275 Profiles may be used to configure compiler options such as optimization
276 levels and debug settings. See the reference
277 <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
278 details.
279
280 Profile selection depends on the target and crate being built. By
281 default the dev or test profiles are used. If the --release flag is
282 given, then the release or bench profiles are used.
283
284
285 ┌────────────────────┬─────────────────┬───────────────────┐
286 │Target │ Default Profile │ --release Profile │
287 ├────────────────────┼─────────────────┼───────────────────┤
288 │lib, bin, example │ dev │ release │
289 ├────────────────────┼─────────────────┼───────────────────┤
290 │test, bench, or any │ test │ bench │
291 │target in "test" or │ │ │
292 │"bench" mode │ │ │
293 └────────────────────┴─────────────────┴───────────────────┘
294
295 Dependencies use the dev/release profiles.
296
298 See the reference
299 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
300 for details on environment variables that Cargo reads.
301
303 · 0: Cargo succeeded.
304
305 · 101: Cargo failed to complete.
306
308 1. Check the local package for errors:
309
310 cargo check
311
312 2. Check all targets, including unit tests:
313
314 cargo check --all-targets --profile=test
315
317 cargo(1), cargo-build(1)
318
319
320
321 CARGO-CHECK(1)