Skip to content

Commit 9b80662

Browse files
committed
Account for clippy-driver having extra prefix rustc
I noticed that we were not caching clippy calls: ``` parse_arguments: CannotCache(multiple input files): ["rustc", "--crate-name", "bots_utils", "--edition=2024", ... ``` Turns out `rustc` is interpreted as one of the source inputs, so the actual input trips sccache into thinking that there are multiple inputs, which is not supported, so the caching does not happen. In a workspace with 161 members and 1761 total crates in the dependency graph we see the following results with sccache running hot (no misses): * Before: ``` Finished `dev` profile [unoptimized + debuginfo] target(s) in 1m 24s ``` ``` Compile requests 1802 Compile requests executed 1182 Cache hits 1177 Cache hits (C/C++) 107 Cache hits (Rust) 1070 Cache misses 0 Cache hits rate 100.00 % Cache hits rate (C/C++) 100.00 % Cache hits rate (Rust) 100.00 % Cache timeouts 0 Cache read errors 0 Forced recaches 0 Cache write errors 0 Cache errors 0 Compilations 0 Compilation failures 5 Non-cacheable compilations 0 Non-cacheable calls 610 Non-compilation calls 10 Unsupported compiler calls 0 Average cache write 0.000 s Average compiler 0.000 s Average cache read hit 0.000 s Failed distributed compilations 0 Non-cacheable reasons: multiple input files 339 crate-type 222 unknown source language 23 - 12 missing input 8 -o 3 missing output_dir 3 Cache location Local disk: "/home/ivan/.cache/sccache" Use direct/preprocessor mode? yes Version (client) 0.9.1 Cache size 444 MiB Max cache size 10 GiB ``` * After: ``` Finished `dev` profile [unoptimized + debuginfo] target(s) in 1m 11s ``` ``` Compile requests 1799 Compile requests executed 1332 Cache hits 1327 Cache hits (C/C++) 107 Cache hits (Rust) 1220 Cache misses 0 Cache hits rate 100.00 % Cache hits rate (C/C++) 100.00 % Cache hits rate (Rust) 100.00 % Cache timeouts 0 Cache read errors 0 Forced recaches 0 Cache write errors 0 Cache errors 0 Compilations 0 Compilation failures 5 Non-cacheable compilations 0 Non-cacheable calls 457 Non-compilation calls 10 Unsupported compiler calls 0 Average cache write 0.000 s Average compiler 0.000 s Average cache read hit 0.000 s Failed distributed compilations 0 Non-cacheable reasons: crate-type 407 unknown source language 23 - 11 missing input 9 argument parse 4 -o 3 Cache location Local disk: "/home/ivan/.cache/sccache" Use direct/preprocessor mode? yes Version (client) 0.10.0 Cache size 444 MiB Max cache size 10 GiB ```
1 parent 36dc4cf commit 9b80662

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/compiler/rust.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
10841084
let mut gcno = false;
10851085
let mut target_json = None;
10861086

1087-
for arg in ArgsIter::new(arguments.iter().cloned(), &ARGS[..]) {
1087+
for (idx, arg) in ArgsIter::new(arguments.iter().cloned(), &ARGS[..]).enumerate() {
10881088
let arg = try_or_cannot_cache!(arg, "argument parse");
10891089
match arg.get_data() {
10901090
Some(TooHardFlag) | Some(TooHardPath(_)) => {
@@ -1176,9 +1176,21 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
11761176
None => {
11771177
match arg {
11781178
Argument::Raw(ref val) => {
1179+
if idx == 0 {
1180+
if let Some(value) = val.to_str() {
1181+
if value == "rustc" {
1182+
// If the first argument is rustc, it's likely called via clippy-driver,
1183+
// so it's not actually an input file, which means we should discount it.
1184+
continue;
1185+
}
1186+
}
1187+
}
11791188
if input.is_some() {
11801189
// Can't cache compilations with multiple inputs.
1181-
cannot_cache!("multiple input files");
1190+
cannot_cache!(
1191+
"multiple input files",
1192+
format!("prev = {input:?}, next = {arg:?}")
1193+
);
11821194
}
11831195
input = Some(val.clone());
11841196
}

0 commit comments

Comments
 (0)