Skip to content

Commit b1a7bac

Browse files
authored
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`
2 parents 6222733 + ef3bb6f commit b1a7bac

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;
@@ -2612,7 +2613,17 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
26122613
}
26132614

26142615
let previous_mtime = t!(t!(path.metadata()).modified());
2615-
command("strip").arg("--strip-debug").arg(path).run_capture(builder);
2616+
let stamp = BuildStamp::new(path.parent().unwrap())
2617+
.with_prefix(path.file_name().unwrap().to_str().unwrap())
2618+
.with_prefix("strip")
2619+
.add_stamp(previous_mtime.duration_since(SystemTime::UNIX_EPOCH).unwrap().as_nanos());
2620+
2621+
// Running strip can be relatively expensive (~1s on librustc_driver.so), so we don't rerun it
2622+
// if the file is unchanged.
2623+
if !stamp.is_up_to_date() {
2624+
command("strip").arg("--strip-debug").arg(path).run_capture(builder);
2625+
}
2626+
t!(stamp.write());
26162627

26172628
let file = t!(fs::File::open(path));
26182629

0 commit comments

Comments
 (0)