Skip to content

Commit

Permalink
Clarify config-relative paths for --config <path>
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Sep 13, 2022
1 parent 65332bc commit 0161499
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/doc/src/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,27 @@ precedence rules as other options specified directly with `--config`.

### Config-relative paths

Paths in config files may be absolute, relative, or a bare name without any
path separators. Paths for executables without a path separator will use the
`PATH` environment variable to search for the executable. Paths for
non-executables will be relative to where the config value is defined. For
config files, that is relative to the parent directory of the `.cargo`
directory where the value was defined. For environment variables it is
relative to the current working directory.
Paths in config files may be absolute, relative, or a bare name without any path separators.
Paths for executables without a path separator will use the `PATH` environment variable to search for the executable.
Paths for non-executables will be relative to where the config value is defined.
In particular, rules are:

* For environment variables it is relative to the current working directory.
* For config files, that is relative to the parent directory of the directory where the value was defined.

That is to say, for config files from either the [hierarchical probing](#hierarchical-structure)
or the [`--config <path>` option](#command-line-overrides),
it is always relative to two directory levels up from where the file was defined.

> **Note:** To maintain consistency with existing `.cargo/config.toml` probing behavior,
> it is by design that a path in a config file passed via `--config <path>`
> is also relative to two levels up from the config file itself.
>
> To avoid unexpected results, the rule of thumb is putting your extra config files
> at the same level of discovered `.cargo/config.toml` in your porject.
> For instance, given a project `/my/project`,
> it is recommended to put config files under `/my/project/.cargo`
> or a new directory at the same level, such as `/my/project/.config`.
```toml
# Relative path examples.
Expand Down

0 comments on commit 0161499

Please sign in to comment.