mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Use --keep-going
cargo flag when building build scripts
This commit is contained in:
parent
e1e93c4438
commit
950de7c3c3
4 changed files with 29 additions and 6 deletions
|
@ -12,6 +12,7 @@ use cargo_metadata::{camino::Utf8Path, Message};
|
||||||
use la_arena::ArenaMap;
|
use la_arena::ArenaMap;
|
||||||
use paths::AbsPathBuf;
|
use paths::AbsPathBuf;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
use semver::Version;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::{cfg_flag::CfgFlag, CargoConfig, CargoWorkspace, Package};
|
use crate::{cfg_flag::CfgFlag, CargoConfig, CargoWorkspace, Package};
|
||||||
|
@ -38,7 +39,7 @@ pub(crate) struct BuildScriptOutput {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WorkspaceBuildScripts {
|
impl WorkspaceBuildScripts {
|
||||||
fn build_command(config: &CargoConfig) -> Command {
|
fn build_command(config: &CargoConfig, toolchain: &Option<Version>) -> Command {
|
||||||
if let Some([program, args @ ..]) = config.run_build_script_command.as_deref() {
|
if let Some([program, args @ ..]) = config.run_build_script_command.as_deref() {
|
||||||
let mut cmd = Command::new(program);
|
let mut cmd = Command::new(program);
|
||||||
cmd.args(args);
|
cmd.args(args);
|
||||||
|
@ -70,6 +71,15 @@ impl WorkspaceBuildScripts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const RUST_1_62: Version = Version::new(1, 62, 0);
|
||||||
|
|
||||||
|
match toolchain {
|
||||||
|
Some(v) if v >= &RUST_1_62 => {
|
||||||
|
cmd.args(&["-Z", "unstable-options", "--keep-going"]).env("RUSTC_BOOTSTRAP", "1");
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
cmd
|
cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +87,9 @@ impl WorkspaceBuildScripts {
|
||||||
config: &CargoConfig,
|
config: &CargoConfig,
|
||||||
workspace: &CargoWorkspace,
|
workspace: &CargoWorkspace,
|
||||||
progress: &dyn Fn(String),
|
progress: &dyn Fn(String),
|
||||||
|
toolchain: &Option<Version>,
|
||||||
) -> io::Result<WorkspaceBuildScripts> {
|
) -> io::Result<WorkspaceBuildScripts> {
|
||||||
let mut cmd = Self::build_command(config);
|
let mut cmd = Self::build_command(config, toolchain);
|
||||||
|
|
||||||
if config.wrap_rustc_in_build_scripts {
|
if config.wrap_rustc_in_build_scripts {
|
||||||
// Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use
|
// Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use
|
||||||
|
|
|
@ -28,6 +28,7 @@ fn load_cargo_with_overrides(file: &str, cfg_overrides: CfgOverrides) -> CrateGr
|
||||||
rustc: None,
|
rustc: None,
|
||||||
rustc_cfg: Vec::new(),
|
rustc_cfg: Vec::new(),
|
||||||
cfg_overrides,
|
cfg_overrides,
|
||||||
|
toolchain: None,
|
||||||
};
|
};
|
||||||
to_crate_graph(project_workspace)
|
to_crate_graph(project_workspace)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ use base_db::{
|
||||||
use cfg::{CfgDiff, CfgOptions};
|
use cfg::{CfgDiff, CfgOptions};
|
||||||
use paths::{AbsPath, AbsPathBuf};
|
use paths::{AbsPath, AbsPathBuf};
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
|
use semver::Version;
|
||||||
use stdx::always;
|
use stdx::always;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -77,6 +78,7 @@ pub enum ProjectWorkspace {
|
||||||
/// different target.
|
/// different target.
|
||||||
rustc_cfg: Vec<CfgFlag>,
|
rustc_cfg: Vec<CfgFlag>,
|
||||||
cfg_overrides: CfgOverrides,
|
cfg_overrides: CfgOverrides,
|
||||||
|
toolchain: Option<Version>,
|
||||||
},
|
},
|
||||||
/// Project workspace was manually specified using a `rust-project.json` file.
|
/// Project workspace was manually specified using a `rust-project.json` file.
|
||||||
Json { project: ProjectJson, sysroot: Option<Sysroot>, rustc_cfg: Vec<CfgFlag> },
|
Json { project: ProjectJson, sysroot: Option<Sysroot>, rustc_cfg: Vec<CfgFlag> },
|
||||||
|
@ -105,6 +107,7 @@ impl fmt::Debug for ProjectWorkspace {
|
||||||
rustc,
|
rustc,
|
||||||
rustc_cfg,
|
rustc_cfg,
|
||||||
cfg_overrides,
|
cfg_overrides,
|
||||||
|
toolchain,
|
||||||
} => f
|
} => f
|
||||||
.debug_struct("Cargo")
|
.debug_struct("Cargo")
|
||||||
.field("root", &cargo.workspace_root().file_name())
|
.field("root", &cargo.workspace_root().file_name())
|
||||||
|
@ -116,6 +119,7 @@ impl fmt::Debug for ProjectWorkspace {
|
||||||
)
|
)
|
||||||
.field("n_rustc_cfg", &rustc_cfg.len())
|
.field("n_rustc_cfg", &rustc_cfg.len())
|
||||||
.field("n_cfg_overrides", &cfg_overrides.len())
|
.field("n_cfg_overrides", &cfg_overrides.len())
|
||||||
|
.field("toolchain", &toolchain)
|
||||||
.finish(),
|
.finish(),
|
||||||
ProjectWorkspace::Json { project, sysroot, rustc_cfg } => {
|
ProjectWorkspace::Json { project, sysroot, rustc_cfg } => {
|
||||||
let mut debug_struct = f.debug_struct("Json");
|
let mut debug_struct = f.debug_struct("Json");
|
||||||
|
@ -160,6 +164,9 @@ impl ProjectWorkspace {
|
||||||
cmd.arg("--version");
|
cmd.arg("--version");
|
||||||
cmd
|
cmd
|
||||||
})?;
|
})?;
|
||||||
|
let toolchain = cargo_version
|
||||||
|
.get("cargo ".len()..)
|
||||||
|
.and_then(|it| Version::parse(it.split_whitespace().next()?).ok());
|
||||||
|
|
||||||
let meta = CargoWorkspace::fetch_metadata(
|
let meta = CargoWorkspace::fetch_metadata(
|
||||||
&cargo_toml,
|
&cargo_toml,
|
||||||
|
@ -169,9 +176,9 @@ impl ProjectWorkspace {
|
||||||
)
|
)
|
||||||
.with_context(|| {
|
.with_context(|| {
|
||||||
format!(
|
format!(
|
||||||
"Failed to read Cargo metadata from Cargo.toml file {}, {}",
|
"Failed to read Cargo metadata from Cargo.toml file {}, {:?}",
|
||||||
cargo_toml.display(),
|
cargo_toml.display(),
|
||||||
cargo_version
|
toolchain
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
let cargo = CargoWorkspace::new(meta);
|
let cargo = CargoWorkspace::new(meta);
|
||||||
|
@ -219,6 +226,7 @@ impl ProjectWorkspace {
|
||||||
rustc,
|
rustc,
|
||||||
rustc_cfg,
|
rustc_cfg,
|
||||||
cfg_overrides,
|
cfg_overrides,
|
||||||
|
toolchain,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -271,8 +279,8 @@ impl ProjectWorkspace {
|
||||||
progress: &dyn Fn(String),
|
progress: &dyn Fn(String),
|
||||||
) -> Result<WorkspaceBuildScripts> {
|
) -> Result<WorkspaceBuildScripts> {
|
||||||
match self {
|
match self {
|
||||||
ProjectWorkspace::Cargo { cargo, .. } => {
|
ProjectWorkspace::Cargo { cargo, toolchain, .. } => {
|
||||||
WorkspaceBuildScripts::run(config, cargo, progress).with_context(|| {
|
WorkspaceBuildScripts::run(config, cargo, progress, toolchain).with_context(|| {
|
||||||
format!("Failed to run build scripts for {}", &cargo.workspace_root().display())
|
format!("Failed to run build scripts for {}", &cargo.workspace_root().display())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -320,6 +328,7 @@ impl ProjectWorkspace {
|
||||||
rustc_cfg: _,
|
rustc_cfg: _,
|
||||||
cfg_overrides: _,
|
cfg_overrides: _,
|
||||||
build_scripts,
|
build_scripts,
|
||||||
|
toolchain: _,
|
||||||
} => {
|
} => {
|
||||||
cargo
|
cargo
|
||||||
.packages()
|
.packages()
|
||||||
|
@ -425,6 +434,7 @@ impl ProjectWorkspace {
|
||||||
rustc_cfg,
|
rustc_cfg,
|
||||||
cfg_overrides,
|
cfg_overrides,
|
||||||
build_scripts,
|
build_scripts,
|
||||||
|
toolchain: _,
|
||||||
} => cargo_to_crate_graph(
|
} => cargo_to_crate_graph(
|
||||||
rustc_cfg.clone(),
|
rustc_cfg.clone(),
|
||||||
cfg_overrides,
|
cfg_overrides,
|
||||||
|
|
|
@ -219,6 +219,7 @@ impl GlobalState {
|
||||||
cfg_overrides,
|
cfg_overrides,
|
||||||
|
|
||||||
build_scripts: _,
|
build_scripts: _,
|
||||||
|
toolchain: _,
|
||||||
} => Some((cargo, sysroot, rustc, rustc_cfg, cfg_overrides)),
|
} => Some((cargo, sysroot, rustc, rustc_cfg, cfg_overrides)),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue