'\" t .\" Title: cargo-build .\" Author: [see the "AUTHOR(S)" section] .\" Generator: Asciidoctor 2.0.10 .\" Date: 2019-09-05 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" .TH "CARGO\-BUILD" "1" "2019-09-05" "\ \&" "\ \&" .ie \n(.g .ds Aq \(aq .el .ds Aq ' .ss \n[.ss] 0 .nh .ad l .de URL \fI\\$2\fP <\\$1>\\$3 .. .als MTO URL .if \n[.g] \{\ . mso www.tmac . am URL . ad l . . . am MTO . ad l . . . LINKSTYLE blue R < > .\} .SH "NAME" cargo\-build \- Compile the current package .SH "SYNOPSIS" .sp \fBcargo build [\fIOPTIONS\fP]\fP .SH "DESCRIPTION" .sp Compile local packages and all of their dependencies. .SH "OPTIONS" .SS "Package Selection" .sp By default, when no package selection options are given, the packages selected depend on the selected manifest file (based on the current working directory if \fB\-\-manifest\-path\fP is not given). If the manifest is the root of a workspace then the workspaces default members are selected, otherwise only the package defined by the manifest will be selected. .sp The default members of a workspace can be set explicitly with the \fBworkspace.default\-members\fP key in the root manifest. If this is not set, a virtual workspace will include all workspace members (equivalent to passing \fB\-\-workspace\fP), and a non\-virtual workspace will include only the root crate itself. .sp \fB\-p\fP \fISPEC\fP..., \fB\-\-package\fP \fISPEC\fP... .RS 4 Build only the specified packages. See \fBcargo\-pkgid\fP(1) for the SPEC format. This flag may be specified multiple times. .RE .sp \fB\-\-workspace\fP .RS 4 Build all members in the workspace. .RE .sp \fB\-\-all\fP .RS 4 Deprecated alias for \fB\-\-workspace\fP. .RE .sp \fB\-\-exclude\fP \fISPEC\fP... .RS 4 Exclude the specified packages. Must be used in conjunction with the \fB\-\-workspace\fP flag. This flag may be specified multiple times. .RE .SS "Target Selection" .sp When no target selection options are given, \fBcargo build\fP will build all binary and library targets of the selected packages. Binaries are skipped if they have \fBrequired\-features\fP that are missing. .sp Passing target selection flags will build only the specified targets. .sp \fB\-\-lib\fP .RS 4 Build the package\(cqs library. .RE .sp \fB\-\-bin\fP \fINAME\fP... .RS 4 Build the specified binary. This flag may be specified multiple times. .RE .sp \fB\-\-bins\fP .RS 4 Build all binary targets. .RE .sp \fB\-\-example\fP \fINAME\fP... .RS 4 Build the specified example. This flag may be specified multiple times. .RE .sp \fB\-\-examples\fP .RS 4 Build all example targets. .RE .sp \fB\-\-test\fP \fINAME\fP... .RS 4 Build the specified integration test. This flag may be specified multiple times. .RE .sp \fB\-\-tests\fP .RS 4 Build all targets in test mode that have the \fBtest = true\fP manifest 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 the \fBtest\fP flag in the manifest settings for the target. .RE .sp \fB\-\-bench\fP \fINAME\fP... .RS 4 Build the specified benchmark. This flag may be specified multiple times. .RE .sp \fB\-\-benches\fP .RS 4 Build all targets in benchmark mode that have the \fBbench = true\fP manifest 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 the \fBbench\fP flag in the manifest settings for the target. .RE .sp \fB\-\-all\-targets\fP .RS 4 Build all targets. This is equivalent to specifying \fB\-\-lib \-\-bins \-\-tests \-\-benches \-\-examples\fP. .RE .SS "Feature Selection" .sp The feature flags allow you to control the enabled features for the "current" package. The "current" package is the package in the current directory, or the one specified in \fB\-\-manifest\-path\fP. If running in the root of a virtual workspace, then the default features are selected for all workspace members, or all features if \fB\-\-all\-features\fP is specified. .sp When no feature options are given, the \fBdefault\fP feature is activated for every selected package. .sp \fB\-\-features\fP \fIFEATURES\fP .RS 4 Space or comma separated list of features to activate. These features only apply to the current directory\(cqs package. Features of direct dependencies may be enabled with \fB/\fP syntax. This flag may be specified multiple times, which enables all specified features. .RE .sp \fB\-\-all\-features\fP .RS 4 Activate all available features of all selected packages. .RE .sp \fB\-\-no\-default\-features\fP .RS 4 Do not activate the \fBdefault\fP feature of the current directory\(cqs package. .RE .SS "Compilation Options" .sp \fB\-\-target\fP \fITRIPLE\fP .RS 4 Build for the given architecture. The default is the host architecture. The general format of the triple is \fB\-\-\-\fP. Run \fBrustc \-\-print target\-list\fP for a list of supported targets. .sp This may also be specified with the \fBbuild.target\fP .URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "." .sp Note that specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. See the .URL "https://doc.rust\-lang.org/cargo/guide/build\-cache.html" "build cache" " " documentation for more details. .RE .sp \fB\-\-release\fP .RS 4 Build optimized artifacts with the \fBrelease\fP profile. See the PROFILES section for details on how this affects profile selection. .RE .SS "Output Options" .sp \fB\-\-target\-dir\fP \fIDIRECTORY\fP .RS 4 Directory for all generated artifacts and intermediate files. May also be specified with the \fBCARGO_TARGET_DIR\fP environment variable, or the \fBbuild.target\-dir\fP \c .URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "." Defaults to \fBtarget\fP in the root of the workspace. .RE .sp \fB\-\-out\-dir\fP \fIDIRECTORY\fP .RS 4 Copy final artifacts to this directory. .sp This option is unstable and available only on the \c .URL "https://doc.rust\-lang.org/book/appendix\-07\-nightly\-rust.html" "nightly channel" and requires the \fB\-Z unstable\-options\fP flag to enable. See \c .URL "https://github.com/rust\-lang/cargo/issues/6790" "" " " for more information. .RE .SS "Display Options" .sp \fB\-v\fP, \fB\-\-verbose\fP .RS 4 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 the \fBterm.verbose\fP .URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "." .RE .sp \fB\-q\fP, \fB\-\-quiet\fP .RS 4 No output printed to stdout. .RE .sp \fB\-\-color\fP \fIWHEN\fP .RS 4 Control when colored output is used. Valid values: .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} \fBauto\fP (default): Automatically detect if color support is available on the terminal. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} \fBalways\fP: Always display colors. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} \fBnever\fP: Never display colors. .RE .sp May also be specified with the \fBterm.color\fP .URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "." .RE .sp \fB\-\-message\-format\fP \fIFMT\fP .RS 4 The output format for diagnostic messages. Can be specified multiple times and consists of comma\-separated values. Valid values: .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} \fBhuman\fP (default): Display in a human\-readable text format. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} \fBshort\fP: Emit shorter, human\-readable text messages. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} \fBjson\fP: Emit JSON messages to stdout. See \c .URL "https://doc.rust\-lang.org/cargo/reference/external\-tools.html#json\-messages" "the reference" for more details. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} \fBjson\-diagnostic\-short\fP: Ensure the \fBrendered\fP field of JSON messages contains the "short" rendering from rustc. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} \fBjson\-diagnostic\-rendered\-ansi\fP: Ensure the \fBrendered\fP field of JSON messages contains embedded ANSI color codes for respecting rustc\(cqs default color scheme. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} \fBjson\-render\-diagnostics\fP: Instruct Cargo to not include rustc diagnostics in in JSON messages printed, but instead Cargo itself should render the JSON diagnostics coming from rustc. Cargo\(cqs own JSON diagnostics and others coming from rustc are still emitted. .RE .RE .sp \fB\-\-build\-plan\fP .RS 4 Outputs a series of JSON messages to stdout that indicate the commands to run the build. .sp This option is unstable and available only on the \c .URL "https://doc.rust\-lang.org/book/appendix\-07\-nightly\-rust.html" "nightly channel" and requires the \fB\-Z unstable\-options\fP flag to enable. See \c .URL "https://github.com/rust\-lang/cargo/issues/5579" "" " " for more information. .RE .SS "Manifest Options" .sp \fB\-\-manifest\-path\fP \fIPATH\fP .RS 4 Path to the \fBCargo.toml\fP file. By default, Cargo searches for the \fBCargo.toml\fP file in the current directory or any parent directory. .RE .sp \fB\-\-frozen\fP, \fB\-\-locked\fP .RS 4 Either of these flags requires that the \fBCargo.lock\fP file is up\-to\-date. If the lock file is missing, or it needs to be updated, Cargo will exit with an error. The \fB\-\-frozen\fP flag also prevents Cargo from attempting to access the network to determine if it is out\-of\-date. .sp These may be used in environments where you want to assert that the \fBCargo.lock\fP file is up\-to\-date (such as a CI build) or want to avoid network access. .RE .sp \fB\-\-offline\fP .RS 4 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. .sp Beware that 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 \fBcargo\-fetch\fP(1) command to download dependencies before going offline. .sp May also be specified with the \fBnet.offline\fP \c .URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "." .RE .SS "Common Options" .sp \fB+TOOLCHAIN\fP .RS 4 If Cargo has been installed with rustup, and the first argument to \fBcargo\fP begins with \fB+\fP, it will be interpreted as a rustup toolchain name (such as \fB+stable\fP or \fB+nightly\fP). See the \c .URL "https://github.com/rust\-lang/rustup/" "rustup documentation" for more information about how toolchain overrides work. .RE .sp \fB\-h\fP, \fB\-\-help\fP .RS 4 Prints help information. .RE .sp \fB\-Z\fP \fIFLAG\fP... .RS 4 Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fP for details. .RE .SS "Miscellaneous Options" .sp \fB\-j\fP \fIN\fP, \fB\-\-jobs\fP \fIN\fP .RS 4 Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fP \c .URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "." Defaults to the number of CPUs. .RE .SH "PROFILES" .sp Profiles may be used to configure compiler options such as optimization levels and debug settings. See \c .URL "https://doc.rust\-lang.org/cargo/reference/profiles.html" "the reference" for more details. .sp Profile selection depends on the target and crate being built. By default the \fBdev\fP or \fBtest\fP profiles are used. If the \fB\-\-release\fP flag is given, then the \fBrelease\fP or \fBbench\fP profiles are used. .TS allbox tab(:); lt lt lt. T{ .sp Target T}:T{ .sp Default Profile T}:T{ .sp \fB\-\-release\fP Profile T} T{ .sp lib, bin, example T}:T{ .sp \fBdev\fP T}:T{ .sp \fBrelease\fP T} T{ .sp test, bench, or any target .br in "test" or "bench" mode T}:T{ .sp \fBtest\fP T}:T{ .sp \fBbench\fP T} .TE .sp .sp Dependencies use the \fBdev\fP/\fBrelease\fP profiles. .SH "ENVIRONMENT" .sp See \c .URL "https://doc.rust\-lang.org/cargo/reference/environment\-variables.html" "the reference" " " for details on environment variables that Cargo reads. .SH "EXIT STATUS" .sp 0 .RS 4 Cargo succeeded. .RE .sp 101 .RS 4 Cargo failed to complete. .RE .SH "EXAMPLES" .sp .RS 4 .ie n \{\ \h'-04' 1.\h'+01'\c .\} .el \{\ . sp -1 . IP " 1." 4.2 .\} Build the local package and all of its dependencies: .sp .if n .RS 4 .nf cargo build .fi .if n .RE .RE .sp .RS 4 .ie n \{\ \h'-04' 2.\h'+01'\c .\} .el \{\ . sp -1 . IP " 2." 4.2 .\} Build with optimizations: .sp .if n .RS 4 .nf cargo build \-\-release .fi .if n .RE .RE .SH "SEE ALSO" .sp \fBcargo\fP(1), \fBcargo\-rustc\fP(1)