Skip to content

Commit bc53451

Browse files
committed
Strip debuginfo if no debuginfo was requested
1 parent 58da1ce commit bc53451

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/cargo/core/profiles.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ impl Default for Profile {
643643
rpath: false,
644644
incremental: false,
645645
panic: PanicStrategy::Unwind,
646-
strip: Strip::Resolved(StripInner::None),
646+
strip: Strip::Deferred(StripInner::None),
647647
rustflags: vec![],
648648
trim_paths: None,
649649
}
@@ -926,6 +926,15 @@ impl Strip {
926926
Strip::Resolved(v) | Strip::Deferred(v) => v,
927927
}
928928
}
929+
930+
pub(crate) fn is_deferred(&self) -> bool {
931+
matches!(self, Strip::Deferred(_))
932+
}
933+
934+
/// Reset to stripping debuginfo.
935+
pub(crate) fn strip_debuginfo(self) -> Self {
936+
Strip::Resolved(StripInner::Named("debuginfo".into()))
937+
}
929938
}
930939

931940
impl PartialEq for Strip {

src/cargo/ops/cargo_compile/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,18 @@ fn traverse_and_share(
657657
};
658658

659659
let mut profile = unit.profile.clone();
660+
if profile.strip.is_deferred() {
661+
// If strip was not manually set, and all dependencies of this unit together
662+
// with this unit have debuginfo turned off, we enable debuginfo stripping.
663+
// This will remove pre-existing debug symbols coming from the standard library.
664+
if !profile.debuginfo.is_turned_on()
665+
&& new_deps
666+
.iter()
667+
.all(|dep| !dep.unit.profile.debuginfo.is_turned_on())
668+
{
669+
profile.strip = profile.strip.strip_debuginfo();
670+
}
671+
}
660672

661673
// If this is a build dependency, and it's not shared with runtime dependencies, we can weaken
662674
// its debuginfo level to optimize build times. We do nothing if it's an artifact dependency,

0 commit comments

Comments
 (0)