LinuxCommandLibrary

cargo-build

Compile a Rust package and its dependencies

TLDR

Build project

$ cargo build
copy
Build with release optimizations
$ cargo build --release
copy
Build specific package
$ cargo build -p [package]
copy
Build all workspace members
$ cargo build --workspace
copy
Build with specific features
$ cargo build --features [feature1,feature2]
copy
Build all features
$ cargo build --all-features
copy
Build for specific target
$ cargo build --target [x86_64-unknown-linux-gnu]
copy
Build offline
$ cargo build --offline
copy

SYNOPSIS

cargo build [options]

DESCRIPTION

cargo build compiles a local package and all its dependencies. Creates executable in target/debug/ by default, or target/release/ with --release flag.
Debug builds compile faster but run slower. Release builds are optimized but take longer to compile.

PARAMETERS

-r, --release

Build with optimizations (release profile)
--profile name
Build with specific profile
-p, --package spec
Build only specified packages
--workspace
Build all workspace members
--all-targets
Build all targets (lib, bins, tests, benches, examples)
--lib
Build library only
--bins
Build all binaries
--examples
Build all examples
--target triple
Build for target platform
--target-dir dir
Output directory
-j, --jobs n
Parallel build jobs
--features features
Enable specified features
--all-features
Enable all features
--no-default-features
Disable default features
--offline
Build without network access
--timings
Output build timing info

OUTPUT LOCATIONS

target/debug/

Debug builds (default)
target/release/
Release builds (--release)

CAVEATS

Same commands work across all operating systems. First build downloads and compiles dependencies.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community