Skip to content

Commit 624233b

Browse files
committed
Auto merge of #13659 - RalfJung:rustc-wrapper, r=ehuss
Make sure to also wrap the initial `-vV` invocation Fixes #10885 and therefore helps unblock rust-lang/miri#3422. This ensures that the version info actually matches the compiler that will later be doing the builds.
2 parents d19d2bc + 8a7ba8f commit 624233b

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1907,7 +1907,10 @@ fn descriptive_pkg_name(name: &str, target: &Target, mode: &CompileMode) -> Stri
19071907
}
19081908

19091909
/// Applies environment variables from config `[env]` to [`ProcessBuilder`].
1910-
fn apply_env_config(gctx: &crate::GlobalContext, cmd: &mut ProcessBuilder) -> CargoResult<()> {
1910+
pub(crate) fn apply_env_config(
1911+
gctx: &crate::GlobalContext,
1912+
cmd: &mut ProcessBuilder,
1913+
) -> CargoResult<()> {
19111914
for (key, value) in gctx.env_config()?.iter() {
19121915
// never override a value that has already been set by cargo
19131916
if cmd.get_envs().contains_key(key) {

src/cargo/util/rustc.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use cargo_util::{paths, ProcessBuilder, ProcessError};
99
use serde::{Deserialize, Serialize};
1010
use tracing::{debug, info, warn};
1111

12+
use crate::core::compiler::apply_env_config;
1213
use crate::util::interning::InternedString;
1314
use crate::util::{CargoResult, GlobalContext, StableHasher};
1415

@@ -57,7 +58,10 @@ impl Rustc {
5758
gctx,
5859
);
5960

60-
let mut cmd = ProcessBuilder::new(&path);
61+
let mut cmd = ProcessBuilder::new(&path)
62+
.wrapped(workspace_wrapper.as_ref())
63+
.wrapped(wrapper.as_deref());
64+
apply_env_config(gctx, &mut cmd)?;
6165
cmd.arg("-vV");
6266
let verbose_version = cache.cached_output(&cmd, 0)?.0;
6367

tests/testsuite/build.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5231,6 +5231,30 @@ fn rustc_wrapper_precendence() {
52315231
.run();
52325232
}
52335233

5234+
#[cargo_test]
5235+
fn rustc_wrapper_queries() {
5236+
// Check that the invocations querying rustc for information are done with the wrapper.
5237+
let p = project().file("src/lib.rs", "").build();
5238+
let wrapper = tools::echo_wrapper();
5239+
p.cargo("build")
5240+
.env("CARGO_LOG", "cargo::util::rustc=debug")
5241+
.env("RUSTC_WRAPPER", &wrapper)
5242+
.with_stderr_contains("[..]running [..]rustc-echo-wrapper[EXE] rustc -vV[..]")
5243+
.with_stderr_contains(
5244+
"[..]running [..]rustc-echo-wrapper[EXE] rustc - --crate-name ___ --print[..]",
5245+
)
5246+
.run();
5247+
p.build_dir().rm_rf();
5248+
p.cargo("build")
5249+
.env("CARGO_LOG", "cargo::util::rustc=debug")
5250+
.env("RUSTC_WORKSPACE_WRAPPER", &wrapper)
5251+
.with_stderr_contains("[..]running [..]rustc-echo-wrapper[EXE] rustc -vV[..]")
5252+
.with_stderr_contains(
5253+
"[..]running [..]rustc-echo-wrapper[EXE] rustc - --crate-name ___ --print[..]",
5254+
)
5255+
.run();
5256+
}
5257+
52345258
#[cargo_test]
52355259
fn rustc_wrapper_relative() {
52365260
Package::new("bar", "1.0.0").publish();

tests/testsuite/cargo_env_config.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,13 @@ fn env_applied_to_target_info_discovery_rustc() {
192192
"src/main.rs",
193193
r#"
194194
fn main() {
195-
let mut args = std::env::args().skip(1);
195+
let mut cmd = std::env::args().skip(1).collect::<Vec<_>>();
196+
// This will be invoked twice (with `-vV` and with all the `--print`),
197+
// make sure the environment variable exists each time.
196198
let env_test = std::env::var("ENV_TEST").unwrap();
197199
eprintln!("WRAPPER ENV_TEST:{env_test}");
198-
let status = std::process::Command::new(&args.next().unwrap())
200+
let (prog, args) = cmd.split_first().unwrap();
201+
let status = std::process::Command::new(prog)
199202
.args(args).status().unwrap();
200203
std::process::exit(status.code().unwrap_or(1));
201204
}

0 commit comments

Comments
 (0)