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 Conflicts with short and json.
202
203 • short: Emit shorter, human-readable text messages. Conflicts
204 with human and json.
205
206 • json: Emit JSON messages to stdout. See the reference
207 <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
208 for more details. Conflicts with human and short.
209
210 • json-diagnostic-short: Ensure the rendered field of JSON
211 messages contains the "short" rendering from rustc. Cannot be
212 used with human or short.
213
214 • json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
215 messages contains embedded ANSI color codes for respecting
216 rustc's default color scheme. Cannot be used with human or
217 short.
218
219 • json-render-diagnostics: Instruct Cargo to not include rustc
220 diagnostics in in JSON messages printed, but instead Cargo
221 itself should render the JSON diagnostics coming from rustc.
222 Cargo's own JSON diagnostics and others coming from rustc are
223 still emitted. Cannot be used with human or short.
224
225 Manifest Options
226 --manifest-path path
227 Path to the Cargo.toml file. By default, Cargo searches for the
228 Cargo.toml file in the current directory or any parent directory.
229
230 --frozen, --locked
231 Either of these flags requires that the Cargo.lock file is
232 up-to-date. If the lock file is missing, or it needs to be updated,
233 Cargo will exit with an error. The --frozen flag also prevents
234 Cargo from attempting to access the network to determine if it is
235 out-of-date.
236
237 These may be used in environments where you want to assert that the
238 Cargo.lock file is up-to-date (such as a CI build) or want to avoid
239 network access.
240
241 --offline
242 Prevents Cargo from accessing the network for any reason. Without
243 this flag, Cargo will stop with an error if it needs to access the
244 network and the network is not available. With this flag, Cargo
245 will attempt to proceed without the network if possible.
246
247 Beware that this may result in different dependency resolution than
248 online mode. Cargo will restrict itself to crates that are
249 downloaded locally, even if there might be a newer version as
250 indicated in the local copy of the index. See the cargo-fetch(1)
251 command to download dependencies before going offline.
252
253 May also be specified with the net.offline config value
254 <https://doc.rust-lang.org/cargo/reference/config.html>.
255
256 Common Options
257 +toolchain
258 If Cargo has been installed with rustup, and the first argument to
259 cargo begins with +, it will be interpreted as a rustup toolchain
260 name (such as +stable or +nightly). See the rustup documentation
261 <https://rust-lang.github.io/rustup/overrides.html> for more
262 information about how toolchain overrides work.
263
264 -h, --help
265 Prints help information.
266
267 -Z flag
268 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
269 details.
270
271 Miscellaneous Options
272 -j N, --jobs N
273 Number of parallel jobs to run. May also be specified with the
274 build.jobs config value
275 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
276 to the number of CPUs.
277
279 Profiles may be used to configure compiler options such as optimization
280 levels and debug settings. See the reference
281 <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
282 details.
283
284 Profile selection depends on the target and crate being built. By
285 default the dev or test profiles are used. If the --release flag is
286 given, then the release or bench profiles are used.
287
288
289 ┌────────────────────┬─────────────────┬───────────────────┐
290 │Target │ Default Profile │ --release Profile │
291 ├────────────────────┼─────────────────┼───────────────────┤
292 │lib, bin, example │ dev │ release │
293 ├────────────────────┼─────────────────┼───────────────────┤
294 │test, bench, or any │ test │ bench │
295 │target in "test" or │ │ │
296 │"bench" mode │ │ │
297 └────────────────────┴─────────────────┴───────────────────┘
298
299 Dependencies use the dev/release profiles.
300
302 See the reference
303 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
304 for details on environment variables that Cargo reads.
305
307 • 0: Cargo succeeded.
308
309 • 101: Cargo failed to complete.
310
312 1. Check the local package for errors:
313
314 cargo check
315
316 2. Check all targets, including unit tests:
317
318 cargo check --all-targets --profile=test
319
321 cargo(1), cargo-build(1)
322
323
324
325 CARGO-CHECK(1)