CARGO-RUN(1)
β¨ NAME β¨
okay so bestie, welcome to cargo-run(1) β the manual for cargo run, and it's literally the command that runs your current package. The official one-liner is giving main character energy:
cargo-run β Run the current package πββοΈπ¨
π οΈ SYNOPSIS π οΈ
The vibe is:
cargo run [options] [-- args]
π DESCRIPTION π
Run a binary or example of the local package. Periodt. β¨
All the arguments following the two dashes (--) are passed to the binary to run. If youβre passing arguments to both Cargo and the binary, the ones after -- go to the binary, the ones before go to Cargo. iykyk π
Unlike 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. lowkey iconic behavior π¦
π OPTIONS π
okay bestie, here come the flags β every single one, no skips, fr fr. π
π¦ Package Selection π¦
By default, the package in the current working directory is selected. The -p flag can be used to choose a different package in a workspace. vibe check: workspace edition β¨
-p spec,--package specβ The package to run. Seecargo-pkgid(1)for theSPECformat. π
π― Target Selection π―
When no target selection options are given, cargo run will run the binary target. If there are multiple binary targets, you must pass a target flag to choose one. Or, the default-run field may be specified in the [package] section of Cargo.toml to choose the name of the binary to run by default. the way that Cargo needs you to pick a faveβ¦ π
--bin nameβ Run the specified binary. π₯--example nameβ Run the specified example. πΈ
β¨ Feature Selection β¨
The feature flags allow you to control which features are enabled. When no feature options are given, the default feature is activated for every selected package. no cap π«
See the features documentation (<https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>) for more details. π«Ά
-F features,--features featuresβ Space or comma separated list of features to activate. Features of workspace members may be enabled withpackage-name/feature-namesyntax. This flag may be specified multiple times, which enables all specified features. π--all-featuresβ Activate all available features of all selected packages. π--no-default-featuresβ Do not activate the default feature of the selected packages. π
βοΈ Compilation Options βοΈ
--target tripleβ 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>). β¨
Note that specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. See the build cache (<https://doc.rust-lang.org/cargo/guide/build-cache.html>) documentation for more details. itβs giving separate directory energy π
-r,--releaseβ Run optimized artifacts with the release profile. See also the--profileoption for choosing a specific profile by name. π₯--profile nameβ Run with the given profile. See the reference (<https://doc.rust-lang.org/cargo/reference/profiles.html>) for more details on profiles. π--ignore-rust-versionβ Run the target even if the selected Rust compiler is older than the required Rust version as configured in the projectβsrust-versionfield. not me ignoring the version check π--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-dir directoryβ 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. defaults? we love a default. π
π 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>). very verbose is the group chat with receipts π-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>). π€«--color whenβ 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-format fmtβ 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-path pathβ Path to theCargo.tomlfile. By default, Cargo searches for theCargo.tomlfile in the current directory or any parent directory. π--frozen,--lockedβ Either of these flags requires that theCargo.lockfile is up-to-date. If the lock file is missing, or it needs to be updated, Cargo will exit with an error. The--frozenflag also prevents Cargo from attempting to access the network to determine if it is out-of-date. bestie, this one is serious β lock file must be locked in. π
These may be used in environments where you want to assert that the Cargo.lock file is up-to-date (such as a CI build) or want to avoid network access. π
--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 that 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. warning: offline mode is not the same as online mode, no cap π
May also be specified with the net.offline config value (<https://doc.rust-lang.org/cargo/reference/config.html>). π
π§° 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. π--config KEY=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. π-C PATHβ 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. π«Ά-Z flagβ Unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor details. π
π² Miscellaneous Options π²
-j N,--jobs Nβ 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 be 0. do not set it to 0, bestie, thatβs not the vibe. β οΈ--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. π₯
π ENVIRONMENT π
See the reference (<https://doc.rust-lang.org/cargo/reference/environment-variables.html>) for details on environment variables that Cargo reads. π±
πͺ EXIT STATUS π
So like, how do you know if it ate or if it flopped? Cargo tells you with numbers, bestie:
0β Cargo succeeded. π Everything worked, the binary ran, you're the main character, go take a selfie.101β Cargo failed to complete. π Something went sideways, the vibe check was failed, it's giving error.
π§ͺ EXAMPLES β¨ (yes, real ones, go try them fr fr)
- Build the local package and run its main target (assuming only one binary):
cargo run
That's it. That's the whole thing. One command, zero drama, so clean. π«Ά
- Run an example with extra arguments:
cargo run --example exname -- --exoption exarg1 exarg2
Look at that lil -- in the middle, okay?? That's the moment where Cargo stops listening and starts handing stuff straight to your program. Everything after it β --exoption exarg1 exarg2 β goes to your code, not to Cargo. The way that little dash-dash is doing the most important job in the whole lineβ¦ iconic. π
Do not forget the --. Fr fr. Without it, Cargo thinks those args are for it, and it will simply not know what you're talking about.
π SEE ALSO π¦
Your other besties in the Cargo friend group:
cargo(1)β the mothership, the whole vibe, start here if you're lost πcargo-build(1)β same energy ascargo runbut it just builds and dips, no running πΈ
And that's the page, bestie!! You made it all the way to the bottom, which is honestly so slay of you. This was the CARGO-RUN(1) page β that's literally what's chillin' down there in the footer, just the page name holding it down, no cap. Go run something. I believe in you. πβ¨
π¦ where this page comes from
- ubuntu jammy: cargo-1.78 1.78.0+dfsg1ubuntu1~bpo0-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.78 1.78.0+dfsg1ubuntu1-0ubuntu0.24.04.2 Β· 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