Skip to content

Commit b1b347b

Browse files
emiliofroydnj
authored andcommitted
rust: workaround --print file-names emitting staticlibs / dylibs.
This fixes cargo check in mozilla-central. The issue is that rustc --print file-names emits a somewhat poor approximation of what's actually going to be emitted. So for a staticlib crate, it will also print the staticlib file, which is not great. See https://bugzilla.mozilla.org/show_bug.cgi?id=1612855#c2 for a more straight-forward explanation of the failure case. Sccache would try to find the library and fail, erroring as a consequence. Pile up on the existing workaround for rmeta files not showing up (rust-lang/rust#54852) by removing files that are not metadata when we only request metadata. rust-lang/rust#68799 contains a rust-side fix that would also fix this.
1 parent 24f4306 commit b1b347b

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

src/compiler/rust.rs

+29-6
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,26 @@ where
11651165
&env_vars,
11661166
)
11671167
.map(move |mut outputs| {
1168+
// metadata / dep-info don't ever generate binaries, but
1169+
// rustc still makes them appear in the --print
1170+
// file-names output (see
1171+
// https://github.com/rust-lang/rust/pull/68799).
1172+
//
1173+
// So if we see a binary in the rustc output and figure
1174+
// out that we're not _actually_ generating it, then we
1175+
// can avoid generating everything that isn't an rlib /
1176+
// rmeta.
1177+
//
1178+
// This can go away once the above rustc PR makes it in.
1179+
let emit_generates_only_metadata =
1180+
!emit.is_empty() && emit.iter().all(|e| e == "metadata" || e == "dep-info");
1181+
1182+
if emit_generates_only_metadata {
1183+
outputs.retain(|o| {
1184+
o.ends_with(".rlib") || o.ends_with(".rmeta")
1185+
});
1186+
}
1187+
11681188
if emit.contains("metadata") {
11691189
// rustc currently does not report rmeta outputs with --print file-names
11701190
// --emit metadata the rlib is printed, and with --emit metadata,link
@@ -1186,8 +1206,11 @@ where
11861206
}
11871207
}
11881208
}
1209+
11891210
let output_dir = PathBuf::from(output_dir);
1190-
// Convert output files into a map of basename -> full path.
1211+
// Convert output files into a map of basename -> full
1212+
// path, and remove some unneeded / non-existing ones,
1213+
// see https://github.com/rust-lang/rust/pull/68799.
11911214
let mut outputs = outputs
11921215
.into_iter()
11931216
.map(|o| {
@@ -1223,10 +1246,10 @@ where
12231246
compilation: Box::new(RustCompilation {
12241247
executable: executable,
12251248
host,
1226-
sysroot: sysroot,
1227-
arguments: arguments,
1228-
inputs: inputs,
1229-
outputs: outputs,
1249+
sysroot,
1250+
arguments,
1251+
inputs,
1252+
outputs,
12301253
crate_link_paths,
12311254
crate_name,
12321255
crate_types,
@@ -2673,7 +2696,7 @@ c:/foo/bar.rs:
26732696
staticlib: false,
26742697
},
26752698
dep_info: None,
2676-
emit: emit,
2699+
emit,
26772700
color_mode: ColorMode::Auto,
26782701
has_json: false,
26792702
},

0 commit comments

Comments
 (0)