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

dev_dependency -> dependency cycle fails to compile crates in correct order/place #432

Closed
huonw opened this issue Aug 25, 2014 · 1 comment

Comments

@huonw
Copy link
Member

huonw commented Aug 25, 2014

$ tree
.
|-- a
|   |-- Cargo.toml
|   `-- src
|       `-- lib.rs
|-- b
|   |-- Cargo.toml
|   `-- src
|       `-- lib.rs
`-- c
    |-- Cargo.toml
    `-- src
        `-- lib.rs

6 directories, 6 files

a

[package]

name = "a"
version = "0.0.1"
authors = []

[dev_dependencies.b]
path = "../b"
[dev_dependencies.c]
path = "../c"
#[cfg(test)] extern crate b;
#[cfg(test)] extern crate c;

b

[package]

name = "b"
version = "0.0.1"
authors = []

[dependencies.a]
path = "../a"
extern crate a;

c

[package]

name = "c"
version = "0.0.1"
authors = []

c/src/lib.rs empty.


.../a $ cargo build
   Compiling a v0.0.1 (.../a)

.../a $ cargo test
   Compiling c v0.0.1 (.../a)
   Compiling a v0.0.1 (.../a)
.../a/src/lib.rs:1:14: 1:29 error: can't find crate for `b`
.../a/src/lib.rs:1 #[cfg(test)] extern crate b;
                                ^~~~~~~~~~~~~~~
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
Could not compile `a`.

To learn more, run the command again with --verbose.

Allowing progress by removing the offending line leads to this:

.../a $ cargo test
   Compiling c v0.0.1 (.../a)
   Compiling a v0.0.1 (.../a)
   Compiling b v0.0.1 (.../a)
Could not compile `b`.

--- stderr
error: extern location does not exist: .../a/target/deps/liba-609ef28031a9b714.rlib
.../b/src/lib.rs:1:1: 1:16 error: can't find crate for `a`
.../b/src/lib.rs:1 extern crate a;
                   ^~~~~~~~~~~~~~~
error: aborting due to 2 previous errors


To learn more, run the command again with --verbose.

If that extern crate is removed (leaving only a/src/lib.rs with anything significant, but b/Cargo.toml with the same dependency), the building becomes racy:

.../a $ rm -rf target && cargo test
   Compiling c v0.0.1 (.../a)
   Compiling a v0.0.1 (.../a)
.../a/src/lib.rs:2:14: 2:29 error: can't find crate for `c`
.../a/src/lib.rs:2 #[cfg(test)] extern crate c;
                                ^~~~~~~~~~~~~~~
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
Could not compile `a`.

To learn more, run the command again with --verbose.

.../a $ rm -rf target && cargo test
   Compiling c v0.0.1 (.../a)
   Compiling a v0.0.1 (.../a)
   Compiling b v0.0.1 (.../a)
     Running target/a-e8d8fdc9319b934d

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured

   Doc-tests a

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured

In summary, the dependency cycle is causing the b library to be built after the a test runner (the first failure), and not even building the a library at all (the second failure), even though the dependency chain is actually:

        `a` library
              |
      [dependencies.a]
              |
        `b` library     `c` library
              |              |
[dev_dependencies.b]   [dev_dependencies.c]
               \           /
              `a` test runner

(which should be fine?)

@huonw
Copy link
Member Author

huonw commented Aug 25, 2014

Example, I want cargo test to test the macro code example there, but the macro crate depends on the main crate, and so the dev dep in the other direction hits this.

bors added a commit that referenced this issue Oct 3, 2014
This is a series of commits which culminates in fixing #432, fixing a number of other related issues along the way. The biggest user-facing fix here is that if you run `cargo build` followed by `cargo test` your library will no longer be rebuilt if you have dev-dependencies.
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

No branches or pull requests

1 participant