rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.82k stars 2.43k forks source link

Support multiple cargo configuration files in `.cargo` #9306

Open jonhoo opened 3 years ago

jonhoo commented 3 years ago

Describe the problem you are trying to solve I want to check in some subset of my cargo configuration into version control (e.g., aliases useful to all devs), but not others (e.g., parts that hold custom patches, rustflags, or other local build options).

Describe the solution you'd like I would like to be able to split my configuration file into multiple files, and then only check in some of them.

Notes Currently, my options are:

None of these are ideal. It'd be nice if cargo supported something like a .cargo/config.toml.d/ directory that could then contain any number of configuration files that are merged.

Revantus commented 3 years ago

Hi @jonhoo, does splitting your config into $HOME/.cargo/config.toml for personal configurations and /projects/foo/.cargo/config.toml for project specific, shared configurations not work in this case? Cargo Doc Reference

jonhoo commented 3 years ago

No, unfortunately not. It's not uncommon to have personal per-project configuration options (like sharing a target directory across related packages or sharing a rustflags definition).

Revantus commented 3 years ago

I can take a look at implementing this. Using the method in system.conf.d for priority loading based on reverse lexicographical sort. So that 99-personal.toml would overwrite 00-shared.toml. First pass implementation would be the single directory config storage and ignore folders inside the config.toml.d.

ensc commented 3 years ago

perhaps something like an include statement could be implemented. So, .cargo/config.toml could look like

[files]
include = "conf.d/*.toml"
include = "required.toml"
include = "-local.toml"
include = "-local-%h.toml"

When wildcards expand to null or when prefixed by -, files are optional (can be missing). Else, they are required.

The optional local.toml file above can contain e.g. local setup (like build.target-dir) and can be excluded e.g. in .gitignore.

Perhaps some placeholders can be implemented too:

This allows to share the source on NFS and set environment specifics configurations (e.g. paths)

jonhoo commented 3 years ago

There is already an unstable include feature that could maybe be extended that way: https://github.com/rust-lang/cargo/issues/7723

Revantus commented 3 years ago

That's what I was thinking as well. With the cli taking priority for load order.