diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 848fb9eade9..131d2566af5 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1676,7 +1676,15 @@ impl<'a> Builder<'a> { self.config.rust_debuginfo_level_tools } }; - cargo.env(profile_var("DEBUG"), debuginfo_level.to_string()); + if debuginfo_level == 1 { + // Use less debuginfo than the default to save on disk space. + cargo.env(profile_var("DEBUG"), "line-tables-only"); + } else { + cargo.env(profile_var("DEBUG"), debuginfo_level.to_string()); + }; + if self.cc[&target].args().iter().any(|arg| arg == "-gz") { + rustflags.arg("-Clink-arg=-gz"); + } cargo.env( profile_var("DEBUG_ASSERTIONS"), if mode == Mode::Std { diff --git a/src/bootstrap/cc_detect.rs b/src/bootstrap/cc_detect.rs index 65c882fb801..db3b69d18c8 100644 --- a/src/bootstrap/cc_detect.rs +++ b/src/bootstrap/cc_detect.rs @@ -69,6 +69,8 @@ fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build { .opt_level(2) .warnings(false) .debug(false) + // Compress debuginfo + .flag_if_supported("-gz") .target(&target.triple) .host(&build.build.triple); match build.crt_static(target) {