Global cargo configuration
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
Research direction
Start in src/cargo/util/config/mod.rs, where Cargo searches for configuration files and the proposed system-wide path is shown. Read the existing configuration traversal and determine the expected Unix and Windows behavior before adding tests and documentation. Done means administrators can provide system-wide defaults through the supported location without disrupting existing configuration precedence.
Written by the indexing model from the issue text.
Description
Describe the problem you are trying to solve
I'm attempting to configure cargo (specifically, custom registries) on large, shared, many-user Linux servers. As far as I can tell, the best way to do that now is to create a file at /.cargo/config, which will be read by the logic that walks up the filesystem tree searching for a .cargo directory.
Describe the solution you'd like
Cargo should also read a config file from /etc/, similar to other Unix-y tools, allowing administrators to set system-wide defaults.
Notes
I believe that a diff such as the following accomplishes this, although it's obviously missing documentation, tests, and perhaps sane behavior on Windows:
diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs
index b9921dfee..57862ffdc 100644
--- a/src/cargo/util/config/mod.rs
+++ b/src/cargo/util/config/mod.rs
@@ -1302,6 +1302,15 @@ impl Config {
}
}
+ if cfg!(unix) {
+ // Also check system-wide config
+ if let Some(path) = self.get_file_path(Path::new("/etc/cargo"), "config", true)? {
+ if !stash.contains(&path) {
+ walk(&path)?;
+ }
+ }
+ }
+
Ok(())
}
If there's interest in such a feature, I'm glad to do the work to write tests & documentation; if there's not interest, I'd be interested in how other people are administering system-wide shared defaults.
NOTE: I initially asked about this at https://users.rust-lang.org/t/how-to-manage-system-wide-cargo-configuration-for-many-users/59160
- Dominant language
- Rust
- Stars
- 15.5k
- Forks
- 3k
- Avg merge
- 23h 30m
- Merged PRs (30d)
- 51
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rust-lang/cargo
-
C-bug S-triage
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
A-completions C-bug S-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
C-bug S-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Command-fix
Difficulty 1/5 Under an hour Newbie friendliness 82/100
-
cargo remove prints "Removing X" for dependencies that never get removed when the command fails OpenC-bug Command-remove S-triage
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100