Skip to content

Commit dfffadb

Browse files
authored
Rollup merge of rust-lang#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```
2 parents 6ad31f1 + ef3bb6f commit dfffadb

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::ffi::OsStr;
1212
use std::io::BufReader;
1313
use std::io::prelude::*;
1414
use std::path::{Path, PathBuf};
15+
use std::time::SystemTime;
1516
use std::{env, fs, str};
1617

1718
use serde_derive::Deserialize;
@@ -2568,7 +2569,17 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
25682569
}
25692570

25702571
let previous_mtime = t!(t!(path.metadata()).modified());
2571-
command("strip").arg("--strip-debug").arg(path).run_capture(builder);
2572+
let stamp = BuildStamp::new(path.parent().unwrap())
2573+
.with_prefix(path.file_name().unwrap().to_str().unwrap())
2574+
.with_prefix("strip")
2575+
.add_stamp(previous_mtime.duration_since(SystemTime::UNIX_EPOCH).unwrap().as_nanos());
2576+
2577+
// Running strip can be relatively expensive (~1s on librustc_driver.so), so we don't rerun it
2578+
// if the file is unchanged.
2579+
if !stamp.is_up_to_date() {
2580+
command("strip").arg("--strip-debug").arg(path).run_capture(builder);
2581+
}
2582+
t!(stamp.write());
25722583

25732584
let file = t!(fs::File::open(path));
25742585

0 commit comments

Comments
 (0)