It seems that the default behavior of Cargo when searching for its configuration directory is to look in the current user's home directory (~/.cargo
on my system). How can this behavior be modified to make Cargo look in a user-supplied directory instead?
Windows: %USERPROFILE%\. cargo\config. toml.
Rustup has a TOML settings file at ${RUSTUP_HOME}/settings. toml (which defaults to ~/. rustup or %USERPROFILE%/. rustup ).
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.
Cargo. toml and Cargo. lock are stored in the root of your project (package root). Source code goes in the src directory.
Environment variables Cargo reads
You can override these environment variables to change Cargo's behavior on your system:
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
, but this variable overrides the location of this directory. Once a crate is cached it is not removed by the clean command.CARGO_TARGET_DIR
— Location of where to place all generated artifacts, relative to the current working directory.RUSTC
— Instead of runningrustc
, Cargo will execute this specified compiler instead.RUSTC_WRAPPER
— Instead of simply runningrustc
, Cargo will execute this specified wrapper instead, passing as its commandline arguments the rustc invocation, with the first argument being rustc.RUSTDOC
— Instead of runningrustdoc
, Cargo will execute this specifiedrustdoc
instance instead.RUSTDOCFLAGS
— A space-separated list of custom flags to pass to allrustdoc
invocations that Cargo performs. In contrast withcargo rustdoc
, this is useful for passing a flag to allrustdoc
instances.RUSTFLAGS
— A space-separated list of custom flags to pass to all compiler invocations that Cargo performs. In contrast withcargo rustc
, this is useful for passing a flag to all compiler instances.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.CARGO_CACHE_RUSTC_INFO
— If this is set to 0 then Cargo will not try to cache compiler version information.
The Cargo documentation
Hierarchical structure
Cargo allows local configuration for a particular package as well as global configuration, like git. Cargo extends this to a hierarchical strategy. If, for example, Cargo were invoked in
/projects/foo/bar/baz
, then the following configuration files would be probed for and unified in this order:
/projects/foo/bar/baz/.cargo/config
/projects/foo/bar/.cargo/config
/projects/foo/.cargo/config
/projects/.cargo/config
/.cargo/config
$HOME/.cargo/config
With this structure, you can specify configuration per-package, and even possibly check it into version control. You can also specify personal defaults with a configuration file in your home directory.
The Cargo documentation
The default location can be changed by means of the environment variable $CARGO_HOME
, it overrides the default location which is $HOME/.cargo
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With