From d4044c9d01ae1a441a4320c11aaba625076dfaf9 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 15 Oct 2023 17:50:19 +0200 Subject: [PATCH] Print environment variables for build script executions with `-vv` This is consistent with other commands. --- src/cargo/core/compiler/custom_build.rs | 4 ++++ tests/testsuite/build_script_env.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 3eeeaa0ee1e..01e2b37e710 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -353,6 +353,10 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { ); cmd.env_remove("RUSTFLAGS"); + if cx.bcx.ws.config().extra_verbose() { + cmd.display_env_vars(); + } + // Gather the set of native dependencies that this package has along with // some other variables to close over. // diff --git a/tests/testsuite/build_script_env.rs b/tests/testsuite/build_script_env.rs index badde3391ef..afa2925f147 100644 --- a/tests/testsuite/build_script_env.rs +++ b/tests/testsuite/build_script_env.rs @@ -180,6 +180,22 @@ fn rustc_bootstrap() { .run(); } +#[cargo_test] +fn build_script_env_verbose() { + let build_rs = r#" + fn main() {} + "#; + let p = project() + .file("Cargo.toml", &basic_manifest("verbose-build", "0.0.1")) + .file("src/lib.rs", "") + .file("build.rs", build_rs) + .build(); + + p.cargo("check -vv") + .with_stderr_contains("[RUNNING] `[..]CARGO=[..]build-script-build`") + .run(); +} + #[cargo_test] #[cfg(target_arch = "x86_64")] fn build_script_sees_cfg_target_feature() {