Skip to content

Commit b9b13d0

Browse files
committed
docs(config-include): polish and mention new fields
Restructure config-include documentation: - Brief intro with examples - Added the "Documentation updates" subsection I am a bit not sure whether we should have standalone sections like `include.path` and `include.optional`, as we cannot really set `include.path = "config.toml"` directly. Or maybe `include[].path` is good for heading?
1 parent aeaf4b9 commit b9b13d0

File tree

1 file changed

+57
-14
lines changed

1 file changed

+57
-14
lines changed

src/doc/src/reference/unstable.md

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -658,28 +658,71 @@ like to stabilize it somehow!
658658

659659
This feature requires the `-Zconfig-include` command-line option.
660660

661-
The `include` key in a config file can be used to load another config file. It
662-
takes a string for a path to another file relative to the config file, or an
663-
array of config file paths. Only path ending with `.toml` is accepted.
661+
The `include` key in a config file can be used to load another config file.
662+
For example:
663+
664+
```toml
665+
# .cargo/config.toml
666+
include = "other-config.toml"
667+
668+
[build]
669+
jobs = 4
670+
```
671+
672+
```toml
673+
# .cargo/other-config.toml
674+
[build]
675+
rustflags = ["-W", "unsafe-code"]
676+
```
677+
678+
### Documentation updates
679+
680+
#### `include`
681+
682+
* Type: string, array of strings, or array of tables
683+
* Default: none
684+
685+
Loads additional config files. Paths are relative to the config file that
686+
includes them. Only paths ending with `.toml` are accepted.
687+
688+
Supports the following formats:
664689

665690
```toml
666-
# a path ending with `.toml`
691+
# single path
667692
include = "path/to/mordor.toml"
668693

669-
# or an array of paths
694+
# array of paths
670695
include = ["frodo.toml", "samwise.toml"]
696+
697+
# inline tables
698+
include = [
699+
"simple.toml",
700+
{ path = "optional.toml", optional = true }
701+
]
702+
703+
# array of tables
704+
[[include]]
705+
path = "required.toml"
706+
707+
[[include]]
708+
path = "optional.toml"
709+
optional = true
671710
```
672711

673-
Unlike other config values, the merge behavior of the `include` key is
674-
different. When a config file contains an `include` key:
712+
When using table syntax (inline tables or array of tables), the following
713+
fields are supported:
714+
715+
* `path` (string, required): Path to the config file to include.
716+
* `optional` (boolean, default: false): If `true`, missing files are silently
717+
skipped instead of causing an error.
718+
719+
The merge behavior of `include` is different from other config values:
675720

676-
1. The config values are first loaded from the `include` path.
677-
* If the value of the `include` key is an array of paths, the config values
678-
are loaded and merged from left to right for each path.
679-
* Recurse this step if the config values from the `include` path also
680-
contain an `include` key.
681-
2. Then, the config file's own values are merged on top of the config
682-
from the `include` path.
721+
1. Config values are first loaded from the `include` path.
722+
* If `include` is an array, config values are loaded and merged from left
723+
to right for each path.
724+
* This step recurses if included config files also contain `include` keys.
725+
2. Then, the config file's own values are merged on top of the included config.
683726

684727
## target-applies-to-host
685728
* Original Pull Request: [#9322](https://github.com/rust-lang/cargo/pull/9322)

0 commit comments

Comments
 (0)