Skip to content

Commit 54d8815

Browse files
committed
Auto merge of #13653 - weihanglo:rust-1.78.0-backport, r=epage
[beta-1.78] Do not strip debuginfo by default for MSVC Beta backports: - #13630 In order to make CI pass, the following PRs are also cherry-picked: -
2 parents fd4fd37 + fbf8b9f commit 54d8815

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/cargo/ops/cargo_compile/mod.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
//! [`drain_the_queue`]: crate::core::compiler::job_queue
3636
//! ["Cargo Target"]: https://doc.rust-lang.org/nightly/cargo/reference/cargo-targets.html
3737
38+
use cargo_platform::Cfg;
3839
use std::collections::{HashMap, HashSet};
3940
use std::hash::{Hash, Hasher};
4041
use std::sync::Arc;
@@ -442,6 +443,7 @@ pub fn create_bcx<'a, 'gctx>(
442443
&units,
443444
&scrape_units,
444445
host_kind_requested.then_some(explicit_host_kind),
446+
&target_data,
445447
);
446448
}
447449

@@ -573,6 +575,7 @@ fn rebuild_unit_graph_shared(
573575
roots: &[Unit],
574576
scrape_units: &[Unit],
575577
to_host: Option<CompileKind>,
578+
target_data: &RustcTargetData<'_>,
576579
) -> (Vec<Unit>, Vec<Unit>, UnitGraph) {
577580
let mut result = UnitGraph::new();
578581
// Map of the old unit to the new unit, used to avoid recursing into units
@@ -589,6 +592,7 @@ fn rebuild_unit_graph_shared(
589592
root,
590593
false,
591594
to_host,
595+
target_data,
592596
)
593597
})
594598
.collect();
@@ -615,6 +619,7 @@ fn traverse_and_share(
615619
unit: &Unit,
616620
unit_is_for_host: bool,
617621
to_host: Option<CompileKind>,
622+
target_data: &RustcTargetData<'_>,
618623
) -> Unit {
619624
if let Some(new_unit) = memo.get(unit) {
620625
// Already computed, no need to recompute.
@@ -632,6 +637,7 @@ fn traverse_and_share(
632637
&dep.unit,
633638
dep.unit_for.is_for_host(),
634639
to_host,
640+
target_data,
635641
);
636642
new_dep_unit.hash(&mut dep_hash);
637643
UnitDep {
@@ -655,8 +661,13 @@ fn traverse_and_share(
655661
_ => unit.kind,
656662
};
657663

664+
let cfg = target_data.cfg(unit.kind);
665+
let is_target_windows_msvc = cfg.contains(&Cfg::Name("windows".to_string()))
666+
&& cfg.contains(&Cfg::KeyPair("target_env".to_string(), "msvc".to_string()));
658667
let mut profile = unit.profile.clone();
659-
if profile.strip.is_deferred() {
668+
// For MSVC, rustc currently treats -Cstrip=debuginfo same as -Cstrip=symbols, which causes
669+
// this optimization to also remove symbols and thus break backtraces.
670+
if profile.strip.is_deferred() && !is_target_windows_msvc {
660671
// If strip was not manually set, and all dependencies of this unit together
661672
// with this unit have debuginfo turned off, we enable debuginfo stripping.
662673
// This will remove pre-existing debug symbols coming from the standard library.

tests/testsuite/profiles.rs

+27
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,9 @@ fn strip_accepts_false_to_disable_strip() {
630630
.run();
631631
}
632632

633+
// Temporarily disabled on Windows due to https://github.com/rust-lang/rust/issues/122857
633634
#[cargo_test]
635+
#[cfg(not(windows))]
634636
fn strip_debuginfo_in_release() {
635637
let p = project()
636638
.file(
@@ -650,7 +652,32 @@ fn strip_debuginfo_in_release() {
650652
.run();
651653
}
652654

655+
// Using -Cstrip=debuginfo in release mode by default is temporarily disabled on Windows due to
656+
// https://github.com/rust-lang/rust/issues/122857
653657
#[cargo_test]
658+
#[cfg(all(target_os = "windows", target_env = "msvc"))]
659+
fn do_not_strip_debuginfo_in_release_on_windows() {
660+
let p = project()
661+
.file(
662+
"Cargo.toml",
663+
r#"
664+
[package]
665+
name = "foo"
666+
version = "0.1.0"
667+
edition = "2015"
668+
"#,
669+
)
670+
.file("src/main.rs", "fn main() {}")
671+
.build();
672+
673+
p.cargo("build --release -v")
674+
.with_stderr_does_not_contain("[..]strip=debuginfo[..]")
675+
.run();
676+
}
677+
678+
// Temporarily disabled on Windows due to https://github.com/rust-lang/rust/issues/122857
679+
#[cargo_test]
680+
#[cfg(not(windows))]
654681
fn strip_debuginfo_without_debug() {
655682
let p = project()
656683
.file(

tests/testsuite/run.rs

+2
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,9 @@ fn one_bin_multiple_examples() {
740740
.run();
741741
}
742742

743+
// Temporarily disabled on Windows due to https://github.com/rust-lang/rust/issues/122857
743744
#[cargo_test]
745+
#[cfg(not(windows))]
744746
fn example_with_release_flag() {
745747
let p = project()
746748
.file(

0 commit comments

Comments
 (0)