Skip to content

Commit

Permalink
rust: workaround --print file-names emitting staticlibs / dylibs.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
emilio committed Feb 3, 2020
1 parent fca8410 commit 275bd03
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/compiler/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,26 @@ where
&env_vars,
)
.map(move |mut outputs| {
// metadata / dep-info don't ever generate binaries, but
// rustc still makes them appear in the --print
// file-names output (see
// https://github.com/rust-lang/rust/pull/68799).
//
// So if we see a binary in the rustc output and figure
// out that we're not _actually_ generating it, then we
// can avoid generating everything that isn't an rlib /
// rmeta.
//
// This can go away once the above rustc PR makes it in.
let emit_generates_only_metadata =
!emit.is_empty() && emit.iter().all(|e| e == "metadata" || e == "dep-info");

if emit_generates_only_metadata {
outputs.retain(|o| {
o.ends_with(".rlib") || o.ends_with(".rmeta")
});
}

if emit.contains("metadata") {
// rustc currently does not report rmeta outputs with --print file-names
// --emit metadata the rlib is printed, and with --emit metadata,link
Expand All @@ -1186,8 +1206,11 @@ where
}
}
}

let output_dir = PathBuf::from(output_dir);
// Convert output files into a map of basename -> full path.
// Convert output files into a map of basename -> full
// path, and remove some unneeded / non-existing ones,
// see https://github.com/rust-lang/rust/pull/68799.
let mut outputs = outputs
.into_iter()
.map(|o| {
Expand Down Expand Up @@ -1223,10 +1246,10 @@ where
compilation: Box::new(RustCompilation {
executable: executable,
host,
sysroot: sysroot,
arguments: arguments,
inputs: inputs,
outputs: outputs,
sysroot,
arguments,
inputs,
outputs,
crate_link_paths,
crate_name,
crate_types,
Expand Down Expand Up @@ -2673,7 +2696,7 @@ c:/foo/bar.rs:
staticlib: false,
},
dep_info: None,
emit: emit,
emit,
color_mode: ColorMode::Auto,
has_json: false,
},
Expand Down

0 comments on commit 275bd03

Please sign in to comment.