diff --git a/crates/project-model/src/build_scripts.rs b/crates/project-model/src/build_scripts.rs index 84e772d1684a..5ccd9d3e31e9 100644 --- a/crates/project-model/src/build_scripts.rs +++ b/crates/project-model/src/build_scripts.rs @@ -82,15 +82,16 @@ impl WorkspaceBuildScripts { ) -> io::Result { const RUST_1_62: Version = Version::new(1, 62, 0); - match Self::run_(Self::build_command(config), config, workspace, progress) { + match Self::run_(Self::build_command(config), workspace, progress) { Ok(WorkspaceBuildScripts { error: Some(error), .. }) if toolchain.as_ref().map_or(false, |it| *it >= RUST_1_62) => { + tracing::info!("running build scripts failed, retrying with --keep-going flag"); // building build scripts failed, attempt to build with --keep-going so // that we potentially get more build data let mut cmd = Self::build_command(config); cmd.args(&["-Z", "unstable-options", "--keep-going"]).env("RUSTC_BOOTSTRAP", "1"); - let mut res = Self::run_(cmd, config, workspace, progress)?; + let mut res = Self::run_(cmd, workspace, progress)?; res.error = Some(error); Ok(res) } @@ -100,19 +101,9 @@ impl WorkspaceBuildScripts { fn run_( mut cmd: Command, - config: &CargoConfig, workspace: &CargoWorkspace, progress: &dyn Fn(String), ) -> io::Result { - if config.wrap_rustc_in_build_scripts { - // Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use - // that to compile only proc macros and build scripts during the initial - // `cargo check`. - let myself = std::env::current_exe()?; - cmd.env("RUSTC_WRAPPER", myself); - cmd.env("RA_RUSTC_WRAPPER", "1"); - } - cmd.current_dir(workspace.workspace_root()); let mut res = WorkspaceBuildScripts::default(); diff --git a/crates/project-model/src/cargo_workspace.rs b/crates/project-model/src/cargo_workspace.rs index eed955b42daa..d825556e364e 100644 --- a/crates/project-model/src/cargo_workspace.rs +++ b/crates/project-model/src/cargo_workspace.rs @@ -95,8 +95,6 @@ pub struct CargoConfig { /// crates to disable `#[cfg(test)]` on pub unset_test_crates: UnsetTestCrates, - pub wrap_rustc_in_build_scripts: bool, - pub run_build_script_command: Option>, } diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index e9de23cb395d..6c6f963aba3c 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs @@ -5,7 +5,6 @@ #![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)] mod logger; -mod rustc_wrapper; use std::{env, fs, path::Path, process}; @@ -23,20 +22,6 @@ static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; fn main() { - if std::env::var("RA_RUSTC_WRAPPER").is_ok() { - let mut args = std::env::args_os(); - let _me = args.next().unwrap(); - let rustc = args.next().unwrap(); - let code = match rustc_wrapper::run_rustc_skipping_cargo_checking(rustc, args.collect()) { - Ok(rustc_wrapper::ExitCode(code)) => code.unwrap_or(102), - Err(err) => { - eprintln!("{}", err); - 101 - } - }; - process::exit(code); - } - if let Err(err) = try_main() { tracing::error!("Unexpected error: {}", err); eprintln!("{}", err); diff --git a/crates/rust-analyzer/src/bin/rustc_wrapper.rs b/crates/rust-analyzer/src/bin/rustc_wrapper.rs deleted file mode 100644 index 2f6d4706d879..000000000000 --- a/crates/rust-analyzer/src/bin/rustc_wrapper.rs +++ /dev/null @@ -1,46 +0,0 @@ -//! We setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself during the -//! initial `cargo check`. That way, we avoid checking the actual project, and -//! only build proc macros and build.rs. -//! -//! Code taken from IntelliJ :0) -//! https://github.com/intellij-rust/intellij-rust/blob/master/native-helper/src/main.rs -use std::{ - ffi::OsString, - io, - process::{Command, Stdio}, -}; - -/// ExitCode/ExitStatus are impossible to create :(. -pub(crate) struct ExitCode(pub(crate) Option); - -pub(crate) fn run_rustc_skipping_cargo_checking( - rustc_executable: OsString, - args: Vec, -) -> io::Result { - let is_cargo_check = args.iter().any(|arg| { - let arg = arg.to_string_lossy(); - // `cargo check` invokes `rustc` with `--emit=metadata` argument. - // - // https://doc.rust-lang.org/rustc/command-line-arguments.html#--emit-specifies-the-types-of-output-files-to-generate - // link — Generates the crates specified by --crate-type. The default - // output filenames depend on the crate type and platform. This - // is the default if --emit is not specified. - // metadata — Generates a file containing metadata about the crate. - // The default output filename is CRATE_NAME.rmeta. - arg.starts_with("--emit=") && arg.contains("metadata") && !arg.contains("link") - }); - if is_cargo_check { - return Ok(ExitCode(Some(0))); - } - run_rustc(rustc_executable, args) -} - -fn run_rustc(rustc_executable: OsString, args: Vec) -> io::Result { - let mut child = Command::new(rustc_executable) - .args(args) - .stdin(Stdio::inherit()) - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) - .spawn()?; - Ok(ExitCode(child.wait()?.code())) -} diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 1629c1dd328a..0a8574823bb2 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -80,9 +80,6 @@ config_data! { /// ``` /// . cargo_buildScripts_overrideCommand: Option> = "null", - /// Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to - /// avoid checking unnecessary things. - cargo_buildScripts_useRustcWrapper: bool = "true", /// List of features to activate. /// /// Set this to `"all"` to pass `--all-features` to cargo. @@ -960,7 +957,6 @@ impl Config { no_sysroot: self.data.cargo_noSysroot, rustc_source, unset_test_crates: UnsetTestCrates::Only(self.data.cargo_unsetTest.clone()), - wrap_rustc_in_build_scripts: self.data.cargo_buildScripts_useRustcWrapper, run_build_script_command: self.data.cargo_buildScripts_overrideCommand.clone(), } } diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index b0f2f1614dbf..0f73b67c786d 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -40,12 +40,6 @@ cargo check --quiet --workspace --message-format=json --all-targets ``` . -- -[[rust-analyzer.cargo.buildScripts.useRustcWrapper]]rust-analyzer.cargo.buildScripts.useRustcWrapper (default: `true`):: -+ --- -Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to -avoid checking unnecessary things. --- [[rust-analyzer.cargo.features]]rust-analyzer.cargo.features (default: `[]`):: + -- diff --git a/editors/code/package.json b/editors/code/package.json index fbdc69c80137..3619cd106001 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -432,11 +432,6 @@ "type": "string" } }, - "rust-analyzer.cargo.buildScripts.useRustcWrapper": { - "markdownDescription": "Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to\navoid checking unnecessary things.", - "default": true, - "type": "boolean" - }, "rust-analyzer.cargo.features": { "markdownDescription": "List of features to activate.\n\nSet this to `\"all\"` to pass `--all-features` to cargo.", "default": [],