Skip to content

Commit f76d2ef

Browse files
authored
Merge pull request #20178 from ShoyuVanilla/cargo-config-cleanup
chore: Cleanup cargo config queries
2 parents 27dca57 + d6bdcf2 commit f76d2ef

File tree

12 files changed

+419
-374
lines changed

12 files changed

+419
-374
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//! Read `.cargo/config.toml` as a JSON object
2+
use rustc_hash::FxHashMap;
3+
use toolchain::Tool;
4+
5+
use crate::{ManifestPath, Sysroot, utf8_stdout};
6+
7+
pub(crate) type CargoConfigFile = serde_json::Map<String, serde_json::Value>;
8+
9+
pub(crate) fn read(
10+
manifest: &ManifestPath,
11+
extra_env: &FxHashMap<String, Option<String>>,
12+
sysroot: &Sysroot,
13+
) -> Option<CargoConfigFile> {
14+
let mut cargo_config = sysroot.tool(Tool::Cargo, manifest.parent(), extra_env);
15+
cargo_config
16+
.args(["-Z", "unstable-options", "config", "get", "--format", "json"])
17+
.env("RUSTC_BOOTSTRAP", "1");
18+
if manifest.is_rust_manifest() {
19+
cargo_config.arg("-Zscript");
20+
}
21+
22+
tracing::debug!("Discovering cargo config by {:?}", cargo_config);
23+
let json: serde_json::Map<String, serde_json::Value> = utf8_stdout(&mut cargo_config)
24+
.inspect(|json| {
25+
tracing::debug!("Discovered cargo config: {:?}", json);
26+
})
27+
.inspect_err(|err| {
28+
tracing::debug!("Failed to discover cargo config: {:?}", err);
29+
})
30+
.ok()
31+
.and_then(|stdout| serde_json::from_str(&stdout).ok())?;
32+
33+
Some(json)
34+
}

0 commit comments

Comments
 (0)