fork/cargo

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

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

home-0.5.12
21.3 KiB479 linesraw
1CARGO-BENCH(1)
2
3NAME
4       cargo-bench — Execute benchmarks of a package
5
6SYNOPSIS
7       cargo bench [options] [benchname] [-- bench-options]
8
9DESCRIPTION
10       Compile and execute benchmarks.
11
12       The benchmark filtering argument benchname and all the arguments
13       following the two dashes (--) are passed to the benchmark binaries and
14       thus to libtest (rustc’s built in unit-test and micro-benchmarking
15       framework). If you are passing arguments to both Cargo and the binary,
16       the ones after -- go to the binary, the ones before go to Cargo. For
17       details about libtest’s arguments see the output of cargo bench --
18       --help and check out the rustc book’s chapter on how tests work at
19       <https://doc.rust-lang.org/rustc/tests/index.html>.
20
21       As an example, this will run only the benchmark named foo (and skip
22       other similarly named benchmarks like foobar):
23
24           cargo bench -- foo --exact
25
26       Benchmarks are built with the --test option to rustc which creates a
27       special executable by linking your code with libtest. The executable
28       automatically runs all functions annotated with the #[bench] attribute.
29       Cargo passes the --bench flag to the test harness to tell it to run only
30       benchmarks, regardless of whether the harness is libtest or a custom
31       harness.
32
33       The libtest harness may be disabled by setting harness = false in the
34       target manifest settings, in which case your code will need to provide
35       its own main function to handle running benchmarks.
36
37          Note: The #[bench] attribute
38          <https://doc.rust-lang.org/nightly/unstable-book/library-features/test.html>
39          is currently unstable and only available on the nightly channel
40          <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html>. There
41          are some packages available on crates.io
42          <https://crates.io/keywords/benchmark> that may help with running
43          benchmarks on the stable channel, such as Criterion
44          <https://crates.io/crates/criterion>.
45
46       By default, cargo bench uses the bench profile
47       <https://doc.rust-lang.org/cargo/reference/profiles.html#bench>, which
48       enables optimizations and disables debugging information. If you need to
49       debug a benchmark, you can use the --profile=dev command-line option to
50       switch to the dev profile. You can then run the debug-enabled benchmark
51       within a debugger.
52
53   Working directory of benchmarks
54       The working directory of every benchmark is set to the root directory of
55       the package the benchmark belongs to. Setting the working directory of
56       benchmarks to the package’s root directory makes it possible for
57       benchmarks to reliably access the package’s files using relative
58       paths, regardless from where cargo bench was executed from.
59
60OPTIONS
61   Benchmark Options
62       --no-run
63           Compile, but don’t run benchmarks.
64
65       --no-fail-fast
66           Run all benchmarks regardless of failure. Without this flag, Cargo
67           will exit after the first executable fails. The Rust test harness
68           will run all benchmarks within the executable to completion, this
69           flag only applies to the executable as a whole.
70
71   Package Selection
72       By default, when no package selection options are given, the packages
73       selected depend on the selected manifest file (based on the current
74       working directory if --manifest-path is not given). If the manifest is
75       the root of a workspace then the workspaces default members are
76       selected, otherwise only the package defined by the manifest will be
77       selected.
78
79       The default members of a workspace can be set explicitly with the
80       workspace.default-members key in the root manifest. If this is not set,
81       a virtual workspace will include all workspace members (equivalent to
82       passing --workspace), and a non-virtual workspace will include only the
83       root crate itself.
84
85       -p spec…, --package spec…
86           Benchmark only the specified packages. See cargo-pkgid(1) for the
87           SPEC format. This flag may be specified multiple times and supports
88           common Unix glob patterns like *, ? and []. However, to avoid your
89           shell accidentally expanding glob patterns before Cargo handles
90           them, you must use single quotes or double quotes around each
91           pattern.
92
93       --workspace
94           Benchmark all members in the workspace.
95
96       --all
97           Deprecated alias for --workspace.
98
99       --exclude SPEC…
100           Exclude the specified packages. Must be used in conjunction with the
101           --workspace flag. This flag may be specified multiple times and
102           supports common Unix glob patterns like *, ? and []. However, to
103           avoid your shell accidentally expanding glob patterns before Cargo
104           handles them, you must use single quotes or double quotes around
105           each pattern.
106
107   Target Selection
108       When no target selection options are given, cargo bench will build the
109       following targets of the selected packages:
110
111       o  lib — used to link with binaries and benchmarks
112
113       o  bins (only if benchmark targets are built and required features are
114          available)
115
116       o  lib as a benchmark
117
118       o  bins as benchmarks
119
120       o  benchmark targets
121
122       The default behavior can be changed by setting the bench flag for the
123       target in the manifest settings. Setting examples to bench = true will
124       build and run the example as a benchmark, replacing the example’s main
125       function with the libtest harness.
126
127       Setting targets to bench = false will stop them from being benchmarked
128       by default. Target selection options that take a target by name (such as
129       --example foo) ignore the bench flag and will always benchmark the given
130       target.
131
132       See Configuring a target
133       <https://doc.rust-lang.org/cargo/reference/cargo-targets.html#configuring-a-target>
134       for more information on per-target settings.
135
136       Binary targets are automatically built if there is an integration test
137       or benchmark being selected to benchmark. This allows an integration
138       test to execute the binary to exercise and test its behavior. The
139       CARGO_BIN_EXE_<name> environment variable
140       <https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates>
141       is set when the integration test is built so that it can use the env
142       macro <https://doc.rust-lang.org/std/macro.env.html> to locate the
143       executable.
144
145       Passing target selection flags will benchmark only the specified
146       targets.
147
148       Note that --bin, --example, --test and --bench flags also support common
149       Unix glob patterns like *, ? and []. However, to avoid your shell
150       accidentally expanding glob patterns before Cargo handles them, you must
151       use single quotes or double quotes around each glob pattern.
152
153       --lib
154           Benchmark the package’s library.
155
156       --bin name…
157           Benchmark the specified binary. This flag may be specified multiple
158           times and supports common Unix glob patterns.
159
160       --bins
161           Benchmark all binary targets.
162
163       --example name…
164           Benchmark the specified example. This flag may be specified multiple
165           times and supports common Unix glob patterns.
166
167       --examples
168           Benchmark all example targets.
169
170       --test name…
171           Benchmark the specified integration test. This flag may be specified
172           multiple times and supports common Unix glob patterns.
173
174       --tests
175           Benchmark all targets that have the test = true manifest flag set.
176           By default this includes the library and binaries built as
177           unittests, and integration tests. Be aware that this will also build
178           any required dependencies, so the lib target may be built twice
179           (once as a unittest, and once as a dependency for binaries,
180           integration tests, etc.). Targets may be enabled or disabled by
181           setting the test flag in the manifest settings for the target.
182
183       --bench name…
184           Benchmark the specified benchmark. This flag may be specified
185           multiple times and supports common Unix glob patterns.
186
187       --benches
188           Benchmark all targets that have the bench = true manifest flag set.
189           By default this includes the library and binaries built as
190           benchmarks, and bench targets. Be aware that this will also build
191           any required dependencies, so the lib target may be built twice
192           (once as a benchmark, and once as a dependency for binaries,
193           benchmarks, etc.). Targets may be enabled or disabled by setting the
194           bench flag in the manifest settings for the target.
195
196       --all-targets
197           Benchmark all targets. This is equivalent to specifying --lib --bins
198           --tests --benches --examples.
199
200   Feature Selection
201       The feature flags allow you to control which features are enabled. When
202       no feature options are given, the default feature is activated for every
203       selected package.
204
205       See the features documentation
206       <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>
207       for more details.
208
209       -F features, --features features
210           Space or comma separated list of features to activate. Features of
211           workspace members may be enabled with package-name/feature-name
212           syntax. This flag may be specified multiple times, which enables all
213           specified features.
214
215       --all-features
216           Activate all available features of all selected packages.
217
218       --no-default-features
219           Do not activate the default feature of the selected packages.
220
221   Compilation Options
222       --target triple
223           Benchmark for the specified target architecture. Flag may be
224           specified multiple times. The default is the host architecture. The
225           general format of the triple is <arch><sub>-<vendor>-<sys>-<abi>.
226
227           Possible values:
228
229           o  Any supported target in rustc --print target-list.
230
231           o  "host-tuple", which will internally be substituted by the
232              host’s target. This can be particularly useful if you’re
233              cross-compiling some crates, and don’t want to specify your
234              host’s machine as a target (for instance, an xtask in a shared
235              project that may be worked on by many hosts).
236
237           o  A path to a custom target specification. See Custom Target Lookup
238              Path
239              <https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-path>
240              for more information.
241
242           This may also be specified with the build.target config value
243           <https://doc.rust-lang.org/cargo/reference/config.html>.
244
245           Note that specifying this flag makes Cargo run in a different mode
246           where the target artifacts are placed in a separate directory. See
247           the build cache
248           <https://doc.rust-lang.org/cargo/reference/build-cache.html>
249           documentation for more details.
250
251       --profile name
252           Benchmark with the given profile. See the reference
253           <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
254           details on profiles.
255
256       --timings=fmts
257           Output information how long each compilation takes, and track
258           concurrency information over time. Accepts an optional
259           comma-separated list of output formats; --timings without an
260           argument will default to --timings=html. Specifying an output format
261           (rather than the default) is unstable and requires
262           -Zunstable-options. Valid output formats:
263
264           o  html (unstable, requires -Zunstable-options): Write a
265              human-readable file cargo-timing.html to the target/cargo-timings
266              directory with a report of the compilation. Also write a report
267              to the same directory with a timestamp in the filename if you
268              want to look at older runs. HTML output is suitable for human
269              consumption only, and does not provide machine-readable timing
270              data.
271
272           o  json (unstable, requires -Zunstable-options): Emit
273              machine-readable JSON information about timing information.
274
275   Output Options
276       --target-dir directory
277           Directory for all generated artifacts and intermediate files. May
278           also be specified with the CARGO_TARGET_DIR environment variable, or
279           the build.target-dir config value
280           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to
281           target in the root of the workspace.
282
283   Display Options
284       By default the Rust test harness hides output from benchmark execution
285       to keep results readable. Benchmark output can be recovered (e.g., for
286       debugging) by passing --no-capture to the benchmark binaries:
287
288           cargo bench -- --no-capture
289
290       -v, --verbose
291           Use verbose output. May be specified twice for “very verbose”
292           output which includes extra output such as dependency warnings and
293           build script output. May also be specified with the term.verbose
294           config value
295           <https://doc.rust-lang.org/cargo/reference/config.html>.
296
297       -q, --quiet
298           Do not print cargo log messages. May also be specified with the
299           term.quiet config value
300           <https://doc.rust-lang.org/cargo/reference/config.html>.
301
302       --color when
303           Control when colored output is used. Valid values:
304
305           o  auto (default): Automatically detect if color support is
306              available on the terminal.
307
308           o  always: Always display colors.
309
310           o  never: Never display colors.
311
312           May also be specified with the term.color config value
313           <https://doc.rust-lang.org/cargo/reference/config.html>.
314
315       --message-format fmt
316           The output format for diagnostic messages. Can be specified multiple
317           times and consists of comma-separated values. Valid values:
318
319           o  human (default): Display in a human-readable text format.
320              Conflicts with short and json.
321
322           o  short: Emit shorter, human-readable text messages. Conflicts with
323              human and json.
324
325           o  json: Emit JSON messages to stdout. See the reference
326              <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
327              for more details. Conflicts with human and short.
328
329           o  json-diagnostic-short: Ensure the rendered field of JSON messages
330              contains the “short” rendering from rustc. Cannot be used
331              with human or short.
332
333           o  json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
334              messages contains embedded ANSI color codes for respecting
335              rustc’s default color scheme. Cannot be used with human or
336              short.
337
338           o  json-render-diagnostics: Instruct Cargo to not include rustc
339              diagnostics in JSON messages printed, but instead Cargo itself
340              should render the JSON diagnostics coming from rustc. Cargo’s
341              own JSON diagnostics and others coming from rustc are still
342              emitted. Cannot be used with human or short.
343
344   Manifest Options
345       --manifest-path path
346           Path to the Cargo.toml file. By default, Cargo searches for the
347           Cargo.toml file in the current directory or any parent directory.
348
349       --ignore-rust-version
350           Ignore rust-version specification in packages.
351
352       --locked
353           Asserts that the exact same dependencies and versions are used as
354           when the existing Cargo.lock file was originally generated. Cargo
355           will exit with an error when either of the following scenarios
356           arises:
357
358           o  The lock file is missing.
359
360           o  Cargo attempted to change the lock file due to a different
361              dependency resolution.
362
363           It may be used in environments where deterministic builds are
364           desired, such as in CI pipelines.
365
366       --offline
367           Prevents Cargo from accessing the network for any reason. Without
368           this flag, Cargo will stop with an error if it needs to access the
369           network and the network is not available. With this flag, Cargo will
370           attempt to proceed without the network if possible.
371
372           Beware that this may result in different dependency resolution than
373           online mode. Cargo will restrict itself to crates that are
374           downloaded locally, even if there might be a newer version as
375           indicated in the local copy of the index. See the cargo-fetch(1)
376           command to download dependencies before going offline.
377
378           May also be specified with the net.offline config value
379           <https://doc.rust-lang.org/cargo/reference/config.html>.
380
381       --frozen
382           Equivalent to specifying both --locked and --offline.
383
384       --lockfile-path PATH
385           Changes the path of the lockfile from the default
386           (<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock
387           (e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that
388           providing --lockfile-path will ignore existing lockfile at the
389           default path, and instead will either use the lockfile from PATH, or
390           write a new lockfile into the provided PATH if it doesn’t exist.
391           This flag can be used to run most commands in read-only directories,
392           writing lockfile into the provided PATH.
393
394           This option is only available on the nightly channel
395           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
396           requires the -Z unstable-options flag to enable (see #14421
397           <https://github.com/rust-lang/cargo/issues/14421>).
398
399   Common Options
400       +toolchain
401           If Cargo has been installed with rustup, and the first argument to
402           cargo begins with +, it will be interpreted as a rustup toolchain
403           name (such as +stable or +nightly). See the rustup documentation
404           <https://rust-lang.github.io/rustup/overrides.html> for more
405           information about how toolchain overrides work.
406
407       --config KEY=VALUE or PATH
408           Overrides a Cargo configuration value. The argument should be in
409           TOML syntax of KEY=VALUE, or provided as a path to an extra
410           configuration file. This flag may be specified multiple times. See
411           the command-line overrides section
412           <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
413           for more information.
414
415       -C PATH
416           Changes the current working directory before executing any specified
417           operations. This affects things like where cargo looks by default
418           for the project manifest (Cargo.toml), as well as the directories
419           searched for discovering .cargo/config.toml, for example. This
420           option must appear before the command name, for example cargo -C
421           path/to/my-project build.
422
423           This option is only available on the nightly channel
424           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
425           requires the -Z unstable-options flag to enable (see #10098
426           <https://github.com/rust-lang/cargo/issues/10098>).
427
428       -h, --help
429           Prints help information.
430
431       -Z flag
432           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
433           details.
434
435   Miscellaneous Options
436       The --jobs argument affects the building of the benchmark executable but
437       does not affect how many threads are used when running the benchmarks.
438       The Rust test harness runs benchmarks serially in a single thread.
439
440       -j N, --jobs N
441           Number of parallel jobs to run. May also be specified with the
442           build.jobs config value
443           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to
444           the number of logical CPUs. If negative, it sets the maximum number
445           of parallel jobs to the number of logical CPUs plus provided value.
446           If a string default is provided, it sets the value back to defaults.
447           Should not be 0.
448
449       While cargo bench involves compilation, it does not provide a
450       --keep-going flag. Use --no-fail-fast to run as many benchmarks as
451       possible without stopping at the first failure. To “compile” as many
452       benchmarks as possible, use --benches to build benchmark binaries
453       separately. For example:
454
455           cargo build --benches --release --keep-going
456           cargo bench --no-fail-fast
457
458ENVIRONMENT
459       See the reference
460       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
461       for details on environment variables that Cargo reads.
462
463EXIT STATUS
464       o  0: Cargo succeeded.
465
466       o  101: Cargo failed to complete.
467
468EXAMPLES
469       1. Build and execute all the benchmarks of the current package:
470
471              cargo bench
472
473       2. Run only a specific benchmark within a specific benchmark target:
474
475              cargo bench --bench bench_name -- modname::some_benchmark
476
477SEE ALSO
478       cargo(1), cargo-test(1)
479