Skip to content

Commit

Permalink
rustc: Prefer loading crates in the sysroot
Browse files Browse the repository at this point in the history
This commit is a random stab in the dark to fix the spurious failures on #39518.
The leading theory of the spurious failures on Windows is that the compiler is
loading a path in the `deps` folder, passing it to `link.exe`, and then this is
racing with Cargo itself updating those paths.

This race, however, has a few unique properties:

* It's isolated to just libstd. Most crates are never passed to the linker and
  simultaneously being worked on by Cargo. Cargo's typical execution of the
  dependency graph never hits this problem.
* The crates are already all located in the sysroot in addition to the `deps`
  folder. This means that the compiler actually has two candidates of crates to
  load, and it's just arbitrarily rejecting one.

Together this means that we shouldn't need to fix this problem "in the large"
and we can instead just fix it in this isolated situation (hopefully). To solve
this the compiler's been updated to prefer crates from the sysroot to leave
Cargo's structure to itself.

We'll see if this actually allows the PR to land...
  • Loading branch information
alexcrichton committed Mar 9, 2017
1 parent 3be02fc commit 6f43149
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/librustc_metadata/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,34 @@ impl<'a> Context<'a> {
lib.display()));
continue;
}

// Ok so at this point we've determined that `(lib, kind)` above is
// a candidate crate to load, and that `slot` is either none (this
// is the first crate of its kind) or if some the previous path has
// the exact same hash (e.g. it's the exact same crate).
//
// In principle these two candidate crates are exactly the same so
// we can choose either of them to link. As a stupidly gross hack,
// however, we favor crate in the sysroot.
//
// You can find more info in rust-lang/rust#39518 and various linked
// issues, but the general gist is that during testing libstd the
// compilers has two candidates to choose from: one in the sysroot
// and one in the deps folder. These two crates are the exact same
// crate but if the compiler chooses the one in the deps folder
// it'll cause spurious errors on Windows.
//
// As a result, we favor the sysroot crate here. Note that the
// candidates are all canonicalized, so we canonicalize the sysroot
// as well.
if let Some((ref prev, _)) = ret {
let sysroot = self.sess.sysroot();
let sysroot = sysroot.canonicalize()
.unwrap_or(sysroot.to_path_buf());
if prev.starts_with(&sysroot) {
continue
}
}
*slot = Some((hash, metadata));
ret = Some((lib, kind));
}
Expand Down

0 comments on commit 6f43149

Please sign in to comment.