Skip to content

Commit a275529

Browse files
committed
Auto merge of #12829 - Nilstrieb:verbosebuildrs, r=weihanglo
Print environment variables for build script executions with `-vv` ### What does this PR try to resolve? When debugging complicated builds (I was trying to figure out how `cargo-miri` cross-compiles compiler_builtins without needing a C cross compiler), it's useful to see all the environment variables passed to the build script. This is also consistent with other commands. ### How should we test and review this PR? I tested it locally by creating a small crate with an empty `build.rs` and building it. Additionally, a test is included.
2 parents 709ac17 + d4044c9 commit a275529

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
353353
);
354354
cmd.env_remove("RUSTFLAGS");
355355

356+
if cx.bcx.ws.config().extra_verbose() {
357+
cmd.display_env_vars();
358+
}
359+
356360
// Gather the set of native dependencies that this package has along with
357361
// some other variables to close over.
358362
//

tests/testsuite/build_script_env.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,22 @@ fn rustc_bootstrap() {
180180
.run();
181181
}
182182

183+
#[cargo_test]
184+
fn build_script_env_verbose() {
185+
let build_rs = r#"
186+
fn main() {}
187+
"#;
188+
let p = project()
189+
.file("Cargo.toml", &basic_manifest("verbose-build", "0.0.1"))
190+
.file("src/lib.rs", "")
191+
.file("build.rs", build_rs)
192+
.build();
193+
194+
p.cargo("check -vv")
195+
.with_stderr_contains("[RUNNING] `[..]CARGO=[..]build-script-build`")
196+
.run();
197+
}
198+
183199
#[cargo_test]
184200
#[cfg(target_arch = "x86_64")]
185201
fn build_script_sees_cfg_target_feature() {

0 commit comments

Comments
 (0)