Skip to content

Commit b7e6537

Browse files
committed
Use RUSTC_BOOTSTRAP=1 instead of +nightly when discovering rust_cfgs throughs cargo
1 parent 8989fb8 commit b7e6537

File tree

2 files changed

+35
-40
lines changed

2 files changed

+35
-40
lines changed

crates/project_model/src/cargo_workspace.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,10 @@ fn rustc_discover_host_triple(cargo_toml: &AbsPath) -> Option<String> {
375375

376376
fn cargo_config_build_target(cargo_toml: &AbsPath) -> Option<String> {
377377
let mut cargo_config = Command::new(toolchain::cargo());
378-
cargo_config.current_dir(cargo_toml.parent().unwrap()).args(&[
379-
"+nightly",
380-
"-Z",
381-
"unstable-options",
382-
"config",
383-
"get",
384-
"build.target",
385-
]);
378+
cargo_config
379+
.current_dir(cargo_toml.parent().unwrap())
380+
.args(&["-Z", "unstable-options", "config", "get", "build.target"])
381+
.env("RUSTC_BOOTSTRAP", "1");
386382
// if successful we receive `build.target = "target-triple"`
387383
log::debug!("Discovering cargo config target by {:?}", cargo_config);
388384
match utf8_stdout(cargo_config) {

crates/project_model/src/rustc_cfg.rs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::process::Command;
44

5+
use anyhow::Result;
56
use paths::AbsPath;
67

78
use crate::{cfg_flag::CfgFlag, utf8_stdout};
@@ -18,41 +19,39 @@ pub(crate) fn get(cargo_toml: Option<&AbsPath>, target: Option<&str>) -> Vec<Cfg
1819
}
1920
}
2021

21-
let rustc_cfgs = {
22-
cargo_toml
23-
.and_then(|cargo_toml| {
24-
let mut cargo_config = Command::new(toolchain::cargo());
25-
cargo_config.current_dir(cargo_toml.parent().unwrap()).args(&[
26-
"+nightly",
27-
"-Z",
28-
"unstable-options",
29-
"rustc",
30-
"--print",
31-
"cfg",
32-
]);
33-
if let Some(target) = target {
34-
cargo_config.args(&["--target", target]);
35-
}
36-
utf8_stdout(cargo_config).ok()
37-
})
38-
.map_or_else(
39-
|| {
40-
// using unstable cargo features failed, fall back to using plain rustc
41-
let mut cmd = Command::new(toolchain::rustc());
42-
cmd.args(&["--print", "cfg", "-O"]);
43-
if let Some(target) = target {
44-
cmd.args(&["--target", target]);
45-
}
46-
utf8_stdout(cmd)
47-
},
48-
Ok,
49-
)
50-
};
51-
52-
match rustc_cfgs {
22+
match get_rust_cfgs(cargo_toml, target) {
5323
Ok(rustc_cfgs) => res.extend(rustc_cfgs.lines().map(|it| it.parse().unwrap())),
5424
Err(e) => log::error!("failed to get rustc cfgs: {:#}", e),
5525
}
5626

5727
res
5828
}
29+
30+
fn get_rust_cfgs(cargo_toml: Option<&AbsPath>, target: Option<&str>) -> Result<String> {
31+
let cargo_rust_cfgs = match cargo_toml {
32+
Some(cargo_toml) => {
33+
let mut cargo_config = Command::new(toolchain::cargo());
34+
cargo_config
35+
.current_dir(cargo_toml.parent().unwrap())
36+
.args(&["-Z", "unstable-options", "rustc", "--print", "cfg"])
37+
.env("RUSTC_BOOTSTRAP", "1");
38+
if let Some(target) = target {
39+
cargo_config.args(&["--target", target]);
40+
}
41+
utf8_stdout(cargo_config).ok()
42+
}
43+
None => None,
44+
};
45+
match cargo_rust_cfgs {
46+
Some(stdout) => Ok(stdout),
47+
None => {
48+
// using unstable cargo features failed, fall back to using plain rustc
49+
let mut cmd = Command::new(toolchain::rustc());
50+
cmd.args(&["--print", "cfg", "-O"]);
51+
if let Some(target) = target {
52+
cmd.args(&["--target", target]);
53+
}
54+
utf8_stdout(cmd)
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)