From e2d0b52cd5a36d699d58322437cee2fc3deb48c3 Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Fri, 1 May 2020 16:37:05 +0300 Subject: [PATCH] Add option to strip binaries --- src/cargo/core/compiler/mod.rs | 5 +++++ src/cargo/core/profiles.rs | 8 ++++++++ src/cargo/util/toml/mod.rs | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index cce5301cd48..ce0b250bf1f 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -748,6 +748,7 @@ fn build_base_args( rpath, ref panic, incremental, + strip, .. } = unit.profile; let test = unit.mode.is_any_test(); @@ -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 diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index d4769389abd..a9608cc39cf 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -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). @@ -595,6 +598,7 @@ pub struct Profile { pub rpath: bool, pub incremental: bool, pub panic: PanicStrategy, + pub strip: bool, } impl Default for Profile { @@ -611,6 +615,7 @@ impl Default for Profile { rpath: false, incremental: false, panic: PanicStrategy::Unwind, + strip: false, } } } @@ -635,6 +640,7 @@ compact_debug! { rpath incremental panic + strip )] } } @@ -721,6 +727,7 @@ impl Profile { bool, bool, PanicStrategy, + bool, ) { ( self.opt_level, @@ -732,6 +739,7 @@ impl Profile { self.rpath, self.incremental, self.panic, + self.strip, ) } } diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index b0295a7245e..e980e226832 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -407,6 +407,7 @@ pub struct TomlProfile { pub build_override: Option>, pub dir_name: Option, pub inherits: Option, + pub strip: Option, } #[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)] @@ -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); + } } }