CARGO-RUN(1)
π CARGO-RUN(1) π
okay bestie, welcome to the manual page for cargo-run. itβs giving βrun the current packageβ energy, and weβre about to get into it. π«Ά
β¨ NAME β¨
cargo-run β Run the current package. no cap, thatβs the whole name. π
β¨ SYNOPSIS β¨
cargo run [options] [-- args]
πΈ DESCRIPTION πΈ
cargo run runs a binary or an example of the local package. literally the main character of βjust let me run this thingβ commands. πββοΈπ¨
all the arguments following the two dashes (--) are passed to the binary to run. so 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. π
and hereβs the lilβ difference from cargo-test(1) and cargo-bench(1): cargo run sets the working directory of the binary executed to the current working directory, same as if it was executed in the shell directly. itβs giving βran it myselfβ energy. β¨
β¨ OPTIONS β¨
π Package Selection
Okay so default vibe: Cargo picks the package sitting in your current working directory. That's the starting point, bestie. Want a different one? Use the -p flag to pick a different package inside a workspace. That's it, that's the whole thing.
-pspec,--packagespec β the package you wanna run. Peepcargo-pkgid(1)for theSPECformat, iykyk. π
π¦ Target Selection
When you don't hand Cargo any target selection options, cargo run runs the binary target. Now here's the tea: if there's more than one binary target, you must pass a target flag to choose one. Or β plot twist β the default-run field can be specified in the [package] section of Cargo.toml to choose the name of the binary to run by default. Slay, honestly.
--binname β run the binary you named. π--examplename β run the example you named. β¨
πΈ Feature Selection
Feature flags let you control which features are enabled. When you give zero feature options, the default feature gets activated for every selected package. That's the default, periodt.
See the features documentation <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options> for more details, if you're feeling academic.
-Ffeatures,--featuresfeatures β a space or comma separated list of features to activate. Features of workspace members may be enabled withpackage-name/feature-namesyntax. And yes, this flag may be specified multiple times, which enables all specified features. Stack 'em up. π--all-featuresβ activate all available features of all selected packages. Everything. All of it. No crumbs.--no-default-featuresβ do not activate the default feature of the selected packages. We're going rogue.
π₯ Compilation Options
--targettriple β run for the given architecture. The default is the host architecture. The general format of the triple is<arch><sub>-<vendor>-<sys>-<abi>. Runrustc --print target-listfor a list of supported targets.
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 thereleaseprofile. See also the--profileoption for choosing a specific profile by name. Glow-up mode activated. π₯--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 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 thebuild.target-dirconfig value <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults totargetin the root of the workspace.
π Display Options
-v,--verboseβ use verbose output. May be specified twice for "very verbose" output which includes extra output such as dependency warnings and build script output. May also be specified with theterm.verboseconfig value <https://doc.rust-lang.org/cargo/reference/config.html>. Not me double-flagging for maximum yapping. π-q,--quietβ do not print cargo log messages. May also be specified with theterm.quietconfig value <https://doc.rust-lang.org/cargo/reference/config.html>. Shhh era. π€«--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 fromrustc. Cannot be used withhumanorshort.json-diagnostic-rendered-ansi: ensure therenderedfield of JSON messages contains embedded ANSI color codes for respectingrustc's default color scheme. Cannot be used withhumanorshort.json-render-diagnostics: instruct Cargo to not includerustcdiagnostics in JSON messages printed, but instead Cargo itself should render the JSON diagnostics coming fromrustc. Cargo's own JSON diagnostics and others coming fromrustcare 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. It's giving "it'll find you wherever you are." π₯°--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. Locked in, literally. π
--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 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, iconic.--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 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 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-options flag to enable (see #14421 <https://github.com/rust-lang/cargo/issues/14421>). Nightly girlies only. π
β 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 ofKEY=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.
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-options flag to enable (see #10098 <https://github.com/rust-lang/cargo/issues/10098>).
-h,--helpβ prints help information. The classic. π«Ά-Zflag β unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor details.
π Miscellaneous Options
-jN,--jobsN β number of parallel jobs to run. May also be specified with thebuild.jobsconfig value <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to the number of logical CPUs. If negative, it sets the maximum number of parallel jobs to the number of logical CPUs plus provided value. If a stringdefaultis provided, it sets the value back to defaults. Should not be0. (Like, genuinely. Don't.)--keep-goingβ build as many crates in the dependency graph as possible, rather than aborting the build on the first one that fails to build.
For example if the current package depends on dependencies fails and works, one of which fails to build, cargo run -j1 may or may not build the one that succeeds (depending on which one of the two builds Cargo picked to run first), whereas cargo run -j1 --keep-going would definitely run both builds, even if the one run first fails.
The way that --keep-going refuses to give up on your crates? Main character energy, fr fr. π
πΏ ENVIRONMENT
Cargo reads a whole bunch of environment variables, bestie, and there's a whole reference page for them at <https://doc.rust-lang.org/cargo/reference/environment-variables.html> β go read it, it's giving documentation.
πͺ EXIT STATUS
0β Cargo succeeded. She ate. π101β Cargo failed to complete. Not the vibe. π
β¨ EXAMPLES β¨
- Build the local package and run its main target (this assumes there's only one binary, so Cargo knows who the main character is):
cargo run
- Run an example with extra arguments β and yes, you need that
--in there, it's the little velvet rope between Cargo's args and your program's args:
cargo run --example exname -- --exoption exarg1 exarg2
π SEE ALSO
And that's a wrap on the whole cargo-run(1) page, bestie β this is the man page as it shipped, with its version and date stamped on it like a little timestamp on a group chat message. Go run some code. π¦β¨
π¦ where this page comes from
- ubuntu jammy: cargo-1.85 1.85.1+dfsg0ubuntu2~bpo0-0ubuntu1.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.85 1.85.1+dfsg0ubuntu2~bpo0-0ubuntu0.24.04.2 Β· Apache-2.0 WITH LLVM exception
- ubuntu questing: cargo-1.85 1.85.1+dfsg0ubuntu2-0ubuntu1
- ubuntu questing: cargo-1.85 1.85.1+dfsg0ubuntu2-0ubuntu1.25.04.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms