Use RUSTC_BOOTSTRAP=1 instead of +nightly when discovering rust_cfgs throughs cargo
This commit is contained in:
parent
8989fb8315
commit
b7e6537935
@ -375,14 +375,10 @@ fn rustc_discover_host_triple(cargo_toml: &AbsPath) -> Option<String> {
|
||||
|
||||
fn cargo_config_build_target(cargo_toml: &AbsPath) -> Option<String> {
|
||||
let mut cargo_config = Command::new(toolchain::cargo());
|
||||
cargo_config.current_dir(cargo_toml.parent().unwrap()).args(&[
|
||||
"+nightly",
|
||||
"-Z",
|
||||
"unstable-options",
|
||||
"config",
|
||||
"get",
|
||||
"build.target",
|
||||
]);
|
||||
cargo_config
|
||||
.current_dir(cargo_toml.parent().unwrap())
|
||||
.args(&["-Z", "unstable-options", "config", "get", "build.target"])
|
||||
.env("RUSTC_BOOTSTRAP", "1");
|
||||
// if successful we receive `build.target = "target-triple"`
|
||||
log::debug!("Discovering cargo config target by {:?}", cargo_config);
|
||||
match utf8_stdout(cargo_config) {
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
use std::process::Command;
|
||||
|
||||
use anyhow::Result;
|
||||
use paths::AbsPath;
|
||||
|
||||
use crate::{cfg_flag::CfgFlag, utf8_stdout};
|
||||
@ -18,41 +19,39 @@ pub(crate) fn get(cargo_toml: Option<&AbsPath>, target: Option<&str>) -> Vec<Cfg
|
||||
}
|
||||
}
|
||||
|
||||
let rustc_cfgs = {
|
||||
cargo_toml
|
||||
.and_then(|cargo_toml| {
|
||||
let mut cargo_config = Command::new(toolchain::cargo());
|
||||
cargo_config.current_dir(cargo_toml.parent().unwrap()).args(&[
|
||||
"+nightly",
|
||||
"-Z",
|
||||
"unstable-options",
|
||||
"rustc",
|
||||
"--print",
|
||||
"cfg",
|
||||
]);
|
||||
if let Some(target) = target {
|
||||
cargo_config.args(&["--target", target]);
|
||||
}
|
||||
utf8_stdout(cargo_config).ok()
|
||||
})
|
||||
.map_or_else(
|
||||
|| {
|
||||
// using unstable cargo features failed, fall back to using plain rustc
|
||||
let mut cmd = Command::new(toolchain::rustc());
|
||||
cmd.args(&["--print", "cfg", "-O"]);
|
||||
if let Some(target) = target {
|
||||
cmd.args(&["--target", target]);
|
||||
}
|
||||
utf8_stdout(cmd)
|
||||
},
|
||||
Ok,
|
||||
)
|
||||
};
|
||||
|
||||
match rustc_cfgs {
|
||||
match get_rust_cfgs(cargo_toml, target) {
|
||||
Ok(rustc_cfgs) => res.extend(rustc_cfgs.lines().map(|it| it.parse().unwrap())),
|
||||
Err(e) => log::error!("failed to get rustc cfgs: {:#}", e),
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
fn get_rust_cfgs(cargo_toml: Option<&AbsPath>, target: Option<&str>) -> Result<String> {
|
||||
let cargo_rust_cfgs = match cargo_toml {
|
||||
Some(cargo_toml) => {
|
||||
let mut cargo_config = Command::new(toolchain::cargo());
|
||||
cargo_config
|
||||
.current_dir(cargo_toml.parent().unwrap())
|
||||
.args(&["-Z", "unstable-options", "rustc", "--print", "cfg"])
|
||||
.env("RUSTC_BOOTSTRAP", "1");
|
||||
if let Some(target) = target {
|
||||
cargo_config.args(&["--target", target]);
|
||||
}
|
||||
utf8_stdout(cargo_config).ok()
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
match cargo_rust_cfgs {
|
||||
Some(stdout) => Ok(stdout),
|
||||
None => {
|
||||
// using unstable cargo features failed, fall back to using plain rustc
|
||||
let mut cmd = Command::new(toolchain::rustc());
|
||||
cmd.args(&["--print", "cfg", "-O"]);
|
||||
if let Some(target) = target {
|
||||
cmd.args(&["--target", target]);
|
||||
}
|
||||
utf8_stdout(cmd)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user