Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aliasing of build.rs output when --out-dir is used #6282

Closed
idubrov opened this issue Nov 8, 2018 · 1 comment · Fixed by #6300
Closed

Aliasing of build.rs output when --out-dir is used #6282

idubrov opened this issue Nov 8, 2018 · 1 comment · Fixed by #6300

Comments

@idubrov
Copy link

idubrov commented Nov 8, 2018

Problem

Unstable flag --out-dir is unsafe in presence of multiple packages with build scripts & parallel build.

What I think is happening is with flag --out-dir cargo places compiled build.rs in a same location for all packages. For example, if I set --out-dir=./target, all build scripts will be compiled into target/build-script-build.

In case of a parallel build, this causes race condition between multiple processes. Eventually, build fails, either because script is deleted by another process or when wrong script is executed.

When build scripts do things like setting extra rustc arguments or generate files, build fails in a particularly spectacular way.

As an example, this is what we periodically get on our CI:

error[E0277]: the trait bound `i128: traits::Num` is not satisfied
   --> /usr/local/cargo/registry/src/git.luolix.top-1ecc6299db9ec823/num-integer-0.1.39/src/roots.rs:136:14
    |
136 |         impl Roots for $T {
    |              ^^^^^ the trait `traits::Num` is not implemented for `i128`
...
170 | signed_roots!(i128, u128);
    | -------------------------- in this macro invocation

I think, this happens because num-traits uses build.rs to set has_i128. So, if "wrong" build.rs is being executed, package does not get this flag and eventually its dependency num-integer fails because of an error above (because it sets this flag independently).

Steps

  1. Get sample project from https://github.com/idubrov/cargo-out-dir-bug
  2. This project is nothing more than a 100 empty modules with build.rs files.
  3. Run cargo build -- everything works fine
  4. Run cargo -Z unstable-options build --out-dir=./target
  5. Eventually, build fails with:
error: failed to remove file `/Users/idubrov/Projects/outdir/./target/build-script-build`                                                                                                                                                     

Caused by:
  No such file or directory (os error 2)

Possible Solution(s)

Maybe, treat build.rs output specially from regular outputs? Never place it into the directory specified by --out-dir?

Notes

Output of cargo version:

$ cargo version
cargo 1.31.0-nightly (2d0863f65 2018-10-20)
@idubrov
Copy link
Author

idubrov commented Nov 10, 2018

I guess it is similar to #6293 except that you don't really have control over target name and also build.rs usage is very common.

bors added a commit that referenced this issue Nov 12, 2018
Don't include build scripts in --out-dir.

As I understand the `--out-dir` use cases, these shouldn't be needed.

Closes #6282
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant