You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cargo has a race condition when a bin and an example have the same name (it's possible there's more when you add tests and benches into the mix, but I haven't checked).
Since the final exacutables and their intermediate build artifacts end up with the same path, if they're built in parallel (e.g. with cargo test), things get weird.
This could be fixed in multiple ways (separate directories, unique temporary paths, locking), but maybe we can just require that each binary have a unique name? Looking at Cargo codebase itself, that seems to be the convention anyway.
Here's how to reproduce the issue:
Create a project with a bin and example named foo:
cargo new racer
cd racer
mkdir -p src/bin
echo 'fn main() { println!("this is a bin"); }' > src/bin/foo.rs
mkdir -p examples
echo 'fn main() { println!("this is an example"); }' > examples/foo.rs
Now run cargo test multiple times (make sure you delete the target dir between each run). You'll randomly get one of the outputs below. If you pass -j 1, the output is consistent and without errors (but one of the executables gets overwritten by the other one).
ICE
$ rm -rf target && cargo test -v
Compiling racer v0.0.1 (file:///home/thomas/tmp/racer)
Running `rustc /home/thomas/tmp/racer/src/lib.rs --crate-name racer --crate-type lib -g -C metadata=9486f62a93fdeee8 -C extra-filename=-9486f62a93fdeee8 --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-lib-racer -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps`
Running `rustc /home/thomas/tmp/racer/src/lib.rs --crate-name racer --crate-type lib -g --test -C metadata=3fa6c9bb6b4c36ba -C extra-filename=-3fa6c9bb6b4c36ba --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-test-lib-racer -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps`
Running `rustc /home/thomas/tmp/racer/src/bin/foo.rs --crate-name foo --crate-type bin -g --test -C metadata=f183869c62948094 -C extra-filename=-f183869c62948094 --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-test-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
Running `rustc /home/thomas/tmp/racer/src/bin/foo.rs --crate-name foo --crate-type bin -g --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
Running `rustc /home/thomas/tmp/racer/examples/foo.rs --crate-name foo --crate-type bin -g --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
/home/thomas/tmp/racer/src/bin/foo.rs:1:1: 1:41 warning: function is never used: `main`, #[warn(dead_code)] on by default
/home/thomas/tmp/racer/src/bin/foo.rs:1 fn main() { println!("this is a bin"); }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' failed at 'called `Result::unwrap()` on an `Err` value: couldn't copy path (the source path is not an existing file; from=/home/thomas/tmp/racer/target/foo.0.o; to=/home/thomas/tmp/racer/target/foo.o)', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libcore/result.rs:808
Build failed, waiting for other jobs to finish...
Could not compile `racer`.
Caused by:
Process didn't exit successfully: `rustc /home/thomas/tmp/racer/src/bin/foo.rs --crate-name foo --crate-type bin -g --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib` (status=101)
Failed test compilation with an unlink path error:
$ rm -rf target && cargo test -v
Compiling racer v0.0.1 (file:///home/thomas/tmp/racer)
Running `rustc /home/thomas/tmp/racer/src/lib.rs --crate-name racer --crate-type lib -g -C metadata=9486f62a93fdeee8 -C extra-filename=-9486f62a93fdeee8 --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-lib-racer -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps`
Running `rustc /home/thomas/tmp/racer/src/lib.rs --crate-name racer --crate-type lib -g --test -C metadata=3fa6c9bb6b4c36ba -C extra-filename=-3fa6c9bb6b4c36ba --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-test-lib-racer -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps`
Running `rustc /home/thomas/tmp/racer/src/bin/foo.rs --crate-name foo --crate-type bin -g --test -C metadata=f183869c62948094 -C extra-filename=-f183869c62948094 --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-test-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
Running `rustc /home/thomas/tmp/racer/src/bin/foo.rs --crate-name foo --crate-type bin -g --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
Running `rustc /home/thomas/tmp/racer/examples/foo.rs --crate-name foo --crate-type bin -g --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
/home/thomas/tmp/racer/src/bin/foo.rs:1:1: 1:41 warning: function is never used: `main`, #[warn(dead_code)] on by default
/home/thomas/tmp/racer/src/bin/foo.rs:1 fn main() { println!("this is a bin"); }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: failed to remove /home/thomas/tmp/racer/target/foo.0.o: couldn't unlink path (no such file or directory (No such file or directory); path=/home/thomas/tmp/racer/target/foo.0.o)
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
Could not compile `racer`.
Caused by:
Process didn't exit successfully: `rustc /home/thomas/tmp/racer/src/bin/foo.rs --crate-name foo --crate-type bin -g --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib` (status=101)
Successful test run with an unlink path error:
$ rm -rf target && cargo test -v
Compiling racer v0.0.1 (file:///home/thomas/tmp/racer)
Running `rustc /home/thomas/tmp/racer/src/lib.rs --crate-name racer --crate-type lib -g -C metadata=9486f62a93fdeee8 -C extra-filename=-9486f62a93fdeee8 --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-lib-racer -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps`
Running `rustc /home/thomas/tmp/racer/src/lib.rs --crate-name racer --crate-type lib -g --test -C metadata=3fa6c9bb6b4c36ba -C extra-filename=-3fa6c9bb6b4c36ba --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-test-lib-racer -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps`
Running `rustc /home/thomas/tmp/racer/src/bin/foo.rs --crate-name foo --crate-type bin -g --test -C metadata=f183869c62948094 -C extra-filename=-f183869c62948094 --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-test-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
Running `rustc /home/thomas/tmp/racer/src/bin/foo.rs --crate-name foo --crate-type bin -g --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
Running `rustc /home/thomas/tmp/racer/examples/foo.rs --crate-name foo --crate-type bin -g --out-dir /home/thomas/tmp/racer/target --dep-info /home/thomas/tmp/racer/target/.fingerprint/racer-9486f62a93fdeee8/dep-bin-foo -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
/home/thomas/tmp/racer/src/bin/foo.rs:1:1: 1:41 warning: function is never used: `main`, #[warn(dead_code)] on by default
/home/thomas/tmp/racer/src/bin/foo.rs:1 fn main() { println!("this is a bin"); }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: failed to remove /home/thomas/tmp/racer/target/foo.o: couldn't unlink path (no such file or directory (No such file or directory); path=/home/thomas/tmp/racer/target/foo.o)
error: failed to remove /home/thomas/tmp/racer/target/foo.metadata.o: couldn't unlink path (no such file or directory (No such file or directory); path=/home/thomas/tmp/racer/target/foo.metadata.o)
Running `/home/thomas/tmp/racer/target/foo-f183869c62948094`
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
Running `/home/thomas/tmp/racer/target/racer-3fa6c9bb6b4c36ba`
running 1 test
test it_works ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
Doc-tests racer
Running `rustdoc --test /home/thomas/tmp/racer/src/lib.rs --crate-name racer -L /home/thomas/tmp/racer/target -L /home/thomas/tmp/racer/target/deps --extern racer=/home/thomas/tmp/racer/target/libracer-9486f62a93fdeee8.rlib`
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
This ends up killing two birds with one stone! The rationale behind this is that
the example and bin namespaces are not the same, and we don't mix metadata into
either filename, so the outputs need to be in different locations.
Closesrust-lang#193Closesrust-lang#751
This ends up killing two birds with one stone! The rationale behind this is that
the example and bin namespaces are not the same, and we don't mix metadata into
either filename, so the outputs need to be in different locations.
Closes#193Closes#751
Cargo has a race condition when a bin and an example have the same name (it's possible there's more when you add tests and benches into the mix, but I haven't checked).
Since the final exacutables and their intermediate build artifacts end up with the same path, if they're built in parallel (e.g. with
cargo test
), things get weird.This could be fixed in multiple ways (separate directories, unique temporary paths, locking), but maybe we can just require that each binary have a unique name? Looking at Cargo codebase itself, that seems to be the convention anyway.
Here's how to reproduce the issue:
Create a project with a bin and example named
foo
:Now run
cargo test
multiple times (make sure you delete thetarget
dir between each run). You'll randomly get one of the outputs below. If you pass-j 1
, the output is consistent and without errors (but one of the executables gets overwritten by the other one).This seems vaguely related to issue #354.
The text was updated successfully, but these errors were encountered: