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 -F features, --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. This flag may be specified multiple
143 times.
144
145 This may also be specified with the build.target config value
146 <https://doc.rust-lang.org/cargo/reference/config.html>.
147
148 Note that specifying this flag makes Cargo run in a different mode
149 where the target artifacts are placed in a separate directory. See
150 the build cache
151 <https://doc.rust-lang.org/cargo/guide/build-cache.html>
152 documentation for more details.
153
154 -r, --release
155 Check optimized artifacts with the release profile. See also the
156 --profile option for choosing a specific profile by name.
157
158 --profile name
159 Check with the given profile.
160
161 As a special case, specifying the test profile will also enable
162 checking in test mode which will enable checking tests and enable
163 the test cfg option. See rustc tests
164 <https://doc.rust-lang.org/rustc/tests/index.html> for more detail.
165
166 See the the reference
167 <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
168 details on profiles.
169
170 --ignore-rust-version
171 Check the target even if the selected Rust compiler is older than
172 the required Rust version as configured in the project's
173 rust-version field.
174
175 --timings=fmts
176 Output information how long each compilation takes, and track
177 concurrency information over time. Accepts an optional
178 comma-separated list of output formats; --timings without an
179 argument will default to --timings=html. Specifying an output
180 format (rather than the default) is unstable and requires
181 -Zunstable-options. Valid output formats:
182
183 • html (unstable, requires -Zunstable-options): Write a
184 human-readable file cargo-timing.html to the
185 target/cargo-timings directory with a report of the
186 compilation. Also write a report to the same directory with a
187 timestamp in the filename if you want to look at older runs.
188 HTML output is suitable for human consumption only, and does
189 not provide machine-readable timing data.
190
191 • json (unstable, requires -Zunstable-options): Emit
192 machine-readable JSON information about timing information.
193
194 Output Options
195 --target-dir directory
196 Directory for all generated artifacts and intermediate files. May
197 also be specified with the CARGO_TARGET_DIR environment variable,
198 or the build.target-dir config value
199 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
200 to target in the root of the workspace.
201
202 Display Options
203 -v, --verbose
204 Use verbose output. May be specified twice for "very verbose"
205 output which includes extra output such as dependency warnings and
206 build script output. May also be specified with the term.verbose
207 config value
208 <https://doc.rust-lang.org/cargo/reference/config.html>.
209
210 -q, --quiet
211 Do not print cargo log messages. May also be specified with the
212 term.quiet config value
213 <https://doc.rust-lang.org/cargo/reference/config.html>.
214
215 --color when
216 Control when colored output is used. Valid values:
217
218 • auto (default): Automatically detect if color support is
219 available on the terminal.
220
221 • always: Always display colors.
222
223 • never: Never display colors.
224
225 May also be specified with the term.color config value
226 <https://doc.rust-lang.org/cargo/reference/config.html>.
227
228 --message-format fmt
229 The output format for diagnostic messages. Can be specified
230 multiple times and consists of comma-separated values. Valid
231 values:
232
233 • human (default): Display in a human-readable text format.
234 Conflicts with short and json.
235
236 • short: Emit shorter, human-readable text messages. Conflicts
237 with human and json.
238
239 • json: Emit JSON messages to stdout. See the reference
240 <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
241 for more details. Conflicts with human and short.
242
243 • json-diagnostic-short: Ensure the rendered field of JSON
244 messages contains the "short" rendering from rustc. Cannot be
245 used with human or short.
246
247 • json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
248 messages contains embedded ANSI color codes for respecting
249 rustc's default color scheme. Cannot be used with human or
250 short.
251
252 • json-render-diagnostics: Instruct Cargo to not include rustc
253 diagnostics in JSON messages printed, but instead Cargo itself
254 should render the JSON diagnostics coming from rustc. Cargo's
255 own JSON diagnostics and others coming from rustc are still
256 emitted. Cannot be used with human or short.
257
258 Manifest Options
259 --manifest-path path
260 Path to the Cargo.toml file. By default, Cargo searches for the
261 Cargo.toml file in the current directory or any parent directory.
262
263 --frozen, --locked
264 Either of these flags requires that the Cargo.lock file is
265 up-to-date. If the lock file is missing, or it needs to be updated,
266 Cargo will exit with an error. The --frozen flag also prevents
267 Cargo from attempting to access the network to determine if it is
268 out-of-date.
269
270 These may be used in environments where you want to assert that the
271 Cargo.lock file is up-to-date (such as a CI build) or want to avoid
272 network access.
273
274 --offline
275 Prevents Cargo from accessing the network for any reason. Without
276 this flag, Cargo will stop with an error if it needs to access the
277 network and the network is not available. With this flag, Cargo
278 will attempt to proceed without the network if possible.
279
280 Beware that this may result in different dependency resolution than
281 online mode. Cargo will restrict itself to crates that are
282 downloaded locally, even if there might be a newer version as
283 indicated in the local copy of the index. See the cargo-fetch(1)
284 command to download dependencies before going offline.
285
286 May also be specified with the net.offline config value
287 <https://doc.rust-lang.org/cargo/reference/config.html>.
288
289 Common Options
290 +toolchain
291 If Cargo has been installed with rustup, and the first argument to
292 cargo begins with +, it will be interpreted as a rustup toolchain
293 name (such as +stable or +nightly). See the rustup documentation
294 <https://rust-lang.github.io/rustup/overrides.html> for more
295 information about how toolchain overrides work.
296
297 --config KEY=VALUE or PATH
298 Overrides a Cargo configuration value. The argument should be in
299 TOML syntax of KEY=VALUE, or provided as a path to an extra
300 configuration file. This flag may be specified multiple times. See
301 the command-line overrides section
302 <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
303 for more information.
304
305 -h, --help
306 Prints help information.
307
308 -Z flag
309 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
310 details.
311
312 Miscellaneous Options
313 -j N, --jobs N
314 Number of parallel jobs to run. May also be specified with the
315 build.jobs config value
316 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
317 to the number of logical CPUs. If negative, it sets the maximum
318 number of parallel jobs to the number of logical CPUs plus provided
319 value. Should not be 0.
320
321 --keep-going
322 Build as many crates in the dependency graph as possible, rather
323 than aborting the build on the first one that fails to build.
324 Unstable, requires -Zunstable-options.
325
326 --future-incompat-report
327 Displays a future-incompat report for any future-incompatible
328 warnings produced during execution of this command
329
330 See cargo-report(1)
331
333 See the reference
334 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
335 for details on environment variables that Cargo reads.
336
338 • 0: Cargo succeeded.
339
340 • 101: Cargo failed to complete.
341
343 1. Check the local package for errors:
344
345 cargo check
346
347 2. Check all targets, including unit tests:
348
349 cargo check --all-targets --profile=test
350
352 cargo(1), cargo-build(1)
353
354
355
356 CARGO-CHECK(1)