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   Output Options
82       --target-dir directory
83           Directory for all generated artifacts and intermediate files. May
84           also be specified with the CARGO_TARGET_DIR environment variable,
85           or the build.target-dir config value
86           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
87           to target in the root of the workspace.
88
89   Display Options
90       -v, --verbose
91           Use verbose output. May be specified twice for "very verbose"
92           output which includes extra output such as dependency warnings and
93           build script output. May also be specified with the term.verbose
94           config value
95           <https://doc.rust-lang.org/cargo/reference/config.html>.
96
97       -q, --quiet
98           No output printed to stdout.
99
100       --color when
101           Control when colored output is used. Valid values:
102
103auto (default): Automatically detect if color support is
104               available on the terminal.
105
106always: Always display colors.
107
108never: Never display colors.
109
110           May also be specified with the term.color config value
111           <https://doc.rust-lang.org/cargo/reference/config.html>.
112
113       --message-format fmt
114           The output format for diagnostic messages. Can be specified
115           multiple times and consists of comma-separated values. Valid
116           values:
117
118human (default): Display in a human-readable text format.
119               Conflicts with short and json.
120
121short: Emit shorter, human-readable text messages. Conflicts
122               with human and json.
123
124json: Emit JSON messages to stdout. See the reference
125               <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
126               for more details. Conflicts with human and short.
127
128json-diagnostic-short: Ensure the rendered field of JSON
129               messages contains the "short" rendering from rustc. Cannot be
130               used with human or short.
131
132json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
133               messages contains embedded ANSI color codes for respecting
134               rustc's default color scheme. Cannot be used with human or
135               short.
136
137json-render-diagnostics: Instruct Cargo to not include rustc
138               diagnostics in in JSON messages printed, but instead Cargo
139               itself should render the JSON diagnostics coming from rustc.
140               Cargo's own JSON diagnostics and others coming from rustc are
141               still emitted. Cannot be used with human or short.
142
143   Manifest Options
144       --manifest-path path
145           Path to the Cargo.toml file. By default, Cargo searches for the
146           Cargo.toml file in the current directory or any parent directory.
147
148       --frozen, --locked
149           Either of these flags requires that the Cargo.lock file is
150           up-to-date. If the lock file is missing, or it needs to be updated,
151           Cargo will exit with an error. The --frozen flag also prevents
152           Cargo from attempting to access the network to determine if it is
153           out-of-date.
154
155           These may be used in environments where you want to assert that the
156           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
157           network access.
158
159       --offline
160           Prevents Cargo from accessing the network for any reason. Without
161           this flag, Cargo will stop with an error if it needs to access the
162           network and the network is not available. With this flag, Cargo
163           will attempt to proceed without the network if possible.
164
165           Beware that this may result in different dependency resolution than
166           online mode. Cargo will restrict itself to crates that are
167           downloaded locally, even if there might be a newer version as
168           indicated in the local copy of the index. See the cargo-fetch(1)
169           command to download dependencies before going offline.
170
171           May also be specified with the net.offline config value
172           <https://doc.rust-lang.org/cargo/reference/config.html>.
173
174   Common Options
175       +toolchain
176           If Cargo has been installed with rustup, and the first argument to
177           cargo begins with +, it will be interpreted as a rustup toolchain
178           name (such as +stable or +nightly). See the rustup documentation
179           <https://rust-lang.github.io/rustup/overrides.html> for more
180           information about how toolchain overrides work.
181
182       -h, --help
183           Prints help information.
184
185       -Z flag
186           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
187           details.
188
189   Miscellaneous Options
190       -j N, --jobs N
191           Number of parallel jobs to run. May also be specified with the
192           build.jobs config value
193           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
194           to the number of CPUs.
195

PROFILES

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

ENVIRONMENT

220       See the reference
221       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
222       for details on environment variables that Cargo reads.
223

EXIT STATUS

2250: Cargo succeeded.
226
227101: Cargo failed to complete.
228

EXAMPLES

230        1. Build the local package and run its main target (assuming only one
231           binary):
232
233               cargo run
234
235        2. Run an example with extra arguments:
236
237               cargo run --example exname -- --exoption exarg1 exarg2
238

SEE ALSO

240       cargo(1), cargo-build(1)
241
242
243
244                                                                  CARGO-RUN(1)
Impressum