CARGO-RUN(1)
hey bestie π welcome to cargo-run(1) β the manual page for the one command you're gonna type like eight hundred times a day. buckle up, we're going through every single flag, no skips, no skimming, periodt.
π NAME π
cargo-run β run the current package β¨
π¦ SYNOPSIS π¦
cargo run [options] [-- args]
πΈ DESCRIPTION πΈ
Runs a binary or an example from the local package. that's the whole vibe. main character energy for real.
Every argument that comes after the two dashes (--) gets handed straight to the binary you're running. and if you're passing args 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 it executes to the current working directory β same as if you'd just run it in the shell directly. no sneaky directory switching, we respect your cwd π
β¨ OPTIONS β¨
π¦ Package Selection
By default, the package in the current working directory is the one that gets selected. but if you want a different package in a workspace, the -p flag is right there bestie.
-pspec,--packagespec β the package to run. seecargo-pkgid(1)for the SPEC format.
π― Target Selection
When you don't give any target selection options, cargo run will run the binary target. if there are multiple binary targets, you must pass a target flag to choose one. alternatively, 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. iconic β¨
--binname β run the specified binary.--examplename β run the specified example.
π Feature Selection
The feature flags are how you control which features get enabled. when no feature options are given, the default feature is activated for every selected package.
More deets live in the features documentation at https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options.
-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 may be specified multiple times, which enables all the specified features. stack them like bracelets π--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 at
https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-pathfor more information.
This may also be specified with the build.target config value at 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 docs at https://doc.rust-lang.org/cargo/reference/build-cache.html for more details.
-r,--releaseβ run optimized artifacts with the release profile. see also the--profileoption for choosing a specific profile by name.--profilename β run with the given profile. see the reference athttps://doc.rust-lang.org/cargo/reference/profiles.htmlfor more details on profiles.--timingsβ output information about how long each compilation takes, and track concurrency information over time.
A file cargo-timing.html will be written to the target/cargo-timings directory at the end of the build. an additional report with a timestamp in its filename is also written if you want to look at a previous run. these reports are suitable for human consumption only, and do not provide machine-readable timing data. look at it with your eyeballs, not your parser π
π 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 athttps://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 athttps://doc.rust-lang.org/cargo/reference/config.html.-q,--quietβ do not print cargo log messages. may also be specified with theterm.quietconfig value athttps://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 at 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 athttps://doc.rust-lang.org/cargo/reference/external-tools.html#json-messagesfor 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. CI besties, this one's for you π«Ά
--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 β οΈ 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 at https://doc.rust-lang.org/cargo/reference/config.html.
--frozenβ equivalent to specifying both--lockedand--offline. two-for-one deal, slay π
π§ 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 athttps://rust-lang.github.io/rustup/overrides.htmlfor more information about how toolchain overrides work.--config KEY=VALUEorPATHβ 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 athttps://doc.rust-lang.org/cargo/reference/config.html#command-line-overridesfor 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 athttps://doc.rust-lang.org/book/appendix-07-nightly-rust.htmland requires the-Z unstable-optionsflag to enable (see #10098 athttps://github.com/rust-lang/cargo/issues/10098). nightly-only, bestie, don't try this on stable π
-h,--helpβ prints help information.-Zflag β 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 athttps://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 the provided value. if a stringdefaultis provided, it sets the value back to defaults. should not be 0. like, seriously, 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. resilience era πͺ
πΈ ENVIRONMENT πΈ
ok so Cargo reads environment variables, and if you wanna know exactly which ones and what they do, bestie, the receipts are all here:
<https://doc.rust-lang.org/cargo/reference/environment-variables.html>
that's the official reference, go read it, it's giving thorough π
β¨ EXIT STATUS β¨
Cargo keeps it super simple, only two moods:
0β Cargo succeeded. slay, we ate, everything worked π101β Cargo failed to complete. not the vibe, something went wrong π
π¦ EXAMPLES π¦
okay real talk, here's how you actually use this thing:
- build the local package and run its main target β this assumes there's only one binary, iykyk:
cargo run
- run an example, and pass it some extra args while you're at it β note the
--bestie, that's the little wall between Cargo's args and your program's args, do not forget it or it's over:
cargo run --example exname -- --exoption exarg1 exarg2
like, see how --example exname is for Cargo and everything after the -- goes straight to your example? that's the whole trick π
π SEE ALSO π
ok that's the whole page, you're officially a cargo run girly now, no cap π this was CARGO-RUN(1) from the Cargo manual, mwah, go build something cute π«Άβ¨
π¦ where this page comes from
- alpine 3.24: cargo-doc 1.96.1-r0 Β· Apache-2.0 OR MIT
- alpine 3.24: chromium-cargo-doc 1.97.0-r0 Β· Apache-2.0 OR MIT
- centos-stream 10: cargo 1.99.1-1.el10 Β· (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- centos-stream 9: cargo 1.99.1-1.el9 Β· (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- debian bookworm: cargo-web 1.96.0+dfsg1-1~deb12u2 Β· MIT OR Apache-2.0
- debian trixie: cargo-web 1.96.0+dfsg1-1~deb13u1+b1 Β· MIT OR Apache-2.0
- fedora 43: cargo 1.98.1-1.fc43
- fedora 43: cargo 1.99.0-1.fc43
- fedora 43: cargo 1.99.1-2.fc43 Β· (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- fedora 44: cargo 1.94.1-1.fc44 Β· (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- fedora 44: cargo 1.98.1-1.fc44
- fedora 44: cargo 1.99.0-1.fc44
- fedora 44: cargo 1.99.1-2.fc44 Β· (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-3.0)
- nixos 26.05: cargo 1.95.0
- opensuse-leap 16.0: cargo1.94 1.94.1-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.94 1.94.1-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.94 1.94.1-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.94 1.94.1-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.95 1.95.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.95 1.95.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.95 1.95.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.95 1.95.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.96 1.96.1-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.96 1.96.1-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.96 1.96.1-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.96 1.96.1-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.97 1.97.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.97 1.97.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.97 1.97.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.97 1.97.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.98 1.98.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.98 1.98.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.98 1.98.0-160000.1.1 Β· Apache-2.0 OR MIT
- opensuse-leap 16.0: cargo1.98 1.98.0-160000.1.1 Β· Apache-2.0 OR MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms