This commit is contained in:
Lukas Wirth 2022-09-19 17:31:08 +02:00
parent d9f5709609
commit a6c067c06d
14 changed files with 89 additions and 88 deletions

View file

@ -3,13 +3,14 @@
use std::process::Command;
use anyhow::Result;
use rustc_hash::FxHashMap;
use crate::{cfg_flag::CfgFlag, utf8_stdout, CargoConfig, ManifestPath};
use crate::{cfg_flag::CfgFlag, utf8_stdout, ManifestPath};
pub(crate) fn get(
cargo_toml: Option<&ManifestPath>,
target: Option<&str>,
config: &CargoConfig,
extra_env: &FxHashMap<String, String>,
) -> Vec<CfgFlag> {
let _p = profile::span("rustc_cfg::get");
let mut res = Vec::with_capacity(6 * 2 + 1);
@ -22,7 +23,7 @@ pub(crate) fn get(
}
}
match get_rust_cfgs(cargo_toml, target, config) {
match get_rust_cfgs(cargo_toml, target, extra_env) {
Ok(rustc_cfgs) => {
tracing::debug!(
"rustc cfgs found: {:?}",
@ -42,11 +43,11 @@ pub(crate) fn get(
fn get_rust_cfgs(
cargo_toml: Option<&ManifestPath>,
target: Option<&str>,
config: &CargoConfig,
extra_env: &FxHashMap<String, String>,
) -> Result<String> {
if let Some(cargo_toml) = cargo_toml {
let mut cargo_config = Command::new(toolchain::cargo());
cargo_config.envs(&config.extra_env);
cargo_config.envs(extra_env);
cargo_config
.current_dir(cargo_toml.parent())
.args(&["-Z", "unstable-options", "rustc", "--print", "cfg"])
@ -61,7 +62,7 @@ fn get_rust_cfgs(
}
// using unstable cargo features failed, fall back to using plain rustc
let mut cmd = Command::new(toolchain::rustc());
cmd.envs(&config.extra_env);
cmd.envs(extra_env);
cmd.args(&["--print", "cfg", "-O"]);
if let Some(target) = target {
cmd.args(&["--target", target]);