@@ -658,28 +658,71 @@ like to stabilize it somehow!
658658
659659This 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
667692include = " path/to/mordor.toml"
668693
669- # or an array of paths
694+ # array of paths
670695include = [" 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