Skip to content

Commit 5941dec

Browse files
committed
Auto merge of rust-lang#13010 - Veykril:build-script-probes, r=Veykril
Do not unconditionally succeed RUSTC_WRAPPER checks when run by build scripts rust-analyzer's RUSTC_WRAPPER 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.
2 parents f982c76 + 72ae308 commit 5941dec

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

crates/rust-analyzer/src/bin/rustc_wrapper.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ pub(crate) fn run_rustc_skipping_cargo_checking(
1717
rustc_executable: OsString,
1818
args: Vec<OsString>,
1919
) -> io::Result<ExitCode> {
20+
// `CARGO_CFG_TARGET_ARCH` is only set by cargo when executing build scripts
21+
// We don't want to exit out checks unconditionally with success if a build
22+
// script tries to invoke checks themselves
23+
// See https://github.com/rust-lang/rust-analyzer/issues/12973 for context
24+
let not_invoked_by_build_script = std::env::var_os("CARGO_CFG_TARGET_ARCH").is_none();
2025
let is_cargo_check = args.iter().any(|arg| {
2126
let arg = arg.to_string_lossy();
2227
// `cargo check` invokes `rustc` with `--emit=metadata` argument.
@@ -29,7 +34,7 @@ pub(crate) fn run_rustc_skipping_cargo_checking(
2934
// The default output filename is CRATE_NAME.rmeta.
3035
arg.starts_with("--emit=") && arg.contains("metadata") && !arg.contains("link")
3136
});
32-
if is_cargo_check {
37+
if not_invoked_by_build_script && is_cargo_check {
3338
return Ok(ExitCode(Some(0)));
3439
}
3540
run_rustc(rustc_executable, args)

0 commit comments

Comments
 (0)