Skip to content

Commit

Permalink
Don't cache Rust compiles with incremental compilation. Fixes #257
Browse files Browse the repository at this point in the history
rustc's incremental compilation mode isn't well-handled by sccache currently
because we don't cache the separate artifacts it creates. Additionally,
if there are existing incremental artifacts it's likely that rustc will do
a better job than sccache anyway, so don't bother trying to cache Rust
compilation when incremental compilation is enabled for now.

Longer-term we would like to make sccache and rustc incremental work
together nicely: #236
  • Loading branch information
luser committed Jul 11, 2018
1 parent c796adc commit 9e92e99
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/compiler/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,15 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
if let (Some(name), Some(val)) = (name, val) {
match name {
"extra-filename" => extra_filename = Some(val.to_owned()),
// Incremental compilation makes a mess of sccache's entire world
// view. It produces additional compiler outputs that we don't cache,
// and just letting rustc do its work in incremental mode is likely
// to be faster than trying to fetch a result from cache anyway, so
// don't bother caching compiles where it's enabled currently.
// Longer-term we would like to figure out better integration between
// sccache and rustc in the incremental scenario:
// https://github.com/mozilla/sccache/issues/236
"incremental" => return CompilerArguments::CannotCache("incremental"),
_ => {},
}
}
Expand Down Expand Up @@ -768,7 +777,7 @@ mod test {
match _parse_arguments(&[ $( $s.to_string(), )* ]) {
CompilerArguments::Ok(_) => panic!("Should not have parsed ok: `{}`", stringify!($( $s, )*)),

_ => {}
o @ _ => o,
}
}
}
Expand Down Expand Up @@ -815,6 +824,14 @@ mod test {
assert_eq!(h.externs, ovec!["/foo/target/debug/deps/liblibc-89a24418d48d484a.rlib", "/foo/target/debug/deps/liblog-2f7366be74992849.rlib"]);
}

#[test]
fn test_parse_arguments_incremental() {
parses!("--emit", "link", "foo.rs", "--out-dir", "out", "--crate-name", "foo");
let r = fails!("--emit", "link", "foo.rs", "--out-dir", "out", "--crate-name", "foo",
"-C", "incremental=/foo");
assert_eq!(r, CompilerArguments::CannotCache("incremental"))
}

#[test]
fn test_parse_arguments_dep_info_no_extra_filename() {
let h = parses!("--crate-name", "foo", "src/lib.rs",
Expand Down
3 changes: 3 additions & 0 deletions tests/sccache_cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ fn test_rust_cargo() {
trace!("cargo build: {:?}", a);
a.unwrap();
// Now get the stats and ensure that we had a cache hit for the second build.
// Ideally we'd check the stats more usefully here--the test crate has one dependency (itoa)
// so there are two separate compilations, but cargo will build the test crate with
// incremental compilation enabled, so sccache will not cache it.
trace!("sccache --show-stats");
Assert::command(&[&sccache.to_string_lossy()])
.with_args(&["--show-stats", "--stats-format=json"])
Expand Down
10 changes: 10 additions & 0 deletions tests/test-crate/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/test-crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ version = "0.1.0"
authors = ["Ted Mielczarek <ted@mielczarek.org>"]

[dependencies]
# Arbitrary crate dependency that doesn't pull in any transitive dependencies.
itoa = "0.3.4"

0 comments on commit 9e92e99

Please sign in to comment.