CARGO-BUILD(1)
๐ CARGO-BUILD โ the manual page, but make it make sense
okay bestie, so this is the page for cargo-build, straight out of the General Commands Manual (yes, section 1, the cool section). It's long, so buckle up โ part 1 starts now and there's more coming after this. ๐
โจ NAME โจ
cargo-build โ Compile the current package ๐ฆ
๐ธ SYNOPSIS ๐ธ
cargo build [options]
that's it. that's the whole vibe. ๐ซถ
๐ DESCRIPTION ๐
Compile local packages and all of their dependencies. no cap, that's literally the whole job. ๐
๐ OPTIONS ๐
๐ Package Selection
okay so here's the tea on how Cargo decides which packages it's even gonna look at when you don't say anything: by default, with no package selection options given, the packages selected depend on the selected manifest file โ and that manifest is picked based on the current working directory, unless you passed --manifest-path. ๐ง
If that manifest is the root of a workspace, then the workspace's default members get selected. Otherwise? Only the single package defined by that manifest. That's it, that's the rule. โจ
You can set a workspace's default members explicitly with the workspace.default-members key in the root manifest. And if you don't set it:
- a virtual workspace will include all workspace members (equivalent to passing
--workspace) ๐ - a non-virtual workspace will include only the root crate itself ๐
-pspecโฆ,--packagespecโฆ โ Build only the specified packages. Wanna know what the SPEC format looks like? Peepcargo-pkgid(1). This flag may be specified multiple times and supports common Unix glob patterns like*,?and[]. BUT โ and this part matters โ to avoid your shell accidentally expanding those glob patterns before Cargo even gets to handle them, you must wrap each pattern in single quotes or double quotes. quoted, bestie. always. ๐--workspaceโ Build all members in the workspace. everybody's invited. ๐--allโ Deprecated alias for--workspace. it's giving legacy. use the new one. ๐--exclude*SPEC*โฆ โ Exclude the specified packages. Must be used in conjunction with the--workspaceflag. This flag may be specified multiple times and supports common Unix glob patterns like*,?and[]. However โ same deal as before โ to avoid your shell accidentally expanding glob patterns before Cargo handles them, you must use single quotes or double quotes around each pattern. ๐
๐ฆ Target Selection
When you don't give any target selection options, cargo build will build all binary and library targets of the selected packages. Binaries get skipped if they have required-features that are missing. sorry to that binary. ๐ญ
Binary targets are automatically built if there's an integration test or benchmark being selected to build โ this lets an integration test actually execute the binary so it can exercise and test its behavior. The CARGO_BIN_EXE_<name> environment variable (see https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates) is set when the integration test is built and run, so it can use the env macro (https://doc.rust-lang.org/std/macro.env.html) or the var function (https://doc.rust-lang.org/std/env/fn.var.html) to locate the executable. iconic behavior honestly. ๐
Passing target selection flags will build only the specified targets.
heads up bestie:--bin,--example,--testand--benchalso support common Unix glob patterns like*,?and[]. But to avoid your shell accidentally expanding glob patterns before Cargo handles them, you must use single quotes or double quotes around each glob pattern. ๐ซถ
--libโ Build the package's library. the classic. ๐--bin*name*โฆ โ Build the specified binary. This flag may be specified multiple times and supports common Unix glob patterns. โจ--binsโ Build all binary targets. all of them. every single one. ๐--example*name*โฆ โ Build the specified example. This flag may be specified multiple times and supports common Unix glob patterns. ๐--examplesโ Build all example targets. ๐ง--test*name*โฆ โ Build the specified integration test. This flag may be specified multiple times and supports common Unix glob patterns. ๐--testsโ Build all targets that have thetest = truemanifest flag set. By default this includes the library and binaries built as unittests, and integration tests. Be aware that this will also build any required dependencies, so the lib target may be built twice (once as a unittest, and once as a dependency for binaries, integration tests, etc.). Targets may be enabled or disabled by setting thetestflag in the manifest settings for the target. double duty, no complaints. ๐ญ--bench*name*โฆ โ Build the specified benchmark. This flag may be specified multiple times and supports common Unix glob patterns. โญ--benchesโ Build all targets that have thebench = truemanifest flag set. By default this includes the library and binaries built as benchmarks, and bench targets. Be aware that this will also build any required dependencies, so the lib target may be built twice (once as a benchmark, and once as a dependency for binaries, benchmarks, etc.). Targets may be enabled or disabled by setting thebenchflag in the manifest settings for the target. same energy as--tests, fr fr. ๐ฅ--all-targetsโ Build all targets. This is equivalent to specifying--lib --bins --tests --benches --examples. the "select all" button but for builds. ๐
๐ธ Feature Selection
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. โจ
See the features documentation at https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options for more details. iykyk. ๐
-Ffeatures,--featuresfeatures โ Space or comma separated list of features to activate. Features of workspace members may be enabled with thepackage-name/feature-namesyntax. 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. go big or go home. ๐--no-default-featuresโ Do not activate the default feature of the selected packages. sometimes you gotta opt out. ๐
๐ฅ Compilation Options
--targettriple โ Build for the specified target architecture. The flag may be specified multiple times. 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, anxtaskin 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 (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 documentation at https://doc.rust-lang.org/cargo/reference/build-cache.html for more details. things get relocated, it's fine, it's fine. ๐
-r,--releaseโ Build optimized artifacts with thereleaseprofile. See also the--profileoption for choosing a specific profile by name. optimized and thriving. ๐--profilename โ Build with the given profile. See the reference athttps://doc.rust-lang.org/cargo/reference/profiles.htmlfor more details on profiles. pick your fighter. ๐--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. sorry robots. ๐ค๐
๐ 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. ๐ธ--artifact-dirdirectory โ Copy final artifacts to this directory. ๐ฆ
This option is unstable and available only on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the-Z unstable-optionsflag to enable. Seehttps://github.com/rust-lang/cargo/issues/6790for more information. nightly girlies only, bestie. ๐
โญ 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). more words, more lore. ๐ฃ๏ธ-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. ๐คซ--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 tostdout. 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 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 have Cargo itself 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'll find it, don't worry. ๐--ignore-rust-versionโ Ignorerust-versionspecification in packages. living dangerously, respectfully. ๐--lockedโ bestie, this one is giving deterministic vibes only. It asserts that the exact same dependencies and versions are used as when the existingCargo.lockfile was originally generated. Cargo will literally exit with an error when either of these 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. So if you want your builds to be as predictable as your fave playlist, this is it. โจ
--offlineโ okay so this one is for when you wanna be unbothered by the network. It 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. So you can set it and forget it. ๐
--frozenโ it's giving two for one special. Equivalent to specifying both--lockedand--offline. Slay. โ๏ธ
๐ Common Options ๐
+toolchainโ if Cargo has been installed with rustup, and the first argument to cargo begins 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. So you can switch toolchains like you switch outfits. ๐--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. So you can be like, actually, I'll take it from here. ๐โโ๏ธ-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). So it's a little exclusive, you know? ๐
-h,--helpโ prints help information. Because sometimes you just need a little guidance, bestie. ๐-Z flagโ unstable (nightly-only) flags to Cargo. Runcargo -Z helpfor details. It's giving secret menu. ๐คซ
โจ 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 be0. So don't be a zero, okay? ๐--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. So it's like, we're not giving up, we're going to see this through. ๐ช
For example if the current package depends on dependencies fails and works, one of which fails to build, cargo build -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 build -j1 --keep-going would definitely run both builds, even if the one run first fails. So it's the never give up energy. โจ
--future-incompat-reportโ displays a future-incompat report for any future-incompatible warnings produced during execution of this command. Seecargo-report(1). So you can stay ahead of the drama. ๐ฎ
๐ ENVIRONMENT ๐
See the reference https://doc.rust-lang.org/cargo/reference/environment-variables.html for details on environment variables that Cargo reads. So many env vars, so little time. ๐
๐ฏ EXIT STATUS ๐ฏ
0: Cargo succeeded. ๐101: Cargo failed to complete. ๐ญ
So if you see 101, you know it's not it. ๐
โจ EXAMPLES โจ
- Build the local package and all of its dependencies:
cargo build
- Build with optimizations:
cargo build --release
So simple, so iconic. ๐ซถ
๐ SEE ALSO ๐
Go check 'em out, bestie. They're part of the squad. ๐
And that's the page! This is from the Cargo manual, and the footer says CARGO-BUILD(1) โ iconic. No date given, but you know it's fresh. Stay slay, bestie! ๐
โจ
๐ฆ 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