fork/cargo

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

Weihang Lofix: use `host-tuple` for host target subsitution (#16003)f2932725b

0.93.0
18.1 KiB417 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 specified target architecture. Flag may be specified
141           multiple times. The default is the host architecture. The general
142           format of the triple is <arch><sub>-<vendor>-<sys>-<abi>.
143
144           Possible values:
145
146           o  Any supported target in rustc --print target-list.
147
148           o  "host-tuple", which will internally be substituted by the
149              host’s target. This can be particularly useful if you’re
150              cross-compiling some crates, and don’t want to specify your
151              host’s machine as a target (for instance, an xtask in a shared
152              project that may be worked on by many hosts).
153
154           o  A path to a custom target specification. See Custom Target Lookup
155              Path
156              <https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-path>
157              for more information.
158
159           This may also be specified with the build.target config value
160           <https://doc.rust-lang.org/cargo/reference/config.html>.
161
162           Note that specifying this flag makes Cargo run in a different mode
163           where the target artifacts are placed in a separate directory. See
164           the build cache
165           <https://doc.rust-lang.org/cargo/reference/build-cache.html>
166           documentation for more details.
167
168       -r, --release
169           Build optimized artifacts with the release profile. See also the
170           --profile option for choosing a specific profile by name.
171
172       --profile name
173           Build with the given profile. See the reference
174           <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
175           details on profiles.
176
177       --timings=fmts
178           Output information how long each compilation takes, and track
179           concurrency information over time. Accepts an optional
180           comma-separated list of output formats; --timings without an
181           argument will default to --timings=html. Specifying an output format
182           (rather than the default) is unstable and requires
183           -Zunstable-options. Valid output formats:
184
185           o  html (unstable, requires -Zunstable-options): Write a
186              human-readable file cargo-timing.html to the target/cargo-timings
187              directory with a report of the compilation. Also write a report
188              to the same directory with a timestamp in the filename if you
189              want to look at older runs. HTML output is suitable for human
190              consumption only, and does not provide machine-readable timing
191              data.
192
193           o  json (unstable, requires -Zunstable-options): Emit
194              machine-readable JSON information about timing information.
195
196   Output Options
197       --target-dir directory
198           Directory for all generated artifacts and intermediate files. May
199           also be specified with the CARGO_TARGET_DIR environment variable, or
200           the build.target-dir config value
201           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to
202           target in the root of the workspace.
203
204       --artifact-dir directory
205           Copy final artifacts to this directory.
206
207           This option is unstable and available only on the nightly channel
208           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
209           requires the -Z unstable-options flag to enable. See
210           <https://github.com/rust-lang/cargo/issues/6790> for more
211           information.
212
213   Display Options
214       -v, --verbose
215           Use verbose output. May be specified twice for “very verbose”
216           output which includes extra output such as dependency warnings and
217           build script output. May also be specified with the term.verbose
218           config value
219           <https://doc.rust-lang.org/cargo/reference/config.html>.
220
221       -q, --quiet
222           Do not print cargo log messages. May also be specified with the
223           term.quiet config value
224           <https://doc.rust-lang.org/cargo/reference/config.html>.
225
226       --color when
227           Control when colored output is used. Valid values:
228
229           o  auto (default): Automatically detect if color support is
230              available on the terminal.
231
232           o  always: Always display colors.
233
234           o  never: Never display colors.
235
236           May also be specified with the term.color config value
237           <https://doc.rust-lang.org/cargo/reference/config.html>.
238
239       --message-format fmt
240           The output format for diagnostic messages. Can be specified multiple
241           times and consists of comma-separated values. Valid values:
242
243           o  human (default): Display in a human-readable text format.
244              Conflicts with short and json.
245
246           o  short: Emit shorter, human-readable text messages. Conflicts with
247              human and json.
248
249           o  json: Emit JSON messages to stdout. See the reference
250              <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
251              for more details. Conflicts with human and short.
252
253           o  json-diagnostic-short: Ensure the rendered field of JSON messages
254              contains the “short” rendering from rustc. Cannot be used
255              with human or short.
256
257           o  json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
258              messages contains embedded ANSI color codes for respecting
259              rustc’s default color scheme. Cannot be used with human or
260              short.
261
262           o  json-render-diagnostics: Instruct Cargo to not include rustc
263              diagnostics in JSON messages printed, but instead Cargo itself
264              should render the JSON diagnostics coming from rustc. Cargo’s
265              own JSON diagnostics and others coming from rustc are still
266              emitted. Cannot be used with human or short.
267
268       --build-plan
269           Outputs a series of JSON messages to stdout that indicate the
270           commands to run the build.
271
272           This option is unstable and available only on the nightly channel
273           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
274           requires the -Z unstable-options flag to enable. See
275           <https://github.com/rust-lang/cargo/issues/5579> for more
276           information.
277
278   Manifest Options
279       --manifest-path path
280           Path to the Cargo.toml file. By default, Cargo searches for the
281           Cargo.toml file in the current directory or any parent directory.
282
283       --ignore-rust-version
284           Ignore rust-version specification in packages.
285
286       --locked
287           Asserts that the exact same dependencies and versions are used as
288           when the existing Cargo.lock file was originally generated. Cargo
289           will exit with an error when either of the following scenarios
290           arises:
291
292           o  The lock file is missing.
293
294           o  Cargo attempted to change the lock file due to a different
295              dependency resolution.
296
297           It may be used in environments where deterministic builds are
298           desired, such as in CI pipelines.
299
300       --offline
301           Prevents Cargo from accessing the network for any reason. Without
302           this flag, Cargo will stop with an error if it needs to access the
303           network and the network is not available. With this flag, Cargo will
304           attempt to proceed without the network if possible.
305
306           Beware that this may result in different dependency resolution than
307           online mode. Cargo will restrict itself to crates that are
308           downloaded locally, even if there might be a newer version as
309           indicated in the local copy of the index. See the cargo-fetch(1)
310           command to download dependencies before going offline.
311
312           May also be specified with the net.offline config value
313           <https://doc.rust-lang.org/cargo/reference/config.html>.
314
315       --frozen
316           Equivalent to specifying both --locked and --offline.
317
318       --lockfile-path PATH
319           Changes the path of the lockfile from the default
320           (<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock
321           (e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that
322           providing --lockfile-path will ignore existing lockfile at the
323           default path, and instead will either use the lockfile from PATH, or
324           write a new lockfile into the provided PATH if it doesn’t exist.
325           This flag can be used to run most commands in read-only directories,
326           writing lockfile into the provided PATH.
327
328           This option is only available on the nightly channel
329           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
330           requires the -Z unstable-options flag to enable (see #14421
331           <https://github.com/rust-lang/cargo/issues/14421>).
332
333   Common Options
334       +toolchain
335           If Cargo has been installed with rustup, and the first argument to
336           cargo begins with +, it will be interpreted as a rustup toolchain
337           name (such as +stable or +nightly). See the rustup documentation
338           <https://rust-lang.github.io/rustup/overrides.html> for more
339           information about how toolchain overrides work.
340
341       --config KEY=VALUE or PATH
342           Overrides a Cargo configuration value. The argument should be in
343           TOML syntax of KEY=VALUE, or provided as a path to an extra
344           configuration file. This flag may be specified multiple times. See
345           the command-line overrides section
346           <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
347           for more information.
348
349       -C PATH
350           Changes the current working directory before executing any specified
351           operations. This affects things like where cargo looks by default
352           for the project manifest (Cargo.toml), as well as the directories
353           searched for discovering .cargo/config.toml, for example. This
354           option must appear before the command name, for example cargo -C
355           path/to/my-project build.
356
357           This option is only available on the nightly channel
358           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
359           requires the -Z unstable-options flag to enable (see #10098
360           <https://github.com/rust-lang/cargo/issues/10098>).
361
362       -h, --help
363           Prints help information.
364
365       -Z flag
366           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
367           details.
368
369   Miscellaneous Options
370       -j N, --jobs N
371           Number of parallel jobs to run. May also be specified with the
372           build.jobs config value
373           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to
374           the number of logical CPUs. If negative, it sets the maximum number
375           of parallel jobs to the number of logical CPUs plus provided value.
376           If a string default is provided, it sets the value back to defaults.
377           Should not be 0.
378
379       --keep-going
380           Build as many crates in the dependency graph as possible, rather
381           than aborting the build on the first one that fails to build.
382
383           For example if the current package depends on dependencies fails and
384           works, one of which fails to build, cargo build -j1 may or may not
385           build the one that succeeds (depending on which one of the two
386           builds Cargo picked to run first), whereas cargo build -j1
387           --keep-going would definitely run both builds, even if the one run
388           first fails.
389
390       --future-incompat-report
391           Displays a future-incompat report for any future-incompatible
392           warnings produced during execution of this command
393
394           See cargo-report(1)
395
396ENVIRONMENT
397       See the reference
398       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
399       for details on environment variables that Cargo reads.
400
401EXIT STATUS
402       o  0: Cargo succeeded.
403
404       o  101: Cargo failed to complete.
405
406EXAMPLES
407       1. Build the local package and all of its dependencies:
408
409              cargo build
410
411       2. Build with optimizations:
412
413              cargo build --release
414
415SEE ALSO
416       cargo(1), cargo-rustc(1)
417