1CARGO-RUN(1)                General Commands Manual               CARGO-RUN(1)
2
3
4

NAME

6       cargo-run - Run the current package
7

SYNOPSIS

9       cargo run [options] [-- args]
10

DESCRIPTION

12       Run a binary or example of the local package.
13
14       All the arguments following the two dashes (--) are passed to the
15       binary to run. If you're passing arguments to both Cargo and the
16       binary, the ones after -- go to the binary, the ones before go to
17       Cargo.
18

OPTIONS

20   Package Selection
21       By default, the package in the current working directory is selected.
22       The -p flag can be used to choose a different package in a workspace.
23
24       -p spec, --package spec
25           The package to run. See cargo-pkgid(1) for the SPEC format.
26
27   Target Selection
28       When no target selection options are given, cargo run will run the
29       binary target. If there are multiple binary targets, you must pass a
30       target flag to choose one. Or, the default-run field may be specified
31       in the [package] section of Cargo.toml to choose the name of the binary
32       to run by default.
33
34       --bin name
35           Run the specified binary.
36
37       --example name
38           Run the specified example.
39
40   Feature Selection
41       The feature flags allow you to control which features are enabled. When
42       no feature options are given, the default feature is activated for
43       every selected package.
44
45       See the features documentation
46       <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>
47       for more details.
48
49       --features features
50           Space or comma separated list of features to activate. Features of
51           workspace members may be enabled with package-name/feature-name
52           syntax. This flag may be specified multiple times, which enables
53           all specified features.
54
55       --all-features
56           Activate all available features of all selected packages.
57
58       --no-default-features
59           Do not activate the default feature of the selected packages.
60
61   Compilation Options
62       --target triple
63           Run for the given architecture. The default is the host
64           architecture. The general format of the triple is
65           <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
66           a list of supported targets.
67
68           This may also be specified with the build.target config value
69           <https://doc.rust-lang.org/cargo/reference/config.html>.
70
71           Note that specifying this flag makes Cargo run in a different mode
72           where the target artifacts are placed in a separate directory. See
73           the build cache
74           <https://doc.rust-lang.org/cargo/guide/build-cache.html>
75           documentation for more details.
76
77       --release
78           Run optimized artifacts with the release profile. See the PROFILES
79           section for details on how this affects profile selection.
80
81       --ignore-rust-version
82           Run the target even if the selected Rust compiler is older than the
83           required Rust version as configured in the project's rust-version
84           field.
85
86   Output Options
87       --target-dir directory
88           Directory for all generated artifacts and intermediate files. May
89           also be specified with the CARGO_TARGET_DIR environment variable,
90           or the build.target-dir config value
91           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
92           to target in the root of the workspace.
93
94   Display Options
95       -v, --verbose
96           Use verbose output. May be specified twice for "very verbose"
97           output which includes extra output such as dependency warnings and
98           build script output. May also be specified with the term.verbose
99           config value
100           <https://doc.rust-lang.org/cargo/reference/config.html>.
101
102       -q, --quiet
103           No output printed to stdout.
104
105       --color when
106           Control when colored output is used. Valid values:
107
108auto (default): Automatically detect if color support is
109               available on the terminal.
110
111always: Always display colors.
112
113never: Never display colors.
114
115           May also be specified with the term.color config value
116           <https://doc.rust-lang.org/cargo/reference/config.html>.
117
118       --message-format fmt
119           The output format for diagnostic messages. Can be specified
120           multiple times and consists of comma-separated values. Valid
121           values:
122
123human (default): Display in a human-readable text format.
124               Conflicts with short and json.
125
126short: Emit shorter, human-readable text messages. Conflicts
127               with human and json.
128
129json: Emit JSON messages to stdout. See the reference
130               <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
131               for more details. Conflicts with human and short.
132
133json-diagnostic-short: Ensure the rendered field of JSON
134               messages contains the "short" rendering from rustc. Cannot be
135               used with human or short.
136
137json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
138               messages contains embedded ANSI color codes for respecting
139               rustc's default color scheme. Cannot be used with human or
140               short.
141
142json-render-diagnostics: Instruct Cargo to not include rustc
143               diagnostics in in JSON messages printed, but instead Cargo
144               itself should render the JSON diagnostics coming from rustc.
145               Cargo's own JSON diagnostics and others coming from rustc are
146               still emitted. Cannot be used with human or short.
147
148   Manifest Options
149       --manifest-path path
150           Path to the Cargo.toml file. By default, Cargo searches for the
151           Cargo.toml file in the current directory or any parent directory.
152
153       --frozen, --locked
154           Either of these flags requires that the Cargo.lock file is
155           up-to-date. If the lock file is missing, or it needs to be updated,
156           Cargo will exit with an error. The --frozen flag also prevents
157           Cargo from attempting to access the network to determine if it is
158           out-of-date.
159
160           These may be used in environments where you want to assert that the
161           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
162           network access.
163
164       --offline
165           Prevents Cargo from accessing the network for any reason. Without
166           this flag, Cargo will stop with an error if it needs to access the
167           network and the network is not available. With this flag, Cargo
168           will attempt to proceed without the network if possible.
169
170           Beware that this may result in different dependency resolution than
171           online mode. Cargo will restrict itself to crates that are
172           downloaded locally, even if there might be a newer version as
173           indicated in the local copy of the index. See the cargo-fetch(1)
174           command to download dependencies before going offline.
175
176           May also be specified with the net.offline config value
177           <https://doc.rust-lang.org/cargo/reference/config.html>.
178
179   Common Options
180       +toolchain
181           If Cargo has been installed with rustup, and the first argument to
182           cargo begins with +, it will be interpreted as a rustup toolchain
183           name (such as +stable or +nightly). See the rustup documentation
184           <https://rust-lang.github.io/rustup/overrides.html> for more
185           information about how toolchain overrides work.
186
187       -h, --help
188           Prints help information.
189
190       -Z flag
191           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
192           details.
193
194   Miscellaneous Options
195       -j N, --jobs N
196           Number of parallel jobs to run. May also be specified with the
197           build.jobs config value
198           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
199           to the number of CPUs.
200

PROFILES

202       Profiles may be used to configure compiler options such as optimization
203       levels and debug settings. See the reference
204       <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
205       details.
206
207       Profile selection depends on the target and crate being built. By
208       default the dev or test profiles are used. If the --release flag is
209       given, then the release or bench profiles are used.
210
211
212       ┌────────────────────┬─────────────────┬───────────────────┐
213       │Target              │ Default Profile │ --release Profile │
214       ├────────────────────┼─────────────────┼───────────────────┤
215       │lib, bin, example   │ dev             release           
216       ├────────────────────┼─────────────────┼───────────────────┤
217       │test, bench, or any │ test            bench             
218       │target in "test" or │                 │                   │
219       │"bench" mode        │                 │                   │
220       └────────────────────┴─────────────────┴───────────────────┘
221
222       Dependencies use the dev/release profiles.
223

ENVIRONMENT

225       See the reference
226       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
227       for details on environment variables that Cargo reads.
228

EXIT STATUS

2300: Cargo succeeded.
231
232101: Cargo failed to complete.
233

EXAMPLES

235        1. Build the local package and run its main target (assuming only one
236           binary):
237
238               cargo run
239
240        2. Run an example with extra arguments:
241
242               cargo run --example exname -- --exoption exarg1 exarg2
243

SEE ALSO

245       cargo(1), cargo-build(1)
246
247
248
249                                                                  CARGO-RUN(1)
Impressum