Cargo sets and reads a number of environment variables which your code can detect or override. Here is a list of the variables Cargo sets, organized by when it interacts with them:
Environment variables Cargo readsYou can override these environment variables to change Cargoâs behavior on your system:
CARGO_LOG
â Cargo uses the tracing
crate to display debug log messages. The CARGO_LOG
environment variable can be set to enable debug logging, with a value such as trace
, debug
, or warn
. Usually it is only used during debugging. For more details refer to the Debug logging.CARGO_HOME
â Cargo maintains a local cache of the registry index and of git checkouts of crates. By default these are stored under $HOME/.cargo
(%USERPROFILE%\.cargo
on Windows), but this variable overrides the location of this directory. Once a crate is cached it is not removed by the clean command. For more details refer to the guide.CARGO_TARGET_DIR
â Location of where to place all generated artifacts, relative to the current working directory. See build.target-dir
to set via config.CARGO
â If set, Cargo will forward this value instead of setting it to its own auto-detected path when it builds crates and when it executes build scripts and external subcommands. This value is not directly executed by Cargo, and should always point at a command that behaves exactly like cargo
, as thatâs what users of the variable will be expecting.RUSTC
â Instead of running rustc
, Cargo will execute this specified compiler instead. See build.rustc
to set via config.RUSTC_WRAPPER
â Instead of simply running rustc
, Cargo will execute this specified wrapper, passing as its command-line arguments the rustc invocation, with the first argument being the path to the actual rustc. Useful to set up a build cache tool such as sccache
. See build.rustc-wrapper
to set via config. Setting this to the empty string overwrites the config and resets cargo to not use a wrapper.RUSTC_WORKSPACE_WRAPPER
â Instead of simply running rustc
, for workspace members Cargo will execute this specified wrapper, passing as its command-line arguments the rustc invocation, with the first argument being the path to the actual rustc. When building a single-package project without workspaces, that package is considered to be the workspace. It affects the filename hash so that artifacts produced by the wrapper are cached separately. See build.rustc-workspace-wrapper
to set via config. Setting this to the empty string overwrites the config and resets cargo to not use a wrapper for workspace members. If both RUSTC_WRAPPER
and RUSTC_WORKSPACE_WRAPPER
are set, then they will be nested: the final invocation is $RUSTC_WRAPPER $RUSTC_WORKSPACE_WRAPPER $RUSTC
.RUSTDOC
â Instead of running rustdoc
, Cargo will execute this specified rustdoc
instance instead. See build.rustdoc
to set via config.RUSTDOCFLAGS
â A space-separated list of custom flags to pass to all rustdoc
invocations that Cargo performs. In contrast with cargo rustdoc
, this is useful for passing a flag to all rustdoc
instances. See build.rustdocflags
for some more ways to set flags. This string is split by whitespace; for a more robust encoding of multiple arguments, see CARGO_ENCODED_RUSTDOCFLAGS
.CARGO_ENCODED_RUSTDOCFLAGS
â A list of custom flags separated by 0x1f
(ASCII Unit Separator) to pass to all rustdoc
invocations that Cargo performs.RUSTFLAGS
â A space-separated list of custom flags to pass to all compiler invocations that Cargo performs. In contrast with cargo rustc
, this is useful for passing a flag to all compiler instances. See build.rustflags
for some more ways to set flags. This string is split by whitespace; for a more robust encoding of multiple arguments, see CARGO_ENCODED_RUSTFLAGS
.CARGO_ENCODED_RUSTFLAGS
â A list of custom flags separated by 0x1f
(ASCII Unit Separator) to pass to all compiler invocations that Cargo performs.CARGO_INCREMENTAL
â If this is set to 1 then Cargo will force incremental compilation to be enabled for the current compilation, and when set to 0 it will force disabling it. If this env var isnât present then cargoâs defaults will otherwise be used. See also build.incremental
config value.CARGO_CACHE_RUSTC_INFO
â If this is set to 0 then Cargo will not try to cache compiler version information.HTTPS_PROXY
or https_proxy
or http_proxy
â The HTTP proxy to use, see http.proxy
for more detail.HTTP_TIMEOUT
â The HTTP timeout in seconds, see http.timeout
for more detail.TERM
â If this is set to dumb
, it disables the progress bar.BROWSER
â The web browser to execute to open documentation with cargo doc
âsâ --open
flag, see doc.browser
for more details.RUSTFMT
â Instead of running rustfmt
, cargo fmt
will execute this specified rustfmt
instance instead.Cargo reads environment variables for some configuration values. See the configuration chapter for more details. In summary, the supported environment variables are:
CARGO_ALIAS_<name>
â Command aliases, see alias
.CARGO_BUILD_JOBS
â Number of parallel jobs, see build.jobs
.CARGO_BUILD_RUSTC
â The rustc
executable, see build.rustc
.CARGO_BUILD_RUSTC_WRAPPER
â The rustc
wrapper, see build.rustc-wrapper
.CARGO_BUILD_RUSTC_WORKSPACE_WRAPPER
â The rustc
wrapper for workspace members only, see build.rustc-workspace-wrapper
.CARGO_BUILD_RUSTDOC
â The rustdoc
executable, see build.rustdoc
.CARGO_BUILD_TARGET
â The default target platform, see build.target
.CARGO_BUILD_TARGET_DIR
â The default output directory, see build.target-dir
.CARGO_BUILD_RUSTFLAGS
â Extra rustc
flags, see build.rustflags
.CARGO_BUILD_RUSTDOCFLAGS
â Extra rustdoc
flags, see build.rustdocflags
.CARGO_BUILD_INCREMENTAL
â Incremental compilation, see build.incremental
.CARGO_BUILD_DEP_INFO_BASEDIR
â Dep-info relative directory, see build.dep-info-basedir
.CARGO_CARGO_NEW_VCS
â The default source control system with cargo new
, see cargo-new.vcs
.CARGO_FUTURE_INCOMPAT_REPORT_FREQUENCY
â How often we should generate a future incompat report notification, see future-incompat-report.frequency
.CARGO_HTTP_DEBUG
â Enables HTTP debugging, see http.debug
.CARGO_HTTP_PROXY
â Enables HTTP proxy, see http.proxy
.CARGO_HTTP_TIMEOUT
â The HTTP timeout, see http.timeout
.CARGO_HTTP_CAINFO
â The TLS certificate Certificate Authority file, see http.cainfo
.CARGO_HTTP_CHECK_REVOKE
â Disables TLS certificate revocation checks, see http.check-revoke
.CARGO_HTTP_SSL_VERSION
â The TLS version to use, see http.ssl-version
.CARGO_HTTP_LOW_SPEED_LIMIT
â The HTTP low-speed limit, see http.low-speed-limit
.CARGO_HTTP_MULTIPLEXING
â Whether HTTP/2 multiplexing is used, see http.multiplexing
.CARGO_HTTP_USER_AGENT
â The HTTP user-agent header, see http.user-agent
.CARGO_INSTALL_ROOT
â The default directory for cargo install
, see install.root
.CARGO_NET_RETRY
â Number of times to retry network errors, see net.retry
.CARGO_NET_GIT_FETCH_WITH_CLI
â Enables the use of the git
executable to fetch, see net.git-fetch-with-cli
.CARGO_NET_OFFLINE
â Offline mode, see net.offline
.CARGO_PROFILE_<name>_BUILD_OVERRIDE_<key>
â Override build script profile, see profile.<name>.build-override
.CARGO_PROFILE_<name>_CODEGEN_UNITS
â Set code generation units, see profile.<name>.codegen-units
.CARGO_PROFILE_<name>_DEBUG
â What kind of debug info to include, see profile.<name>.debug
.CARGO_PROFILE_<name>_DEBUG_ASSERTIONS
â Enable/disable debug assertions, see profile.<name>.debug-assertions
.CARGO_PROFILE_<name>_INCREMENTAL
â Enable/disable incremental compilation, see profile.<name>.incremental
.CARGO_PROFILE_<name>_LTO
â Link-time optimization, see profile.<name>.lto
.CARGO_PROFILE_<name>_OVERFLOW_CHECKS
â Enable/disable overflow checks, see profile.<name>.overflow-checks
.CARGO_PROFILE_<name>_OPT_LEVEL
â Set the optimization level, see profile.<name>.opt-level
.CARGO_PROFILE_<name>_PANIC
â The panic strategy to use, see profile.<name>.panic
.CARGO_PROFILE_<name>_RPATH
â The rpath linking option, see profile.<name>.rpath
.CARGO_PROFILE_<name>_SPLIT_DEBUGINFO
â Controls debug file output behavior, see profile.<name>.split-debuginfo
.CARGO_PROFILE_<name>_STRIP
â Controls stripping of symbols and/or debuginfos, see profile.<name>.strip
.CARGO_REGISTRIES_<name>_CREDENTIAL_PROVIDER
â Credential provider for a registry, see registries.<name>.credential-provider
.CARGO_REGISTRIES_<name>_INDEX
â URL of a registry index, see registries.<name>.index
.CARGO_REGISTRIES_<name>_TOKEN
â Authentication token of a registry, see registries.<name>.token
.CARGO_REGISTRY_CREDENTIAL_PROVIDER
â Credential provider for crates.io, see registry.credential-provider
.CARGO_REGISTRY_DEFAULT
â Default registry for the --registry
flag, see registry.default
.CARGO_REGISTRY_GLOBAL_CREDENTIAL_PROVIDERS
â Credential providers for registries that do not have a specific provider defined. See registry.global-credential-providers
.CARGO_REGISTRY_TOKEN
â Authentication token for crates.io, see registry.token
.CARGO_TARGET_<triple>_LINKER
â The linker to use, see target.<triple>.linker
. The triple must be converted to uppercase and underscores.CARGO_TARGET_<triple>_RUNNER
â The executable runner, see target.<triple>.runner
.CARGO_TARGET_<triple>_RUSTFLAGS
â Extra rustc
flags for a target, see target.<triple>.rustflags
.CARGO_TERM_QUIET
â Quiet mode, see term.quiet
.CARGO_TERM_VERBOSE
â The default terminal verbosity, see term.verbose
.CARGO_TERM_COLOR
â The default color mode, see term.color
.CARGO_TERM_PROGRESS_WHEN
â The default progress bar showing mode, see term.progress.when
.CARGO_TERM_PROGRESS_WIDTH
â The default progress bar width, see term.progress.width
.Cargo exposes these environment variables to your crate when it is compiled. Note that this applies for running binaries with cargo run
and cargo test
as well. To get the value of any of these variables in a Rust program, do this:
let version = env!("CARGO_PKG_VERSION");
version
will now contain the value of CARGO_PKG_VERSION
.
Note that if one of these values is not provided in the manifest, the corresponding environment variable is set to the empty string, ""
.
CARGO
â Path to the cargo
binary performing the build.CARGO_MANIFEST_DIR
â The directory containing the manifest of your package.CARGO_MANIFEST_PATH
â The path to the manifest of your package.CARGO_PKG_VERSION
â The full version of your package.CARGO_PKG_VERSION_MAJOR
â The major version of your package.CARGO_PKG_VERSION_MINOR
â The minor version of your package.CARGO_PKG_VERSION_PATCH
â The patch version of your package.CARGO_PKG_VERSION_PRE
â The pre-release version of your package.CARGO_PKG_AUTHORS
â Colon separated list of authors from the manifest of your package.CARGO_PKG_NAME
â The name of your package.CARGO_PKG_DESCRIPTION
â The description from the manifest of your package.CARGO_PKG_HOMEPAGE
â The home page from the manifest of your package.CARGO_PKG_REPOSITORY
â The repository from the manifest of your package.CARGO_PKG_LICENSE
â The license from the manifest of your package.CARGO_PKG_LICENSE_FILE
â The license file from the manifest of your package.CARGO_PKG_RUST_VERSION
â The Rust version from the manifest of your package. Note that this is the minimum Rust version supported by the package, not the current Rust version.CARGO_PKG_README
â Path to the README file of your package.CARGO_CRATE_NAME
â The name of the crate that is currently being compiled. It is the name of the Cargo target with -
converted to _
, such as the name of the library, binary, example, integration test, or benchmark.CARGO_BIN_NAME
â The name of the binary that is currently being compiled. Only set for binaries or binary examples. This name does not include any file extension, such as .exe
.OUT_DIR
â If the package has a build script, this is set to the folder where the build script should place its output. See below for more information. (Only set during compilation.)CARGO_BIN_EXE_<name>
â The absolute path to a binary targetâs executable. This is only set when building an integration test or benchmark. This may be used with the env
macro to find the executable to run for testing purposes. The <name>
is the name of the binary target, exactly as-is. For example, CARGO_BIN_EXE_my-program
for a binary named my-program
. Binaries are automatically built when the test is built, unless the binary has required features that are not enabled.CARGO_PRIMARY_PACKAGE
â This environment variable will be set if the package being built is primary. Primary packages are the ones the user selected on the command-line, either with -p
flags or the defaults based on the current directory and the default workspace members. This variable will not be set when building dependencies, unless a dependency is also a workspace member that was also selected on the command-line. This is only set when compiling the package (not when running binaries or tests).CARGO_TARGET_TMPDIR
â Only set when building integration test or benchmark code. This is a path to a directory inside the target directory where integration tests or benchmarks are free to put any data needed by the tests/benches. Cargo initially creates this directory but doesnât manage its content in any way, this is the responsibility of the test code.Cargo also sets the dynamic library path when compiling and running binaries with commands like cargo run
and cargo test
. This helps with locating shared libraries that are part of the build process. The variable name depends on the platform:
PATH
DYLD_FALLBACK_LIBRARY_PATH
LD_LIBRARY_PATH
LIBPATH
The value is extended from the existing value when Cargo starts. macOS has special consideration where if DYLD_FALLBACK_LIBRARY_PATH
is not already set, it will add the default $HOME/lib:/usr/local/lib:/usr/lib
.
Cargo includes the following paths:
rustc-link-search
instruction. Paths outside of the target
directory are removed. It is the responsibility of the user running Cargo to properly set the environment if additional libraries on the system are needed in the search path.target/debug
, and the âdepsâ directory. This is mostly for support of proc-macros.Cargo sets several environment variables when build scripts are run. Because these variables are not yet set when the build script is compiled, the above example using env!
wonât work and instead youâll need to retrieve the values when the build script is run:
use std::env;
let out_dir = env::var("OUT_DIR").unwrap();
out_dir
will now contain the value of OUT_DIR
.
CARGO
â Path to the cargo
binary performing the build.CARGO_MANIFEST_DIR
â The directory containing the manifest for the package being built (the package containing the build script). Also note that this is the value of the current working directory of the build script when it starts.CARGO_MANIFEST_PATH
â The path to the manifest of your package.CARGO_MANIFEST_LINKS
â the manifest links
value.CARGO_MAKEFLAGS
â Contains parameters needed for Cargoâs jobserver implementation to parallelize subprocesses. Rustc or cargo invocations from build.rs can already read CARGO_MAKEFLAGS
, but GNU Make requires the flags to be specified either directly as arguments, or through the MAKEFLAGS
environment variable. Currently Cargo doesnât set the MAKEFLAGS
variable, but itâs free for build scripts invoking GNU Make to set it to the contents of CARGO_MAKEFLAGS
.CARGO_FEATURE_<name>
â For each activated feature of the package being built, this environment variable will be present where <name>
is the name of the feature uppercased and having -
translated to _
.CARGO_CFG_<cfg>
â For each configuration option of the package being built, this environment variable will contain the value of the configuration, where <cfg>
is the name of the configuration uppercased and having -
translated to _
. Boolean configurations are present if they are set, and not present otherwise. Configurations with multiple values are joined to a single variable with the values delimited by ,
. This includes values built-in to the compiler (which can be seen with rustc --print=cfg
) and values set by build scripts and extra flags passed to rustc
(such as those defined in RUSTFLAGS
). Some examples of what these variables are:
CARGO_CFG_FEATURE
â Each activated feature of the package being built.CARGO_CFG_UNIX
â Set on unix-like platforms.CARGO_CFG_WINDOWS
â Set on windows-like platforms.CARGO_CFG_TARGET_FAMILY=unix,wasm
â The target family.CARGO_CFG_TARGET_OS=macos
â The target operating system.CARGO_CFG_TARGET_ARCH=x86_64
â The CPU target architecture.CARGO_CFG_TARGET_VENDOR=apple
â The target vendor.CARGO_CFG_TARGET_ENV=gnu
â The target environment ABI.CARGO_CFG_TARGET_ABI=sim
â The target ABI.CARGO_CFG_TARGET_POINTER_WIDTH=64
â The CPU pointer width.CARGO_CFG_TARGET_ENDIAN=little
â The CPU target endianness.CARGO_CFG_TARGET_FEATURE=mmx,sse
â List of CPU target features enabled.Note that different target triples have different sets of
cfg
values, hence variables present in one target triple might not be available in the other.Some cfg values like
debug_assertions
andtest
are not available.
OUT_DIR
â the folder in which all output and intermediate artifacts should be placed. This folder is inside the build directory for the package being built, and it is unique for the package in question.TARGET
â the target triple that is being compiled for. Native code should be compiled for this triple. See the Target Triple description for more information.HOST
â the host triple of the Rust compiler.NUM_JOBS
â the parallelism specified as the top-level parallelism. This can be useful to pass a -j
parameter to a system like make
. Note that care should be taken when interpreting this environment variable. For historical purposes this is still provided but recent versions of Cargo, for example, do not need to run make -j
, and instead can set the MAKEFLAGS
env var to the content of CARGO_MAKEFLAGS
to activate the use of Cargoâs GNU Make compatible jobserver for sub-make invocations.OPT_LEVEL
, DEBUG
â values of the corresponding variables for the profile currently being built.PROFILE
â release
for release builds, debug
for other builds. This is determined based on if the profile inherits from the dev
or release
profile. Using this environment variable is not recommended. Using other environment variables like OPT_LEVEL
provide a more correct view of the actual settings being used.DEP_<name>_<key>
â For more information about this set of environment variables, see build script documentation about links
.RUSTC
, RUSTDOC
â the compiler and documentation generator that Cargo has resolved to use, passed to the build script so it might use it as well.RUSTC_WRAPPER
â the rustc
wrapper, if any, that Cargo is using. See build.rustc-wrapper
.RUSTC_WORKSPACE_WRAPPER
â the rustc
wrapper, if any, that Cargo is using for workspace members. See build.rustc-workspace-wrapper
.RUSTC_LINKER
â The path to the linker binary that Cargo has resolved to use for the current target, if specified. The linker can be changed by editing .cargo/config.toml
; see the documentation about cargo configuration for more information.CARGO_ENCODED_RUSTFLAGS
â extra flags that Cargo invokes rustc
with, separated by a 0x1f
character (ASCII Unit Separator). See build.rustflags
. Note that since Rust 1.55, RUSTFLAGS
is removed from the environment; scripts should use CARGO_ENCODED_RUSTFLAGS
instead.CARGO_PKG_<var>
â The package information variables, with the same names and values as are provided during crate building.Cargo exposes this environment variable to 3rd party subcommands (ie. programs named cargo-foobar
placed in $PATH
):
CARGO
â Path to the cargo
binary performing the build.CARGO_MAKEFLAGS
â Contains parameters needed for Cargoâs jobserver implementation to parallelize subprocesses. This is set only when Cargo detects the existence of a jobserver.For extended information about your environment you may run cargo metadata
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3