Skip to content

Commit 58da1ce

Browse files
committed
Store the Strip option in Deferred form
1 parent 13e9792 commit 58da1ce

File tree

2 files changed

+71
-13
lines changed

2 files changed

+71
-13
lines changed

src/cargo/core/compiler/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ use self::unit_graph::UnitDep;
8888
use crate::core::compiler::future_incompat::FutureIncompatReport;
8989
pub use crate::core::compiler::unit::{Unit, UnitInterner};
9090
use crate::core::manifest::TargetSourcePath;
91-
use crate::core::profiles::{PanicStrategy, Profile, Strip};
91+
use crate::core::profiles::{PanicStrategy, Profile, StripInner};
9292
use crate::core::{Feature, PackageId, Target, Verbosity};
9393
use crate::util::errors::{CargoResult, VerboseError};
9494
use crate::util::interning::InternedString;
@@ -1130,7 +1130,8 @@ fn build_base_args(cx: &Context<'_, '_>, cmd: &mut ProcessBuilder, unit: &Unit)
11301130
opt(cmd, "-C", "incremental=", Some(dir));
11311131
}
11321132

1133-
if strip != Strip::None {
1133+
let strip = strip.into_inner();
1134+
if strip != StripInner::None {
11341135
cmd.arg("-C").arg(format!("strip={}", strip));
11351136
}
11361137

src/cargo/core/profiles.rs

+68-11
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,17 @@ fn merge_profile(profile: &mut Profile, toml: &TomlProfile) {
573573
profile.trim_paths = Some(trim_paths.clone());
574574
}
575575
profile.strip = match toml.strip {
576-
Some(StringOrBool::Bool(true)) => Strip::Named(InternedString::new("symbols")),
577-
None | Some(StringOrBool::Bool(false)) => Strip::None,
578-
Some(StringOrBool::String(ref n)) if n.as_str() == "none" => Strip::None,
579-
Some(StringOrBool::String(ref n)) => Strip::Named(InternedString::new(n)),
576+
Some(StringOrBool::Bool(true)) => {
577+
Strip::Resolved(StripInner::Named(InternedString::new("symbols")))
578+
}
579+
Some(StringOrBool::Bool(false)) => Strip::Resolved(StripInner::None),
580+
Some(StringOrBool::String(ref n)) if n.as_str() == "none" => {
581+
Strip::Resolved(StripInner::None)
582+
}
583+
Some(StringOrBool::String(ref n)) => {
584+
Strip::Resolved(StripInner::Named(InternedString::new(n)))
585+
}
586+
None => Strip::Deferred(StripInner::None),
580587
};
581588
}
582589

@@ -636,7 +643,7 @@ impl Default for Profile {
636643
rpath: false,
637644
incremental: false,
638645
panic: PanicStrategy::Unwind,
639-
strip: Strip::None,
646+
strip: Strip::Resolved(StripInner::None),
640647
rustflags: vec![],
641648
trim_paths: None,
642649
}
@@ -873,28 +880,78 @@ impl fmt::Display for PanicStrategy {
873880
}
874881
}
875882

876-
/// The setting for choosing which symbols to strip
877883
#[derive(
878884
Clone, Copy, PartialEq, Eq, Debug, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
879885
)]
880-
#[serde(rename_all = "lowercase")]
881-
pub enum Strip {
886+
pub enum StripInner {
882887
/// Don't remove any symbols
883888
None,
884889
/// Named Strip settings
885890
Named(InternedString),
886891
}
887892

888-
impl fmt::Display for Strip {
893+
impl fmt::Display for StripInner {
889894
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
890895
match *self {
891-
Strip::None => "none",
892-
Strip::Named(s) => s.as_str(),
896+
StripInner::None => "none",
897+
StripInner::Named(s) => s.as_str(),
893898
}
894899
.fmt(f)
895900
}
896901
}
897902

903+
/// The setting for choosing which symbols to strip.
904+
///
905+
/// This is semantically a [`StripInner`], and should be used as so via the
906+
/// [`Strip::into_inner`] method for all intents and purposes.
907+
///
908+
/// Internally, it's used to model a strip option whose value can be deferred
909+
/// for optimization purposes: when no package being compiled requires debuginfo,
910+
/// then we can strip debuginfo to remove pre-existing debug symbols from the
911+
/// standard library.
912+
#[derive(Clone, Copy, Debug, Eq, serde::Serialize, serde::Deserialize)]
913+
#[serde(rename_all = "lowercase")]
914+
pub enum Strip {
915+
/// A strip option that is fixed and will not change.
916+
Resolved(StripInner),
917+
/// A strip option that might be overridden by Cargo for optimization
918+
/// purposes.
919+
Deferred(StripInner),
920+
}
921+
922+
impl Strip {
923+
/// The main way to interact with this strip option, turning it into a [`StripInner`].
924+
pub fn into_inner(self) -> StripInner {
925+
match self {
926+
Strip::Resolved(v) | Strip::Deferred(v) => v,
927+
}
928+
}
929+
}
930+
931+
impl PartialEq for Strip {
932+
fn eq(&self, other: &Self) -> bool {
933+
self.into_inner().eq(&other.into_inner())
934+
}
935+
}
936+
937+
impl Hash for Strip {
938+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
939+
self.into_inner().hash(state);
940+
}
941+
}
942+
943+
impl PartialOrd for Strip {
944+
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
945+
self.into_inner().partial_cmp(&other.into_inner())
946+
}
947+
}
948+
949+
impl Ord for Strip {
950+
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
951+
self.into_inner().cmp(&other.into_inner())
952+
}
953+
}
954+
898955
/// Flags used in creating `Unit`s to indicate the purpose for the target, and
899956
/// to ensure the target's dependencies have the correct settings.
900957
///

0 commit comments

Comments
 (0)