Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can the location of Cargo's configuration directory be overridden?

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?

like image 233
Doe Avatar asked Jun 27 '16 10:06

Doe


People also ask

Where is cargo config file?

Windows: %USERPROFILE%\. cargo\config. toml.

Where is config TOML rust?

Rustup has a TOML settings file at ${RUSTUP_HOME}/settings. toml (which defaults to ~/. rustup or %USERPROFILE%/. rustup ).

What is Out_dir?

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.

Where is Cargo TOML?

Cargo. toml and Cargo. lock are stored in the root of your project (package root). Source code goes in the src directory.


2 Answers

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 running rustc, Cargo will execute this specified compiler instead.
  • RUSTC_WRAPPER — Instead of simply running rustc, Cargo will execute this specified wrapper instead, passing as its commandline arguments the rustc invocation, with the first argument being rustc.
  • RUSTDOC — Instead of running rustdoc, Cargo will execute this specified rustdoc instance instead.
  • 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.
  • 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.
  • 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

like image 100
aSpex Avatar answered Nov 05 '22 17:11

aSpex


The default location can be changed by means of the environment variable $CARGO_HOME, it overrides the default location which is $HOME/.cargo.

like image 27
Andrew Lygin Avatar answered Nov 05 '22 15:11

Andrew Lygin