← 返回命令列表

Linux command

cargo-build 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Build project

cargo build

Build with release optimizations

cargo build --release

Build specific package

cargo build -p [package]

Build all workspace members

cargo build --workspace

Build with specific features

cargo build --features [feature1,feature2]

Build all features

cargo build --all-features

Build for specific target

cargo build --target [x86_64-unknown-linux-gnu]

Build offline

cargo build --offline

说明

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.

参数

-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

FAQ

What is the cargo-build command used for?

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.

How do I run a basic cargo-build example?

Run `cargo build` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -r, --release do in cargo-build?

Build with optimizations (release profile)