Skip to content

Commit 25d4fbe

Browse files
committed
Re-try build script building with --keep-going
1 parent 950de7c commit 25d4fbe

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

crates/project-model/src/build_scripts.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub(crate) struct BuildScriptOutput {
3939
}
4040

4141
impl WorkspaceBuildScripts {
42-
fn build_command(config: &CargoConfig, toolchain: &Option<Version>) -> Command {
42+
fn build_command(config: &CargoConfig) -> Command {
4343
if let Some([program, args @ ..]) = config.run_build_script_command.as_deref() {
4444
let mut cmd = Command::new(program);
4545
cmd.args(args);
@@ -71,26 +71,39 @@ impl WorkspaceBuildScripts {
7171
}
7272
}
7373

74+
cmd
75+
}
76+
77+
pub(crate) fn run(
78+
config: &CargoConfig,
79+
workspace: &CargoWorkspace,
80+
progress: &dyn Fn(String),
81+
toolchain: &Option<Version>,
82+
) -> io::Result<WorkspaceBuildScripts> {
7483
const RUST_1_62: Version = Version::new(1, 62, 0);
7584

76-
match toolchain {
77-
Some(v) if v >= &RUST_1_62 => {
85+
match Self::run_(Self::build_command(config), config, workspace, progress) {
86+
Ok(WorkspaceBuildScripts { error: Some(error), .. })
87+
if toolchain.as_ref().map_or(false, |it| *it >= RUST_1_62) =>
88+
{
89+
// building build scripts failed, attempt to build with --keep-going so
90+
// that we potentially get more build data
91+
let mut cmd = Self::build_command(config);
7892
cmd.args(&["-Z", "unstable-options", "--keep-going"]).env("RUSTC_BOOTSTRAP", "1");
93+
let mut res = Self::run_(cmd, config, workspace, progress)?;
94+
res.error = Some(error);
95+
Ok(res)
7996
}
80-
_ => (),
97+
res => res,
8198
}
82-
83-
cmd
8499
}
85100

86-
pub(crate) fn run(
101+
fn run_(
102+
mut cmd: Command,
87103
config: &CargoConfig,
88104
workspace: &CargoWorkspace,
89105
progress: &dyn Fn(String),
90-
toolchain: &Option<Version>,
91106
) -> io::Result<WorkspaceBuildScripts> {
92-
let mut cmd = Self::build_command(config, toolchain);
93-
94107
if config.wrap_rustc_in_build_scripts {
95108
// Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use
96109
// that to compile only proc macros and build scripts during the initial

0 commit comments

Comments
 (0)