Skip to content

Commit 066da36

Browse files
committed
improve debuginfo error message when build script fails
1 parent 779b3c1 commit 066da36

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
332332
// Need a separate copy for the fresh closure.
333333
let targets_fresh = targets.clone();
334334

335+
let env_profile_name = unit.profile.name.to_uppercase();
336+
335337
// Prepare the unit of "dirty work" which will actually run the custom build
336338
// command.
337339
//
@@ -406,15 +408,19 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
406408
true,
407409
)
408410
.with_context(|| {
409-
let mut build_error_context = format!("failed to run custom build command for `{}`", pkg_descr);
411+
let mut build_error_context =
412+
format!("failed to run custom build command for `{}`", pkg_descr);
410413

411414
// If we're opting into backtraces, mention that build dependencies' backtraces can
412415
// be improved by setting a higher debuginfo level.
413416
if let Ok(show_backtraces) = std::env::var("RUST_BACKTRACE") {
414417
if show_backtraces != "0" {
415-
build_error_context.push_str("\n\
416-
note: To improve backtraces for build dependencies, make sure full debug info is turned on. \
417-
More details at https://doc.rust-lang.org/cargo/reference/profiles.html#build-dependencies");
418+
build_error_context.push_str(&format!(
419+
"\n\
420+
note: To improve backtraces for build dependencies, set the \
421+
CARGO_PROFILE_{env_profile_name}_BUILD_OVERRIDE_DEBUG=true environment \
422+
variable to enable debug information generation.",
423+
));
418424
}
419425
}
420426

tests/testsuite/build_script.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,24 @@ fn custom_build_script_failed_backtraces_message() {
7777
[RUNNING] `rustc --crate-name build_script_build build.rs [..]--crate-type bin [..]`
7878
[RUNNING] `[..]/build-script-build`
7979
[ERROR] failed to run custom build command for `foo v0.5.0 ([CWD])`
80-
note: To improve backtraces for build dependencies[..]
80+
note: To improve backtraces for build dependencies, set the \
81+
CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG=true environment variable [..]
82+
83+
Caused by:
84+
process didn't exit successfully: `[..]/build-script-build` (exit [..]: 101)",
85+
)
86+
.run();
87+
88+
p.cargo("check -v")
89+
.env("RUST_BACKTRACE", "1")
90+
.with_status(101)
91+
.with_stderr(
92+
"\
93+
[COMPILING] foo v0.5.0 ([CWD])
94+
[RUNNING] `[..]/build-script-build`
95+
[ERROR] failed to run custom build command for `foo v0.5.0 ([CWD])`
96+
note: To improve backtraces for build dependencies, set the \
97+
CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG=true environment variable [..]
8198
8299
Caused by:
83100
process didn't exit successfully: `[..]/build-script-build` (exit [..]: 101)",

0 commit comments

Comments
 (0)