about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2025-08-19 19:45:32 +0800
committerGitHub <noreply@github.com>2025-08-19 19:45:32 +0800
commitb1a7bac798d5472c1932d9c12dc3d9f343e25b18 (patch)
tree08dc92bcb5f3d63dff8e17025e88e5b0db16484e /src
parent62227334ae04429f4b1196c8f852d666ae56204b (diff)
parentef3bb6fb0b7d7095f1a988835486daba4552ed89 (diff)
downloadrust-b1a7bac798d5472c1932d9c12dc3d9f343e25b18.tar.gz
rust-b1a7bac798d5472c1932d9c12dc3d9f343e25b18.zip
Rollup merge of #145452 - Kobzol:bootstrap-strip, r=jieyouxu
Do not strip binaries in bootstrap everytime if they are unchanged

I was profiling bootstrap to figure out why a no-op build takes upward of two seconds on my machine. I found that half of that is Cargo (which is mostly unavoidable) and the rest (~900ms) is running strip. We don't need to restrip already stripped binaries all the time.

r? `@jieyouxu`
Diffstat (limited to 'src')
-rw-r--r--src/bootstrap/src/core/build_steps/compile.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs
index 74a8cea1ebe..c9126a3929e 100644
--- a/src/bootstrap/src/core/build_steps/compile.rs
+++ b/src/bootstrap/src/core/build_steps/compile.rs
@@ -12,6 +12,7 @@ use std::ffi::OsStr;
 use std::io::BufReader;
 use std::io::prelude::*;
 use std::path::{Path, PathBuf};
+use std::time::SystemTime;
 use std::{env, fs, str};
 
 use serde_derive::Deserialize;
@@ -2612,7 +2613,17 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
     }
 
     let previous_mtime = t!(t!(path.metadata()).modified());
-    command("strip").arg("--strip-debug").arg(path).run_capture(builder);
+    let stamp = BuildStamp::new(path.parent().unwrap())
+        .with_prefix(path.file_name().unwrap().to_str().unwrap())
+        .with_prefix("strip")
+        .add_stamp(previous_mtime.duration_since(SystemTime::UNIX_EPOCH).unwrap().as_nanos());
+
+    // Running strip can be relatively expensive (~1s on librustc_driver.so), so we don't rerun it
+    // if the file is unchanged.
+    if !stamp.is_up_to_date() {
+        command("strip").arg("--strip-debug").arg(path).run_capture(builder);
+    }
+    t!(stamp.write());
 
     let file = t!(fs::File::open(path));