CARGO-RUN(1)
π cargo-run β Run the current package
okay bestie, welcome to the manual page for cargo-run (that's CARGO-RUN(1) if you're being formal, which we are not π ). She's a general commands manual page and she is iconic. Let's get into it.
β¨ NAME β¨
cargo-run β Run the current package πβοΈπ¨
πΈ SYNOPSIS πΈ
cargo run [options] [-- args]
π¦ DESCRIPTION π¦
Runs a binary or an example from your local package. That's the whole vibe. π
Every single argument that comes after the two dashes (--) gets handed off to the binary you're running. And here's the thing, bestie, because this trips everyone up: if you're passing arguments to both Cargo and the binary, the ones after -- go to the binary, and the ones before -- go to Cargo. Periodt.
Unlike cargo-test(1) and cargo-bench(1), cargo run sets the working directory of the binary it executes to the current working directory β same as if you'd run it in the shell directly. No sneaky directory changes. Slay. β¨
π OPTIONS π
π¦ Package Selection
By default, it's the package sitting in your current working directory that gets selected. But if you want a different package in a workspace, the -p flag is your girl.
-pspec,--packagespec β The package to run. Peepcargo-pkgid(1)for the SPEC format. π
π― Target Selection
When you don't pass any target selection options, cargo run will run the binary target. If there are multiple binary targets, you must pass a target flag to pick one. OR β and this is lowkey the move β the default-run field can be specified in the [package] section of Cargo.toml to choose the name of the binary that runs by default. π
--binname β Run the specified binary. π--examplename β Run the specified example. π
π Feature Selection
Feature flags let you control which features get enabled. When you don't give any feature options, the default feature is activated for every selected package.
See the features documentation <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options> for more deets.
-Ffeatures,--featuresfeatures β A space- or comma-separated list of features to activate. Features of workspace members can be enabled with thepackage-name/feature-namesyntax. This flag can be specified multiple times, and doing so enables all the specified features. π«Ά--all-featuresβ Activate all available features of all selected packages. Go big or go home.--no-default-featuresβ Do not activate the default feature of the selected packages. π
π¨ Compilation Options
--targettriple β Run for the specified target architecture. The default is the host architecture. The general format of the triple is<arch><sub>-<vendor>-<sys>-<abi>.
Possible values:
- Any supported target in
rustc --print target-list. "host-tuple", which will internally be substituted by the host's target. This can be particularly useful if you're cross-compiling some crates and don't want to specify your host's machine as a target (for instance, an xtask in a shared project that may be worked on by many hosts). π―- A path to a custom target specification. See Custom Target Lookup Path
<https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-path>for more information.
This may also be specified with the build.target config value <https://doc.rust-lang.org/cargo/reference/config.html>.
Heads up bestie: specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. See the build cache documentation <https://doc.rust-lang.org/cargo/reference/build-cache.html> for more details. π
-r,--releaseβ Run optimized artifacts with the release profile. Also peep the--profileoption if you wanna choose a specific profile by name. π₯--profilename β Run with the given profile. See the reference<https://doc.rust-lang.org/cargo/reference/profiles.html>for more details on profiles.--timings=fmts β Output information about how long each compilation takes, and track concurrency information over time. Accepts an optional comma-separated list of output formats;--timingswithout an argument will default to--timings=html. Specifying an output format (rather than the default) is unstable and requires-Zunstable-options. Valid output formats:html(unstable, requires-Zunstable-options): Write a human-readable filecargo-timing.htmlto thetarget/cargo-timingsdirectory with a report of the compilation. Also write a report to the same directory with a timestamp in the filename if you want to look at older runs. HTML output is suitable for human consumption only, and does not provide machine-readable timing data.json(unstable, requires-Zunstable-options): Emit machine-readable JSON information about timing information. π€
π Output Options
--target-dirdirectory β Directory for all generated artifacts and intermediate files. May also be specified with theCARGO_TARGET_DIRenvironment variable, or the build.target-dir config value<https://doc.rust-lang.org/cargo/reference/config.html>. Defaults totargetin the root of the workspace. ποΈ
π£οΈ Display Options
-v,--verboseβ Use verbose output. Can be specified twice for "very verbose" output, which includes extra output such as dependency warnings and build script output. May also be specified with the term.verbose config value<https://doc.rust-lang.org/cargo/reference/config.html>. π£οΈπ£οΈ-q,--quietβ Do not print cargo log messages. May also be specified with the term.quiet config value<https://doc.rust-lang.org/cargo/reference/config.html>. π€«--colorwhen β Control when colored output is used. Valid values:auto(default): Automatically detect if color support is available on the terminal. π¨always: Always display colors. πnever: Never display colors. π«
May also be specified with the term.color config value <https://doc.rust-lang.org/cargo/reference/config.html>.
--message-formatfmt β The output format for diagnostic messages. Can be specified multiple times and consists of comma-separated values. Valid values:human(default): Display in a human-readable text format. Conflicts withshortandjson.short: Emit shorter, human-readable text messages. Conflicts withhumanandjson.json: Emit JSON messages to stdout. See the reference<https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>for more details. Conflicts withhumanandshort.json-diagnostic-short: Ensure therenderedfield of JSON messages contains the "short" rendering from rustc. Cannot be used withhumanorshort.json-diagnostic-rendered-ansi: Ensure therenderedfield of JSON messages contains embedded ANSI color codes for respecting rustc's default color scheme. Cannot be used withhumanorshort.json-render-diagnostics: Instruct Cargo to not include rustc diagnostics in JSON messages printed, but instead Cargo itself should render the JSON diagnostics coming from rustc. Cargo's own JSON diagnostics and others coming from rustc are still emitted. Cannot be used withhumanorshort.
π Manifest Options
--manifest-pathpath β Path to theCargo.tomlfile. By default, Cargo searches for theCargo.tomlfile in the current directory or any parent directory. π--ignore-rust-versionβ Ignorerust-versionspecification in packages. π--lockedβ Asserts that the exact same dependencies and versions are used as when the existingCargo.lockfile was originally generated. Cargo will exit with an error when either of the following scenarios arises:- The lock file is missing.
- Cargo attempted to change the lock file due to a different dependency resolution.
It may be used in environments where deterministic builds are desired, such as in CI pipelines. ποΈ
--offlineβ Prevents Cargo from accessing the network for any reason. Without this flag, Cargo will stop with an error if it needs to access the network and the network is not available. With this flag, Cargo will attempt to proceed without the network if possible.
Beware bestie π this may result in a different dependency resolution than online mode. Cargo will restrict itself to crates that are downloaded locally, even if there might be a newer version as indicated in the local copy of the index. See the cargo-fetch(1) command to download dependencies before going offline.
May also be specified with the net.offline config value <https://doc.rust-lang.org/cargo/reference/config.html>.
--frozenβ Equivalent to specifying both--lockedand--offline. Two for one, we love a bundle. π§--lockfile-pathPATH β Changes the path of the lockfile from the default (<workspace_root>/Cargo.lock) to PATH. PATH must end withCargo.lock(e.g.--lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that providing--lockfile-pathwill ignore the existing lockfile at the default path, and instead will either use the lockfile from PATH, or write a new lockfile into the provided PATH if it doesn't exist. This flag can be used to run most commands in read-only directories, writing the lockfile into the provided PATH.
This option is only available on the nightly channel<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html>and requires the-Z unstable-optionsflag to enable (see #14421<https://github.com/rust-lang/cargo/issues/14421>). β¨
π Common Options
+toolchain β If Cargo has been installed with rustup, and the first argument tocargobegins with+, it will be interpreted as a rustup toolchain name (such as+stableor+nightly). See the rustup documentation<https://rust-lang.github.io/rustup/overrides.html>for more information about how toolchain overrides work. π§--configKEY=VALUE or PATH β Overrides a Cargo configuration value. The argument should be in TOML syntax of KEY=VALUE, or provided as a path to an extra configuration file. This flag may be specified multiple times. See the command-line overrides section<https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>for more information. βοΈ-CPATH β Changes the current working directory before executing any specified operations. This affects things like where cargo looks by default for the project manifest (Cargo.toml), as well as the directories searched for discovering.cargo/config.toml, for example. This option must appear before the command name, for examplecargo -C path/to/my-project build. π
and that's part one, bestie β there's more coming, so don't go anywhere π«Ά
This one's only on the nightly channel <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> bestie, and it needs the -Z unstable-options flag switched on to even show up (peep #10098 <https://github.com/rust-lang/cargo/issues/10098> if you wanna read the lore π).
-h,--helpβ prints help information. That's it, that's the whole job π-Zflag β the unstable, nightly-only flags for Cargo. Runcargo -Z helpif you wanna see the whole menu of them β¨
π Miscellaneous Options π
-jN,--jobsN β how many parallel jobs you wanna run. You can also set this with thebuild.jobsconfig value <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to the number of logical CPUs. If you give it a negative number, it sets the max number of parallel jobs to the number of logical CPUs plus the value you gave. If you hand it a string default, it sets the value back to the defaults. And babes β it should not be0. Not ever. π«Ά--keep-goingβ build as many crates in the dependency graph as you possibly can, instead of straight up aborting the whole build the second one of them fails to build. It's giving resilience, it's giving perseverance π€
So like, picture this: your current package depends on some dependencies β some of them fail, some of them work β and one of them fails to build. With cargo run -j1, Cargo may or may not build the one that succeeds (it all depends on which of the two builds Cargo decided to run first π), whereas cargo run -j1 --keep-going would definitely run both builds, even if the one it ran first fails. No cap.
π ENVIRONMENT π
Cargo reads some environment variables, and the whole rundown lives in the reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html>. Go peek for the details, bestie π
πͺ EXIT STATUS πͺ
0: Cargo succeeded. Slay. π101: Cargo failed to complete. Not slay. π
πΈ EXAMPLES πΈ
- Build the local package and run its main target (this is assuming there's only one binary, okay?):
cargo run
- Run an example with extra arguments:
cargo run --example exname -- --exoption exarg1 exarg2
π SEE ALSO π
And that's the whole page, bestie β you made it to the end, main character behaviour fr fr ππ This lil masterpiece comes to you from the CARGO-RUN(1) manual page, so go forth and cargo run something iconic. Periodt. β¨π
π¦ where this page comes from
- ubuntu jammy: cargo-1.91 1.91.1+dfsg~22.04-0ubuntu0.22.04.3 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.91 1.91.1+dfsg~24.04-0ubuntu0.24.04.2 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.91 1.91.1+dfsg~24.04-0ubuntu0.24.04.3 Β· Apache-2.0 WITH LLVM exception
- ubuntu questing: cargo-1.91 1.91.1+dfsg-0ubuntu3~25.10.1
- ubuntu resolute: cargo-1.91 1.91.1+dfsg-0ubuntu3 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms