Skip to content

Commit f67b040

Browse files
committed
Rollup merge of rust-lang#48059 - alexcrichton:sccachebs, r=Mark-Simulacrum
rustbuild: Pass `ccache` to build scripts Right now the ccache setting is only used for LLVM, but this tweaks it to also be used for build scripts so C++ builds like `librustc_llvm` can be a bit speedier.
2 parents 2e28f98 + 64a8730 commit f67b040

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/bootstrap/builder.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,25 @@ impl<'a> Builder<'a> {
600600
//
601601
// FIXME: the guard against msvc shouldn't need to be here
602602
if !target.contains("msvc") {
603-
let cc = self.cc(target);
604-
cargo.env(format!("CC_{}", target), cc)
605-
.env("CC", cc);
603+
let ccache = self.config.ccache.as_ref();
604+
let ccacheify = |s: &Path| {
605+
let ccache = match ccache {
606+
Some(ref s) => s,
607+
None => return s.display().to_string(),
608+
};
609+
// FIXME: the cc-rs crate only recognizes the literal strings
610+
// `ccache` and `sccache` when doing caching compilations, so we
611+
// mirror that here. It should probably be fixed upstream to
612+
// accept a new env var or otherwise work with custom ccache
613+
// vars.
614+
match &ccache[..] {
615+
"ccache" | "sccache" => format!("{} {}", ccache, s.display()),
616+
_ => s.display().to_string(),
617+
}
618+
};
619+
let cc = ccacheify(&self.cc(target));
620+
cargo.env(format!("CC_{}", target), &cc)
621+
.env("CC", &cc);
606622

607623
let cflags = self.cflags(target).join(" ");
608624
cargo.env(format!("CFLAGS_{}", target), cflags.clone())
@@ -617,8 +633,9 @@ impl<'a> Builder<'a> {
617633
}
618634

619635
if let Ok(cxx) = self.cxx(target) {
620-
cargo.env(format!("CXX_{}", target), cxx)
621-
.env("CXX", cxx)
636+
let cxx = ccacheify(&cxx);
637+
cargo.env(format!("CXX_{}", target), &cxx)
638+
.env("CXX", &cxx)
622639
.env(format!("CXXFLAGS_{}", target), cflags.clone())
623640
.env("CXXFLAGS", cflags);
624641
}

0 commit comments

Comments
 (0)