Rust: Running "x.py check" and "x.py test" in parallel leads to errors

Created on 13 Sep 2020  路  10Comments  路  Source: rust-lang/rust

Since I started using vscode, it is now often the case that the ./x.py check library/std which vscode runs is still not done when I alt-tab back to my terminal to do (for example) ./x.py test --stage 0 library/core --test-args slice. That regularly leads to errors like this:

error[E0464]: multiple matching crates for `core`
  |
  = note: candidates:
          crate `core`: /home/r/src/rust/rustc.2/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-deaf58ff3f911d75.rlib

error: aborting due to previous error

error: could not compile `getrandom`.

In those cases, just running x.py test again solves the problem -- but it would still be better if having vscode run in background would not break what I do in the terminal.

Cc @Mark-Simulacrum

A-contributor-roadblock A-rustbuild C-bug

All 10 comments

So there's several solutions to this:

  • Don't support this, tell people to run x.py check in a different directory so the build directory goes elsewhere.
  • Add a global lock like Cargo's on the build directory
  • Specialize x.py check to use different sysroot for stage0 - i.e. don't fix x.py build and test running simultaneously etc

I am interested in hearing which you think would be preferable.

Cc @spastorino

If they could run truly in parallel that would be great. However, a separate build dir also means the bootstrap rustc is downloaded again, right? That would not be great.

Yes, option 1 would duplicate the stage0 rustc downloads. Option 3, though, would not - it's probably the right choice I think since x.py check is somewhat unique in being the most likely to be invoked in parallel.

@Mark-Simulacrum in an ideal world, would fixing https://github.com/rust-lang/rust/issues/65427 also fix this?

Not really. It might even make things worse. rustbuild uses the same stamps for both check and build steps (and sysroots etc) so when both are running simultaneously we will stomp all over the other, which is going to lead to incorrect behavior.

I was not able to replicate this. On my machine running both in parallel gives

Checking std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Blocking waiting for file lock on build directory

Ok, I figured out when this happens: you need one terminal to be building the compiler while the other is building libstd. If both are building libstd this error doesn't show up.

I think this can also lead to losing the build cache... at least I just had a case where after showing this error, it then (on the next attempt) proceeded to rebuild the crate graph rustc depends on, instead of just the crate that I changed.

FYI option 3 was seen as too big a hammer in https://github.com/rust-lang/rust/pull/77779#issuecomment-709526858; the proposed fix was to use a build lock on the sysroot instead, the same way cargo has a build lock for target/deps.

I think that's not quite accurate, in #77779 the specialization was too specific (i.e., the problem is more widespread, any two x.py runs can touch shared files currently). "Insufficiently big hammer" is probably the right description of option 3.

Was this page helpful?
0 / 5 - 0 ratings