Skip to content

Commit cbe129a

Browse files
committed
Do not unconditionally succeed RUSTC_WRAPPER when run by build scripts
intellij-rust-native-helper in `RUSTC_WRAPPER` role unconditionally succeeds `cargo check` invocations tripping up build scripts using `cargo check` to probe for successful compilations. To prevent this from happening the `RUSTC_WRAPPER` now checks if it's run from a build script by looking for the `CARGO_CFG_TARGET_ARCH` env var that cargo sets only when running build scripts.
1 parent ebcedfa commit cbe129a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

native-helper/src/rustc_wrapper.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
use std::ffi::OsString;
2-
use std::process::{Command, Stdio};
32
use std::io;
3+
use std::process::{Command, Stdio};
44

55
pub struct ExitCode(pub Option<i32>);
66

77
pub fn run_rustc_skipping_cargo_checking(
88
rustc_executable: OsString,
99
args: Vec<OsString>,
1010
) -> io::Result<ExitCode> {
11+
// `CARGO_CFG_TARGET_ARCH` is only set by cargo when executing build scripts
12+
// We don't want to exit out checks unconditionally with success if a build
13+
// script tries to invoke checks themselves
14+
// See https://github.com/rust-lang/rust-analyzer/issues/12973 for context
15+
let is_invoked_by_build_script = std::env::var_os("CARGO_CFG_TARGET_ARCH").is_some();
16+
1117
let is_cargo_check = args.iter().any(|arg| {
1218
let arg = arg.to_string_lossy();
1319
// `cargo check` invokes `rustc` with `--emit=metadata` argument.
@@ -20,7 +26,7 @@ pub fn run_rustc_skipping_cargo_checking(
2026
// The default output filename is CRATE_NAME.rmeta.
2127
arg.starts_with("--emit=") && arg.contains("metadata") && !arg.contains("link")
2228
});
23-
if is_cargo_check {
29+
if !is_invoked_by_build_script && is_cargo_check {
2430
return Ok(ExitCode(Some(0)));
2531
}
2632
run_rustc(rustc_executable, args)

0 commit comments

Comments
 (0)