From b7e6537935d421afd7e02585aaa5cec92bee63b0 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 9 May 2021 00:07:04 +0200 Subject: Use RUSTC_BOOTSTRAP=1 instead of +nightly when discovering rust_cfgs throughs cargo --- crates/project_model/src/cargo_workspace.rs | 12 ++---- crates/project_model/src/rustc_cfg.rs | 63 ++++++++++++++--------------- 2 files changed, 35 insertions(+), 40 deletions(-) (limited to 'crates/project_model') diff --git a/crates/project_model/src/cargo_workspace.rs b/crates/project_model/src/cargo_workspace.rs index f1ad00d36..b18699b77 100644 --- a/crates/project_model/src/cargo_workspace.rs +++ b/crates/project_model/src/cargo_workspace.rs @@ -375,14 +375,10 @@ fn rustc_discover_host_triple(cargo_toml: &AbsPath) -> Option { fn cargo_config_build_target(cargo_toml: &AbsPath) -> Option { 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) { diff --git a/crates/project_model/src/rustc_cfg.rs b/crates/project_model/src/rustc_cfg.rs index 6de40cfe2..012eab256 100644 --- a/crates/project_model/src/rustc_cfg.rs +++ b/crates/project_model/src/rustc_cfg.rs @@ -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 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 { + 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) + } + } +} -- cgit v1.2.3