Use RUSTC_BOOTSTRAP=1 instead of +nightly when discovering rust_cfgs throughs cargo

This commit is contained in:
Lukas Wirth 2021-05-09 00:07:04 +02:00
parent 8989fb8315
commit b7e6537935
2 changed files with 35 additions and 40 deletions

View File

@ -375,14 +375,10 @@ fn rustc_discover_host_triple(cargo_toml: &AbsPath) -> Option<String> {
fn cargo_config_build_target(cargo_toml: &AbsPath) -> Option<String> { fn cargo_config_build_target(cargo_toml: &AbsPath) -> Option<String> {
let mut cargo_config = Command::new(toolchain::cargo()); let mut cargo_config = Command::new(toolchain::cargo());
cargo_config.current_dir(cargo_toml.parent().unwrap()).args(&[ cargo_config
"+nightly", .current_dir(cargo_toml.parent().unwrap())
"-Z", .args(&["-Z", "unstable-options", "config", "get", "build.target"])
"unstable-options", .env("RUSTC_BOOTSTRAP", "1");
"config",
"get",
"build.target",
]);
// if successful we receive `build.target = "target-triple"` // if successful we receive `build.target = "target-triple"`
log::debug!("Discovering cargo config target by {:?}", cargo_config); log::debug!("Discovering cargo config target by {:?}", cargo_config);
match utf8_stdout(cargo_config) { match utf8_stdout(cargo_config) {

View File

@ -2,6 +2,7 @@
use std::process::Command; use std::process::Command;
use anyhow::Result;
use paths::AbsPath; use paths::AbsPath;
use crate::{cfg_flag::CfgFlag, utf8_stdout}; use crate::{cfg_flag::CfgFlag, utf8_stdout};
@ -18,25 +19,32 @@ pub(crate) fn get(cargo_toml: Option<&AbsPath>, target: Option<&str>) -> Vec<Cfg
} }
} }
let rustc_cfgs = { match get_rust_cfgs(cargo_toml, target) {
cargo_toml Ok(rustc_cfgs) => res.extend(rustc_cfgs.lines().map(|it| it.parse().unwrap())),
.and_then(|cargo_toml| { 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()); let mut cargo_config = Command::new(toolchain::cargo());
cargo_config.current_dir(cargo_toml.parent().unwrap()).args(&[ cargo_config
"+nightly", .current_dir(cargo_toml.parent().unwrap())
"-Z", .args(&["-Z", "unstable-options", "rustc", "--print", "cfg"])
"unstable-options", .env("RUSTC_BOOTSTRAP", "1");
"rustc",
"--print",
"cfg",
]);
if let Some(target) = target { if let Some(target) = target {
cargo_config.args(&["--target", target]); cargo_config.args(&["--target", target]);
} }
utf8_stdout(cargo_config).ok() utf8_stdout(cargo_config).ok()
}) }
.map_or_else( None => None,
|| { };
match cargo_rust_cfgs {
Some(stdout) => Ok(stdout),
None => {
// using unstable cargo features failed, fall back to using plain rustc // using unstable cargo features failed, fall back to using plain rustc
let mut cmd = Command::new(toolchain::rustc()); let mut cmd = Command::new(toolchain::rustc());
cmd.args(&["--print", "cfg", "-O"]); cmd.args(&["--print", "cfg", "-O"]);
@ -44,15 +52,6 @@ pub(crate) fn get(cargo_toml: Option<&AbsPath>, target: Option<&str>) -> Vec<Cfg
cmd.args(&["--target", target]); cmd.args(&["--target", target]);
} }
utf8_stdout(cmd) utf8_stdout(cmd)
},
Ok,
)
};
match rustc_cfgs {
Ok(rustc_cfgs) => res.extend(rustc_cfgs.lines().map(|it| it.parse().unwrap())),
Err(e) => log::error!("failed to get rustc cfgs: {:#}", e),
} }
}
res
} }