Skip to content

Commit be515c7

Browse files
committed
feat(trim-paths): default value for release profile
trim-paths is shown as disabled as default in `Debug` impl. Although this doesn't reflect the correct default for `-Ztrim-pthas`, this is no critical as it is only for debugging, and it's a bit tricky to make it more correct.
1 parent faaf3ad commit be515c7

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/cargo/core/profiles.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
use crate::core::compiler::{CompileKind, CompileTarget, Unit};
2525
use crate::core::dependency::Artifact;
2626
use crate::core::resolver::features::FeaturesFor;
27+
use crate::core::Feature;
2728
use crate::core::{PackageId, PackageIdSpec, Resolve, Shell, Target, Workspace};
2829
use crate::util::interning::InternedString;
2930
use crate::util::toml::TomlTrimPaths;
31+
use crate::util::toml::TomlTrimPathsValue;
3032
use crate::util::toml::{
3133
ProfilePackageSpec, StringOrBool, TomlDebugInfo, TomlProfile, TomlProfiles,
3234
};
@@ -81,7 +83,9 @@ impl Profiles {
8183
rustc_host,
8284
};
8385

84-
Self::add_root_profiles(&mut profile_makers, &profiles);
86+
let trim_paths_enabled = ws.unstable_features().is_enabled(Feature::trim_paths())
87+
|| config.cli_unstable().trim_paths;
88+
Self::add_root_profiles(&mut profile_makers, &profiles, trim_paths_enabled);
8589

8690
// Merge with predefined profiles.
8791
use std::collections::btree_map::Entry;
@@ -124,6 +128,7 @@ impl Profiles {
124128
fn add_root_profiles(
125129
profile_makers: &mut Profiles,
126130
profiles: &BTreeMap<InternedString, TomlProfile>,
131+
trim_paths_enabled: bool,
127132
) {
128133
profile_makers.by_name.insert(
129134
InternedString::new("dev"),
@@ -132,7 +137,10 @@ impl Profiles {
132137

133138
profile_makers.by_name.insert(
134139
InternedString::new("release"),
135-
ProfileMaker::new(Profile::default_release(), profiles.get("release").cloned()),
140+
ProfileMaker::new(
141+
Profile::default_release(trim_paths_enabled),
142+
profiles.get("release").cloned(),
143+
),
136144
);
137145
}
138146

@@ -635,7 +643,7 @@ compact_debug! {
635643
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
636644
let (default, default_name) = match self.name.as_str() {
637645
"dev" => (Profile::default_dev(), "default_dev()"),
638-
"release" => (Profile::default_release(), "default_release()"),
646+
"release" => (Profile::default_release(false), "default_release()"),
639647
_ => (Profile::default(), "default()"),
640648
};
641649
[debug_the_fields(
@@ -696,11 +704,13 @@ impl Profile {
696704
}
697705

698706
/// Returns a built-in `release` profile.
699-
fn default_release() -> Profile {
707+
fn default_release(trim_paths_enabled: bool) -> Profile {
708+
let trim_paths = trim_paths_enabled.then(|| TomlTrimPathsValue::Object.into());
700709
Profile {
701710
name: InternedString::new("release"),
702711
root: ProfileRoot::Release,
703712
opt_level: InternedString::new("3"),
713+
trim_paths,
704714
..Profile::default()
705715
}
706716
}

0 commit comments

Comments
 (0)