1CARGO-RUN(1) General Commands Manual CARGO-RUN(1)
2
3
4
6 cargo-run - Run the current package
7
9 cargo run [options] [-- args]
10
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
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 -F features, --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 -r, --release
78 Run optimized artifacts with the release profile. See also the
79 --profile option for choosing a specific profile by name.
80
81 --profile name
82 Run with the given profile. See the the reference
83 <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
84 details on profiles.
85
86 --ignore-rust-version
87 Run the target even if the selected Rust compiler is older than the
88 required Rust version as configured in the project's rust-version
89 field.
90
91 --timings=fmts
92 Output information how long each compilation takes, and track
93 concurrency information over time. Accepts an optional
94 comma-separated list of output formats; --timings without an
95 argument will default to --timings=html. Specifying an output
96 format (rather than the default) is unstable and requires
97 -Zunstable-options. Valid output formats:
98
99 • html: Write a human-readable file cargo-timing.html to the
100 target/cargo-timings directory with a report of the
101 compilation. Also write a report to the same directory with a
102 timestamp in the filename if you want to look at older runs.
103 HTML output is suitable for human consumption only, and does
104 not provide machine-readable timing data.
105
106 • json (unstable, requires -Zunstable-options): Emit
107 machine-readable JSON information about timing information.
108
109 Output Options
110 --target-dir directory
111 Directory for all generated artifacts and intermediate files. May
112 also be specified with the CARGO_TARGET_DIR environment variable,
113 or the build.target-dir config value
114 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
115 to target in the root of the workspace.
116
117 Display Options
118 -v, --verbose
119 Use verbose output. May be specified twice for "very verbose"
120 output which includes extra output such as dependency warnings and
121 build script output. May also be specified with the term.verbose
122 config value
123 <https://doc.rust-lang.org/cargo/reference/config.html>.
124
125 -q, --quiet
126 Do not print cargo log messages. May also be specified with the
127 term.quiet config value
128 <https://doc.rust-lang.org/cargo/reference/config.html>.
129
130 --color when
131 Control when colored output is used. Valid values:
132
133 • auto (default): Automatically detect if color support is
134 available on the terminal.
135
136 • always: Always display colors.
137
138 • never: Never display colors.
139
140 May also be specified with the term.color config value
141 <https://doc.rust-lang.org/cargo/reference/config.html>.
142
143 --message-format fmt
144 The output format for diagnostic messages. Can be specified
145 multiple times and consists of comma-separated values. Valid
146 values:
147
148 • human (default): Display in a human-readable text format.
149 Conflicts with short and json.
150
151 • short: Emit shorter, human-readable text messages. Conflicts
152 with human and json.
153
154 • json: Emit JSON messages to stdout. See the reference
155 <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
156 for more details. Conflicts with human and short.
157
158 • json-diagnostic-short: Ensure the rendered field of JSON
159 messages contains the "short" rendering from rustc. Cannot be
160 used with human or short.
161
162 • json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
163 messages contains embedded ANSI color codes for respecting
164 rustc's default color scheme. Cannot be used with human or
165 short.
166
167 • json-render-diagnostics: Instruct Cargo to not include rustc
168 diagnostics in in JSON messages printed, but instead Cargo
169 itself should render the JSON diagnostics coming from rustc.
170 Cargo's own JSON diagnostics and others coming from rustc are
171 still emitted. Cannot be used with human or short.
172
173 Manifest Options
174 --manifest-path path
175 Path to the Cargo.toml file. By default, Cargo searches for the
176 Cargo.toml file in the current directory or any parent directory.
177
178 --frozen, --locked
179 Either of these flags requires that the Cargo.lock file is
180 up-to-date. If the lock file is missing, or it needs to be updated,
181 Cargo will exit with an error. The --frozen flag also prevents
182 Cargo from attempting to access the network to determine if it is
183 out-of-date.
184
185 These may be used in environments where you want to assert that the
186 Cargo.lock file is up-to-date (such as a CI build) or want to avoid
187 network access.
188
189 --offline
190 Prevents Cargo from accessing the network for any reason. Without
191 this flag, Cargo will stop with an error if it needs to access the
192 network and the network is not available. With this flag, Cargo
193 will attempt to proceed without the network if possible.
194
195 Beware that this may result in different dependency resolution than
196 online mode. Cargo will restrict itself to crates that are
197 downloaded locally, even if there might be a newer version as
198 indicated in the local copy of the index. See the cargo-fetch(1)
199 command to download dependencies before going offline.
200
201 May also be specified with the net.offline config value
202 <https://doc.rust-lang.org/cargo/reference/config.html>.
203
204 Common Options
205 +toolchain
206 If Cargo has been installed with rustup, and the first argument to
207 cargo begins with +, it will be interpreted as a rustup toolchain
208 name (such as +stable or +nightly). See the rustup documentation
209 <https://rust-lang.github.io/rustup/overrides.html> for more
210 information about how toolchain overrides work.
211
212 -h, --help
213 Prints help information.
214
215 -Z flag
216 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
217 details.
218
219 Miscellaneous Options
220 -j N, --jobs N
221 Number of parallel jobs to run. May also be specified with the
222 build.jobs config value
223 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
224 to the number of CPUs.
225
226 --keep-going
227 Build as many crates in the dependency graph as possible, rather
228 than aborting the build on the first one that fails to build.
229 Unstable, requires -Zunstable-options.
230
232 See the reference
233 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
234 for details on environment variables that Cargo reads.
235
237 • 0: Cargo succeeded.
238
239 • 101: Cargo failed to complete.
240
242 1. Build the local package and run its main target (assuming only one
243 binary):
244
245 cargo run
246
247 2. Run an example with extra arguments:
248
249 cargo run --example exname -- --exoption exarg1 exarg2
250
252 cargo(1), cargo-build(1)
253
254
255
256 CARGO-RUN(1)