CARGO-RUN(1)
π CARGO-RUN π
okay bestie, welcome to the cargo-run(1) glow-up β¨ this is a General Commands Manual situation, and honestly? it's giving main character energy. let's get into it π«Ά
β¨ NAME β¨
cargo-run β run the current package πβοΈπ¨
β¨ SYNOPSIS β¨
cargo run [options] [-- args]
like, that's the whole vibe. short, iconic, no notes π
β¨ DESCRIPTION β¨
So what does it actually do, you ask? It runs a binary or an example of the local package. That's it. That's the whole thing. Lowkey obsessed with how simple that is πΈ
Now here's the part you gotta remember, bestie, because it trips people up constantly π β all the arguments that come after the two dashes (--) get passed straight to the binary that's being run. Periodt.
And if you're out here passing arguments to both Cargo and the binary? Okay so the rule is:
- the ones after
--go to the binary π - the ones before
--go to Cargo π
not me making this mistake every single time β write it down, fr fr π
One more thing, and this one is kinda iconic: unlike cargo-test(1) and cargo-bench(1), cargo run sets the working directory of the binary it executes to the current working directory. Which means it behaves the same as if you'd just executed it in the shell directly. Same vibe, no surprises, we love to see it β¨π¦
okay that's the vibe check for this part, but hold up β there's more coming π don't go anywhere π
β¨ OPTIONS β¨
π¦ Package Selection
okay so by default, cargo run grabs the package sitting in your current working directory. that's it, that's the vibe. but if you're in a workspace and wanna run a different one? that's what -p is for, bestie.
-pspec,--packagespec β the package you wanna run. for the whole SPEC format situation, go peek atcargo-pkgid(1).
π― Target Selection
when you don't pass any target selection flags, cargo run just runs the binary target. easy. BUT β if there are multiple binary targets, you have to pass a target flag to pick one. no flag, no run, them's the rules. π
orrrr you can set the default-run field in the [package] section of Cargo.toml to pick which binary runs by default. main character binary energy, honestly.
--binname β run the binary you named.--examplename β run the example you named.
πΈ Feature Selection
the feature flags are how you control which features get enabled. when you don't pass any feature options, the default feature gets activated for every selected package. automatic, no notes.
if you want the full tea on features, the features documentation is right here: 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. you can enable features of workspace members with thepackage-name/feature-namesyntax. and yes you can pass this flag multiple times β every feature you list gets enabled.--all-featuresβ activate every available feature of every selected package. go big or go home, fr fr.--no-default-featuresβ do not activate the default feature of the selected packages. choosing chaos, love that for you.
βοΈ Compilation Options
--targettriple β run for the given architecture. default is the host architecture. the general format of the triple is<arch><sub>-<vendor>-<sys>-<abi>. runrustc --print target-listto get a list of supported targets.
this can also be set with the build.target config value: https://doc.rust-lang.org/cargo/reference/config.html
heads up: passing this flag makes Cargo run in a different mode where the target artifacts go in a separate directory. the build cache docs have the deets: https://doc.rust-lang.org/cargo/guide/build-cache.html
-r,--releaseβ run optimized artifacts with the release profile. also peep the--profileoption if you wanna pick a specific profile by name.--profilename β run with the given profile. reference is over here:https://doc.rust-lang.org/cargo/reference/profiles.html--timings=fmtsβ outputs info about how long each compilation takes, and tracks concurrency info over time. accepts an optional comma-separated list of output formats.--timingswith no argument defaults to--timings=html. specifying an output format (instead of the default) is unstable and needs-Zunstable-options. valid output formats:html(unstable, requires-Zunstable-options): writes a human-readable filecargo-timing.htmlto thetarget/cargo-timingsdirectory with a report of the compilation. it also writes a report to the same directory with a timestamp in the filename, in case you wanna look at older runs. HTML output is for human consumption only and does not provide machine-readable timing data.json(unstable, requires-Zunstable-options): emits machine-readable JSON info about the timing information.
π Output Options
--target-dirdirectory β directory for all generated artifacts and intermediate files. can also be set 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. you can pass it twice for "very verbose" output, which throws in extra stuff like dependency warnings and build script output. can also be set with theterm.verboseconfig value:https://doc.rust-lang.org/cargo/reference/config.html-q,--quietβ do not print cargo log messages. can also be set with theterm.quietconfig value:https://doc.rust-lang.org/cargo/reference/config.html--colorwhen β control when colored output is used. valid values:auto(default): automatically detects if color support is available on the terminal.always: always display colors. πnever: never display colors.
can also be set 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 is made 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. reference right here:https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages. 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, so it respects rustc's default color scheme. cannot be used withhumanorshort.json-render-diagnostics: tells Cargo to not include rustc diagnostics in the printed JSON messages, and instead have Cargo itself 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β ignore therust-versionspecification in packages. pretend you didn't see it.--lockedβ asserts that the exact same dependencies and versions are used as when the existingCargo.lockfile was originally generated. Cargo exits with an error when either of these situations comes up:- the lock file is missing.
- Cargo attempted to change the lock file due to a different dependency resolution.
this one's for environments where you want deterministic builds, like CI pipelines. locked in, literally.
--offlineβ prevents Cargo from accessing the network for any reason. without this flag, Cargo stops with an error if it needs the network and the network isn't available. with this flag, Cargo attempts to proceed without the network if it can.
beware bestie: this may result in different dependency resolution than online mode. Cargo restricts itself to crates that are downloaded locally, even if there might be a newer version as indicated in the local copy of the index. peep cargo-fetch(1) to download dependencies before going offline.
can also be set 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 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 #14421https://github.com/rust-lang/cargo/issues/14421).
π§ Common Options
+toolchain β if Cargo was installed with rustup, and the first argument tocargobegins with+, it gets interpreted as a rustup toolchain name (like+stableor+nightly). rustup docs for more:https://rust-lang.github.io/rustup/overrides.html--configKEY=VALUE or PATH β overrides a Cargo configuration value. the argument should be in TOML syntax ofKEY=VALUE, or given as a path to an extra configuration file. this flag can be specified multiple times. command-line overrides section:https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides-CPATH β changes the current working directory before executing any specified operations. this affects stuff like where cargo looks by default for the project manifest (Cargo.toml), and the directories searched for discovering.cargo/config.toml, for example. this option must appear before the command name, likecargo -C path/to/my-project build.
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 #10098https://github.com/rust-lang/cargo/issues/10098).
-h,--helpβ prints help information. π«Ά-Zflag β unstable (nightly-only) flags to Cargo. runcargo -Z helpfor the details.
π Miscellaneous Options
-jN,--jobsN β number of parallel jobs to run. can also be set 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 the provided value. if a stringdefaultis provided, it sets the value back to defaults. should not be0. not zero, babe. π--keep-goingβ build as many crates in the dependency graph as possible, instead of aborting the build on the first one that fails.
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. so you get the receipts either way. π
π ENVIRONMENT π
okay so Cargo does read environment variables, bestie, and it reads a lot of them π if you wanna know every single one, the official reference is right here:
https://doc.rust-lang.org/cargo/reference/environment-variables.html
that page has all the deets on the environment variables that Cargo reads. go peek, it's giving β¨documentationβ¨ π¦
π EXIT STATUS π
Cargo keeps it super simple on the way out, no cap:
0β Cargo succeeded. slay. she ate. π101β Cargo failed to complete. π not the vibe, but at least you know fr fr
π EXAMPLES π
- Build the local package and run its main target (this is assuming there's only one binary, iykyk):
cargo run
- Run an example with extra arguments β note the
--doing its lil separator thing, it's iconic:
cargo run --example exname -- --exoption exarg1 exarg2
π SEE ALSO π
and that's the whole page, bestie π«Ά this was CARGO-RUN(1) from the Cargo manual, dated the day the manpage fairy dropped it, version whatever's in your cargo --version πΈ go forth and cargo run your little heart out πβ¨
π¦ where this page comes from
- ubuntu jammy: cargo-1.82 1.82.0+dfsg0ubuntu0~jammy-0ubuntu0.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.82 1.82.0+dfsg0ubuntu0-0ubuntu0.24.04.1 Β· Apache-2.0 WITH LLVM exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms