Skip to content

Commit fdef6a8

Browse files
committed
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
1 parent a85417f commit fdef6a8

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

693709
let cflags = self.cflags(target).join(" ");
694710
cargo.env(format!("CFLAGS_{}", target), cflags.clone())
@@ -703,8 +719,9 @@ impl<'a> Builder<'a> {
703719
}
704720

705721
if let Ok(cxx) = self.cxx(target) {
706-
cargo.env(format!("CXX_{}", target), cxx)
707-
.env("CXX", cxx)
722+
let cxx = ccacheify(&cxx);
723+
cargo.env(format!("CXX_{}", target), &cxx)
724+
.env("CXX", &cxx)
708725
.env(format!("CXXFLAGS_{}", target), cflags.clone())
709726
.env("CXXFLAGS", cflags);
710727
}

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)