Skip to content

Commit e52e360

Browse files
committed
Auto merge of #13654 - weihanglo:rust-1.77.0-backport, r=epage
[stable-1.77] Do not strip debuginfo by default for MSVC Stable backports: - #13630 In order to make CI pass, the following PRs are also cherry-picked: -
2 parents 3fe68ea + 2cb25a2 commit e52e360

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ self_named_module_files = "warn"
124124

125125
[package]
126126
name = "cargo"
127-
version = "0.78.0"
127+
version = "0.78.1"
128128
edition.workspace = true
129129
license.workspace = true
130130
rust-version = "1.75.0" # MSRV:1

src/cargo/ops/cargo_compile/mod.rs

Lines changed: 12 additions & 1 deletion
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;
@@ -443,6 +444,7 @@ pub fn create_bcx<'a, 'cfg>(
443444
&units,
444445
&scrape_units,
445446
host_kind_requested.then_some(explicit_host_kind),
447+
&target_data,
446448
);
447449
}
448450

@@ -574,6 +576,7 @@ fn rebuild_unit_graph_shared(
574576
roots: &[Unit],
575577
scrape_units: &[Unit],
576578
to_host: Option<CompileKind>,
579+
target_data: &RustcTargetData<'_>,
577580
) -> (Vec<Unit>, Vec<Unit>, UnitGraph) {
578581
let mut result = UnitGraph::new();
579582
// Map of the old unit to the new unit, used to avoid recursing into units
@@ -590,6 +593,7 @@ fn rebuild_unit_graph_shared(
590593
root,
591594
false,
592595
to_host,
596+
target_data,
593597
)
594598
})
595599
.collect();
@@ -616,6 +620,7 @@ fn traverse_and_share(
616620
unit: &Unit,
617621
unit_is_for_host: bool,
618622
to_host: Option<CompileKind>,
623+
target_data: &RustcTargetData<'_>,
619624
) -> Unit {
620625
if let Some(new_unit) = memo.get(unit) {
621626
// Already computed, no need to recompute.
@@ -633,6 +638,7 @@ fn traverse_and_share(
633638
&dep.unit,
634639
dep.unit_for.is_for_host(),
635640
to_host,
641+
target_data,
636642
);
637643
new_dep_unit.hash(&mut dep_hash);
638644
UnitDep {
@@ -656,8 +662,13 @@ fn traverse_and_share(
656662
_ => unit.kind,
657663
};
658664

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

tests/testsuite/profiles.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,9 @@ fn strip_accepts_false_to_disable_strip() {
611611
.run();
612612
}
613613

614+
// Temporarily disabled on Windows due to https://github.com/rust-lang/rust/issues/122857
614615
#[cargo_test]
616+
#[cfg(not(windows))]
615617
fn strip_debuginfo_in_release() {
616618
let p = project()
617619
.file(
@@ -630,7 +632,32 @@ fn strip_debuginfo_in_release() {
630632
.run();
631633
}
632634

635+
// Using -Cstrip=debuginfo in release mode by default is temporarily disabled on Windows due to
636+
// https://github.com/rust-lang/rust/issues/122857
633637
#[cargo_test]
638+
#[cfg(all(target_os = "windows", target_env = "msvc"))]
639+
fn do_not_strip_debuginfo_in_release_on_windows() {
640+
let p = project()
641+
.file(
642+
"Cargo.toml",
643+
r#"
644+
[package]
645+
name = "foo"
646+
version = "0.1.0"
647+
edition = "2015"
648+
"#,
649+
)
650+
.file("src/main.rs", "fn main() {}")
651+
.build();
652+
653+
p.cargo("build --release -v")
654+
.with_stderr_does_not_contain("[..]strip=debuginfo[..]")
655+
.run();
656+
}
657+
658+
// Temporarily disabled on Windows due to https://github.com/rust-lang/rust/issues/122857
659+
#[cargo_test]
660+
#[cfg(not(windows))]
634661
fn strip_debuginfo_without_debug() {
635662
let p = project()
636663
.file(

tests/testsuite/run.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,9 @@ fn one_bin_multiple_examples() {
735735
.run();
736736
}
737737

738+
// Temporarily disabled on Windows due to https://github.com/rust-lang/rust/issues/122857
738739
#[cargo_test]
740+
#[cfg(not(windows))]
739741
fn example_with_release_flag() {
740742
let p = project()
741743
.file(

0 commit comments

Comments
 (0)