@@ -4,10 +4,12 @@ This document explains how Cargo’s configuration system works, as well as
4
4
available keys or configuration. For configuration of a package through its
5
5
manifest, see the [ manifest format] ( manifest.md ) .
6
6
7
- ### Hierarchical structure
7
+ ### How configuration files are found
8
8
9
9
Cargo allows local configuration for a particular package as well as global
10
- configuration. It looks for configuration files in the current directory and
10
+ configuration. It has two mechanisms for this.
11
+
12
+ By default, it looks for configuration files in the current directory and
11
13
all parent directories. If, for example, Cargo were invoked in
12
14
` /projects/foo/bar/baz ` , then the following configuration files would be
13
15
probed for and unified in this order:
@@ -25,10 +27,24 @@ With this structure, you can specify configuration per-package, and even
25
27
possibly check it into version control. You can also specify personal defaults
26
28
with a configuration file in your home directory.
27
29
30
+ Alternatively, if the ` CARGO_CONFIG_PATH ` environment variable is set, it is
31
+ used as a ` : ` -delimited path of directories. Each of these directories is used
32
+ in the order they appear in ` CARGO_CONFIG_PATH ` . For example the path
33
+ ` CARGO_CONFIG_PATH=.:..:/projects/common:/home/me ` will search in:
34
+
35
+ * ` ./.cargo/config `
36
+ * ` ../.cargo/config `
37
+ * ` /projects/common/.cargo/config `
38
+ * ` /home/me/.cargo/config `
39
+
40
+ No other directories are searched, including ` CARGO_HOME ` .
41
+
28
42
If a key is specified in multiple config files, the values will get merged
29
- together. Numbers, strings, and booleans will use the value in the deeper
43
+ together. Numbers, strings, and booleans will use the value in the first
44
+ resolved config file - when using heirarchical search, the deeper
30
45
config directory taking precedence over ancestor directories, where the
31
- home directory is the lowest priority. Arrays will be joined together.
46
+ home directory is the lowest priority, and the earlier directory in ` CARGO_CONFIG_PATH `
47
+ when it is used. Arrays will be joined together.
32
48
33
49
> ** Note:** Cargo also reads config files without the ` .toml ` extension, such as
34
50
> ` .cargo/config ` . Support for the ` .toml ` extension was added in version 1.39
0 commit comments