Skip to content

Commit 4a316e7

Browse files
committed
Auto merge of #48630 - alexcrichton:more-sccache, r=kennytm
rustbuild: Pass `ccache` to build scripts This is a re-attempt at #48192 hopefully this time with 100% less randomly [blocking builds for 20 minutes][block]. To work around #48192 the sccache server is started in the `run.sh` script very early on in the compilation process. [block]: #48192
2 parents 4a72063 + fdef6a8 commit 4a316e7

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/bootstrap/builder.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,25 @@ impl<'a> Builder<'a> {
688688
//
689689
// FIXME: the guard against msvc shouldn't need to be here
690690
if !target.contains("msvc") {
691-
let cc = self.cc(target);
692-
cargo.env(format!("CC_{}", target), cc)
693-
.env("CC", cc);
691+
let ccache = self.config.ccache.as_ref();
692+
let ccacheify = |s: &Path| {
693+
let ccache = match ccache {
694+
Some(ref s) => s,
695+
None => return s.display().to_string(),
696+
};
697+
// FIXME: the cc-rs crate only recognizes the literal strings
698+
// `ccache` and `sccache` when doing caching compilations, so we
699+
// mirror that here. It should probably be fixed upstream to
700+
// accept a new env var or otherwise work with custom ccache
701+
// vars.
702+
match &ccache[..] {
703+
"ccache" | "sccache" => format!("{} {}", ccache, s.display()),
704+
_ => s.display().to_string(),
705+
}
706+
};
707+
let cc = ccacheify(&self.cc(target));
708+
cargo.env(format!("CC_{}", target), &cc)
709+
.env("CC", &cc);
694710

695711
let cflags = self.cflags(target).join(" ");
696712
cargo.env(format!("CFLAGS_{}", target), cflags.clone())
@@ -705,8 +721,9 @@ impl<'a> Builder<'a> {
705721
}
706722

707723
if let Ok(cxx) = self.cxx(target) {
708-
cargo.env(format!("CXX_{}", target), cxx)
709-
.env("CXX", cxx)
724+
let cxx = ccacheify(&cxx);
725+
cargo.env(format!("CXX_{}", target), &cxx)
726+
.env("CXX", &cxx)
710727
.env(format!("CXXFLAGS_{}", target), cflags.clone())
711728
.env("CXXFLAGS", cflags);
712729
}

src/ci/run.sh

+6
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ else
6767
fi
6868
fi
6969

70+
# We've had problems in the past of shell scripts leaking fds into the sccache
71+
# server (#48192) which causes Cargo to erroneously think that a build script
72+
# hasn't finished yet. Try to solve that problem by starting a very long-lived
73+
# sccache server at the start of the build, but no need to worry if this fails.
74+
SCCACHE_IDLE_TIMEOUT=10800 sccache --start-server || true
75+
7076
travis_fold start configure
7177
travis_time_start
7278
$SRC/configure $RUST_CONFIGURE_ARGS

0 commit comments

Comments
 (0)