Skip to content

Commit 3d668e8

Browse files
committed
Document CARGO_CONFIG_PATH
1 parent a858aa0 commit 3d668e8

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/doc/src/reference/config.md

+20-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ This document explains how Cargo’s configuration system works, as well as
44
available keys or configuration. For configuration of a package through its
55
manifest, see the [manifest format](manifest.md).
66

7-
### Hierarchical structure
7+
### How configuration files are found
88

99
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
1113
all parent directories. If, for example, Cargo were invoked in
1214
`/projects/foo/bar/baz`, then the following configuration files would be
1315
probed for and unified in this order:
@@ -25,10 +27,24 @@ With this structure, you can specify configuration per-package, and even
2527
possibly check it into version control. You can also specify personal defaults
2628
with a configuration file in your home directory.
2729

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+
2842
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
3045
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.
3248

3349
> **Note:** Cargo also reads config files without the `.toml` extension, such as
3450
> `.cargo/config`. Support for the `.toml` extension was added in version 1.39

0 commit comments

Comments
 (0)