Skip to content

Add option to strip binaries #8191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ fn build_base_args(
rpath,
ref panic,
incremental,
strip,
..
} = unit.profile;
let test = unit.mode.is_any_test();
Expand Down Expand Up @@ -919,6 +920,10 @@ fn build_base_args(
opt(cmd, "-C", "incremental=", Some(dir));
}

if strip {
opt(cmd, "-C", "link-arg=", Some(OsStr::new("-s")));
}

if unit.is_std {
// -Zforce-unstable-if-unmarked prevents the accidental use of
// unstable crates within the sysroot (such as "extern crate libc" or
Expand Down
8 changes: 8 additions & 0 deletions src/cargo/core/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,9 @@ fn merge_profile(profile: &mut Profile, toml: &TomlProfile) {
if let Some(incremental) = toml.incremental {
profile.incremental = incremental;
}
if let Some(strip) = toml.strip {
profile.strip = strip;
}
}

/// The root profile (dev/release).
Expand Down Expand Up @@ -595,6 +598,7 @@ pub struct Profile {
pub rpath: bool,
pub incremental: bool,
pub panic: PanicStrategy,
pub strip: bool,
}

impl Default for Profile {
Expand All @@ -611,6 +615,7 @@ impl Default for Profile {
rpath: false,
incremental: false,
panic: PanicStrategy::Unwind,
strip: false,
}
}
}
Expand All @@ -635,6 +640,7 @@ compact_debug! {
rpath
incremental
panic
strip
)]
}
}
Expand Down Expand Up @@ -721,6 +727,7 @@ impl Profile {
bool,
bool,
PanicStrategy,
bool,
) {
(
self.opt_level,
Expand All @@ -732,6 +739,7 @@ impl Profile {
self.rpath,
self.incremental,
self.panic,
self.strip,
)
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ pub struct TomlProfile {
pub build_override: Option<Box<TomlProfile>>,
pub dir_name: Option<InternedString>,
pub inherits: Option<InternedString>,
pub strip: Option<bool>,
}

#[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
Expand Down Expand Up @@ -641,6 +642,10 @@ impl TomlProfile {
if let Some(v) = &profile.dir_name {
self.dir_name = Some(*v);
}

if let Some(v) = profile.strip {
self.strip = Some(v);
}
}
}

Expand Down