fork/cargo

git clone https://git.julia.blue/fork/cargo

borsAuto merge of #14675 - RalfJung:help, r=weihanglode128bea7

0.91.0
17.5 KiB404 linesraw
1CARGO-BUILD(1)
2
3NAME
4       cargo-build — Compile the current package
5
6SYNOPSIS
7       cargo build [options]
8
9DESCRIPTION
10       Compile local packages and all of their dependencies.
11
12OPTIONS
13   Package Selection
14       By default, when no package selection options are given, the packages
15       selected depend on the selected manifest file (based on the current
16       working directory if --manifest-path is not given). If the manifest is
17       the root of a workspace then the workspaces default members are
18       selected, otherwise only the package defined by the manifest will be
19       selected.
20
21       The default members of a workspace can be set explicitly with the
22       workspace.default-members key in the root manifest. If this is not set,
23       a virtual workspace will include all workspace members (equivalent to
24       passing --workspace), and a non-virtual workspace will include only the
25       root crate itself.
26
27       -p spec…, --package spec…
28           Build only the specified packages. See cargo-pkgid(1) for the SPEC
29           format. This flag may be specified multiple times and supports
30           common Unix glob patterns like *, ? and []. However, to avoid your
31           shell accidentally expanding glob patterns before Cargo handles
32           them, you must use single quotes or double quotes around each
33           pattern.
34
35       --workspace
36           Build all members in the workspace.
37
38       --all
39           Deprecated alias for --workspace.
40
41       --exclude SPEC…
42           Exclude the specified packages. Must be used in conjunction with the
43           --workspace flag. This flag may be specified multiple times and
44           supports common Unix glob patterns like *, ? and []. However, to
45           avoid your shell accidentally expanding glob patterns before Cargo
46           handles them, you must use single quotes or double quotes around
47           each pattern.
48
49   Target Selection
50       When no target selection options are given, cargo build will build all
51       binary and library targets of the selected packages. Binaries are
52       skipped if they have required-features that are missing.
53
54       Binary targets are automatically built if there is an integration test
55       or benchmark being selected to build. This allows an integration test to
56       execute the binary to exercise and test its behavior. The
57       CARGO_BIN_EXE_<name> environment variable
58       <https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates>
59       is set when the integration test is built so that it can use the env
60       macro <https://doc.rust-lang.org/std/macro.env.html> to locate the
61       executable.
62
63       Passing target selection flags will build only the specified targets.
64
65       Note that --bin, --example, --test and --bench flags also support common
66       Unix glob patterns like *, ? and []. However, to avoid your shell
67       accidentally expanding glob patterns before Cargo handles them, you must
68       use single quotes or double quotes around each glob pattern.
69
70       --lib
71           Build the package’s library.
72
73       --bin name…
74           Build the specified binary. This flag may be specified multiple
75           times and supports common Unix glob patterns.
76
77       --bins
78           Build all binary targets.
79
80       --example name…
81           Build the specified example. This flag may be specified multiple
82           times and supports common Unix glob patterns.
83
84       --examples
85           Build all example targets.
86
87       --test name…
88           Build the specified integration test. This flag may be specified
89           multiple times and supports common Unix glob patterns.
90
91       --tests
92           Build all targets that have the test = true manifest flag set. By
93           default this includes the library and binaries built as unittests,
94           and integration tests. Be aware that this will also build any
95           required dependencies, so the lib target may be built twice (once as
96           a unittest, and once as a dependency for binaries, integration
97           tests, etc.). Targets may be enabled or disabled by setting the test
98           flag in the manifest settings for the target.
99
100       --bench name…
101           Build the specified benchmark. This flag may be specified multiple
102           times and supports common Unix glob patterns.
103
104       --benches
105           Build all targets that have the bench = true manifest flag set. By
106           default this includes the library and binaries built as benchmarks,
107           and bench targets. Be aware that this will also build any required
108           dependencies, so the lib target may be built twice (once as a
109           benchmark, and once as a dependency for binaries, benchmarks, etc.).
110           Targets may be enabled or disabled by setting the bench flag in the
111           manifest settings for the target.
112
113       --all-targets
114           Build all targets. This is equivalent to specifying --lib --bins
115           --tests --benches --examples.
116
117   Feature Selection
118       The feature flags allow you to control which features are enabled. When
119       no feature options are given, the default feature is activated for every
120       selected package.
121
122       See the features documentation
123       <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>
124       for more details.
125
126       -F features, --features features
127           Space or comma separated list of features to activate. Features of
128           workspace members may be enabled with package-name/feature-name
129           syntax. This flag may be specified multiple times, which enables all
130           specified features.
131
132       --all-features
133           Activate all available features of all selected packages.
134
135       --no-default-features
136           Do not activate the default feature of the selected packages.
137
138   Compilation Options
139       --target triple
140           Build for the given architecture. The default is the host
141           architecture. The general format of the triple is
142           <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
143           a list of supported targets. This flag may be specified multiple
144           times.
145
146           This may also be specified with the build.target config value
147           <https://doc.rust-lang.org/cargo/reference/config.html>.
148
149           Note that specifying this flag makes Cargo run in a different mode
150           where the target artifacts are placed in a separate directory. See
151           the build cache
152           <https://doc.rust-lang.org/cargo/reference/build-cache.html>
153           documentation for more details.
154
155       -r, --release
156           Build optimized artifacts with the release profile. See also the
157           --profile option for choosing a specific profile by name.
158
159       --profile name
160           Build with the given profile. See the reference
161           <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
162           details on profiles.
163
164       --timings=fmts
165           Output information how long each compilation takes, and track
166           concurrency information over time. Accepts an optional
167           comma-separated list of output formats; --timings without an
168           argument will default to --timings=html. Specifying an output format
169           (rather than the default) is unstable and requires
170           -Zunstable-options. Valid output formats:
171
172           o  html (unstable, requires -Zunstable-options): Write a
173              human-readable file cargo-timing.html to the target/cargo-timings
174              directory with a report of the compilation. Also write a report
175              to the same directory with a timestamp in the filename if you
176              want to look at older runs. HTML output is suitable for human
177              consumption only, and does not provide machine-readable timing
178              data.
179
180           o  json (unstable, requires -Zunstable-options): Emit
181              machine-readable JSON information about timing information.
182
183   Output Options
184       --target-dir directory
185           Directory for all generated artifacts and intermediate files. May
186           also be specified with the CARGO_TARGET_DIR environment variable, or
187           the build.target-dir config value
188           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to
189           target in the root of the workspace.
190
191       --artifact-dir directory
192           Copy final artifacts to this directory.
193
194           This option is unstable and available only on the nightly channel
195           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
196           requires the -Z unstable-options flag to enable. See
197           <https://github.com/rust-lang/cargo/issues/6790> for more
198           information.
199
200   Display Options
201       -v, --verbose
202           Use verbose output. May be specified twice for “very verbose”
203           output which includes extra output such as dependency warnings and
204           build script output. May also be specified with the term.verbose
205           config value
206           <https://doc.rust-lang.org/cargo/reference/config.html>.
207
208       -q, --quiet
209           Do not print cargo log messages. May also be specified with the
210           term.quiet config value
211           <https://doc.rust-lang.org/cargo/reference/config.html>.
212
213       --color when
214           Control when colored output is used. Valid values:
215
216           o  auto (default): Automatically detect if color support is
217              available on the terminal.
218
219           o  always: Always display colors.
220
221           o  never: Never display colors.
222
223           May also be specified with the term.color config value
224           <https://doc.rust-lang.org/cargo/reference/config.html>.
225
226       --message-format fmt
227           The output format for diagnostic messages. Can be specified multiple
228           times and consists of comma-separated values. Valid values:
229
230           o  human (default): Display in a human-readable text format.
231              Conflicts with short and json.
232
233           o  short: Emit shorter, human-readable text messages. Conflicts with
234              human and json.
235
236           o  json: Emit JSON messages to stdout. See the reference
237              <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
238              for more details. Conflicts with human and short.
239
240           o  json-diagnostic-short: Ensure the rendered field of JSON messages
241              contains the “short” rendering from rustc. Cannot be used
242              with human or short.
243
244           o  json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
245              messages contains embedded ANSI color codes for respecting
246              rustc’s default color scheme. Cannot be used with human or
247              short.
248
249           o  json-render-diagnostics: Instruct Cargo to not include rustc
250              diagnostics in JSON messages printed, but instead Cargo itself
251              should render the JSON diagnostics coming from rustc. Cargo’s
252              own JSON diagnostics and others coming from rustc are still
253              emitted. Cannot be used with human or short.
254
255       --build-plan
256           Outputs a series of JSON messages to stdout that indicate the
257           commands to run the build.
258
259           This option is unstable and available only on the nightly channel
260           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
261           requires the -Z unstable-options flag to enable. See
262           <https://github.com/rust-lang/cargo/issues/5579> for more
263           information.
264
265   Manifest Options
266       --manifest-path path
267           Path to the Cargo.toml file. By default, Cargo searches for the
268           Cargo.toml file in the current directory or any parent directory.
269
270       --ignore-rust-version
271           Ignore rust-version specification in packages.
272
273       --locked
274           Asserts that the exact same dependencies and versions are used as
275           when the existing Cargo.lock file was originally generated. Cargo
276           will exit with an error when either of the following scenarios
277           arises:
278
279           o  The lock file is missing.
280
281           o  Cargo attempted to change the lock file due to a different
282              dependency resolution.
283
284           It may be used in environments where deterministic builds are
285           desired, such as in CI pipelines.
286
287       --offline
288           Prevents Cargo from accessing the network for any reason. Without
289           this flag, Cargo will stop with an error if it needs to access the
290           network and the network is not available. With this flag, Cargo will
291           attempt to proceed without the network if possible.
292
293           Beware that this may result in different dependency resolution than
294           online mode. Cargo will restrict itself to crates that are
295           downloaded locally, even if there might be a newer version as
296           indicated in the local copy of the index. See the cargo-fetch(1)
297           command to download dependencies before going offline.
298
299           May also be specified with the net.offline config value
300           <https://doc.rust-lang.org/cargo/reference/config.html>.
301
302       --frozen
303           Equivalent to specifying both --locked and --offline.
304
305       --lockfile-path PATH
306           Changes the path of the lockfile from the default
307           (<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock
308           (e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that
309           providing --lockfile-path will ignore existing lockfile at the
310           default path, and instead will either use the lockfile from PATH, or
311           write a new lockfile into the provided PATH if it doesn’t exist.
312           This flag can be used to run most commands in read-only directories,
313           writing lockfile into the provided PATH.
314
315           This option is only available on the nightly channel
316           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
317           requires the -Z unstable-options flag to enable (see #14421
318           <https://github.com/rust-lang/cargo/issues/14421>).
319
320   Common Options
321       +toolchain
322           If Cargo has been installed with rustup, and the first argument to
323           cargo begins with +, it will be interpreted as a rustup toolchain
324           name (such as +stable or +nightly). See the rustup documentation
325           <https://rust-lang.github.io/rustup/overrides.html> for more
326           information about how toolchain overrides work.
327
328       --config KEY=VALUE or PATH
329           Overrides a Cargo configuration value. The argument should be in
330           TOML syntax of KEY=VALUE, or provided as a path to an extra
331           configuration file. This flag may be specified multiple times. See
332           the command-line overrides section
333           <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
334           for more information.
335
336       -C PATH
337           Changes the current working directory before executing any specified
338           operations. This affects things like where cargo looks by default
339           for the project manifest (Cargo.toml), as well as the directories
340           searched for discovering .cargo/config.toml, for example. This
341           option must appear before the command name, for example cargo -C
342           path/to/my-project build.
343
344           This option is only available on the nightly channel
345           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
346           requires the -Z unstable-options flag to enable (see #10098
347           <https://github.com/rust-lang/cargo/issues/10098>).
348
349       -h, --help
350           Prints help information.
351
352       -Z flag
353           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
354           details.
355
356   Miscellaneous Options
357       -j N, --jobs N
358           Number of parallel jobs to run. May also be specified with the
359           build.jobs config value
360           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to
361           the number of logical CPUs. If negative, it sets the maximum number
362           of parallel jobs to the number of logical CPUs plus provided value.
363           If a string default is provided, it sets the value back to defaults.
364           Should not be 0.
365
366       --keep-going
367           Build as many crates in the dependency graph as possible, rather
368           than aborting the build on the first one that fails to build.
369
370           For example if the current package depends on dependencies fails and
371           works, one of which fails to build, cargo build -j1 may or may not
372           build the one that succeeds (depending on which one of the two
373           builds Cargo picked to run first), whereas cargo build -j1
374           --keep-going would definitely run both builds, even if the one run
375           first fails.
376
377       --future-incompat-report
378           Displays a future-incompat report for any future-incompatible
379           warnings produced during execution of this command
380
381           See cargo-report(1)
382
383ENVIRONMENT
384       See the reference
385       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
386       for details on environment variables that Cargo reads.
387
388EXIT STATUS
389       o  0: Cargo succeeded.
390
391       o  101: Cargo failed to complete.
392
393EXAMPLES
394       1. Build the local package and all of its dependencies:
395
396              cargo build
397
398       2. Build with optimizations:
399
400              cargo build --release
401
402SEE ALSO
403       cargo(1), cargo-rustc(1)
404