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 --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
103 · auto (default): Automatically detect if color support is
104 available on the terminal.
105
106 · always: Always display colors.
107
108 · never: 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
118 · human (default): Display in a human-readable text format.
119
120 · short: Emit shorter, human-readable text messages.
121
122 · json: Emit JSON messages to stdout. See the reference
123 <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
124 for more details.
125
126 · json-diagnostic-short: Ensure the rendered field of JSON
127 messages contains the "short" rendering from rustc.
128
129 · json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
130 messages contains embedded ANSI color codes for respecting
131 rustc's default color scheme.
132
133 · json-render-diagnostics: Instruct Cargo to not include rustc
134 diagnostics in in JSON messages printed, but instead Cargo
135 itself should render the JSON diagnostics coming from rustc.
136 Cargo's own JSON diagnostics and others coming from rustc are
137 still emitted.
138
139 Manifest Options
140 --manifest-path path
141 Path to the Cargo.toml file. By default, Cargo searches for the
142 Cargo.toml file in the current directory or any parent directory.
143
144 --frozen, --locked
145 Either of these flags requires that the Cargo.lock file is
146 up-to-date. If the lock file is missing, or it needs to be updated,
147 Cargo will exit with an error. The --frozen flag also prevents
148 Cargo from attempting to access the network to determine if it is
149 out-of-date.
150
151 These may be used in environments where you want to assert that the
152 Cargo.lock file is up-to-date (such as a CI build) or want to avoid
153 network access.
154
155 --offline
156 Prevents Cargo from accessing the network for any reason. Without
157 this flag, Cargo will stop with an error if it needs to access the
158 network and the network is not available. With this flag, Cargo
159 will attempt to proceed without the network if possible.
160
161 Beware that this may result in different dependency resolution than
162 online mode. Cargo will restrict itself to crates that are
163 downloaded locally, even if there might be a newer version as
164 indicated in the local copy of the index. See the cargo-fetch(1)
165 command to download dependencies before going offline.
166
167 May also be specified with the net.offline config value
168 <https://doc.rust-lang.org/cargo/reference/config.html>.
169
170 Common Options
171 +toolchain
172 If Cargo has been installed with rustup, and the first argument to
173 cargo begins with +, it will be interpreted as a rustup toolchain
174 name (such as +stable or +nightly). See the rustup documentation
175 <https://rust-lang.github.io/rustup/overrides.html> for more
176 information about how toolchain overrides work.
177
178 -h, --help
179 Prints help information.
180
181 -Z flag
182 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
183 details.
184
185 Miscellaneous Options
186 -j N, --jobs N
187 Number of parallel jobs to run. May also be specified with the
188 build.jobs config value
189 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
190 to the number of CPUs.
191
193 Profiles may be used to configure compiler options such as optimization
194 levels and debug settings. See the reference
195 <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
196 details.
197
198 Profile selection depends on the target and crate being built. By
199 default the dev or test profiles are used. If the --release flag is
200 given, then the release or bench profiles are used.
201
202
203 ┌────────────────────┬─────────────────┬───────────────────┐
204 │Target │ Default Profile │ --release Profile │
205 ├────────────────────┼─────────────────┼───────────────────┤
206 │lib, bin, example │ dev │ release │
207 ├────────────────────┼─────────────────┼───────────────────┤
208 │test, bench, or any │ test │ bench │
209 │target in "test" or │ │ │
210 │"bench" mode │ │ │
211 └────────────────────┴─────────────────┴───────────────────┘
212
213 Dependencies use the dev/release profiles.
214
216 See the reference
217 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
218 for details on environment variables that Cargo reads.
219
221 · 0: Cargo succeeded.
222
223 · 101: Cargo failed to complete.
224
226 1. Build the local package and run its main target (assuming only one
227 binary):
228
229 cargo run
230
231 2. Run an example with extra arguments:
232
233 cargo run --example exname -- --exoption exarg1 exarg2
234
236 cargo(1), cargo-build(1)
237
238
239
240 CARGO-RUN(1)