`build-dependencies` dependency resolution problem

I have crate A that depends on crate B. They live in the same workspace. The crate B has a build dependency link to crate A i.e. its build.rs uses code from A.

Cargo reports dependency cycle. According to the docs build.rs script lives in a different dependency space from the crate it is a part of.

In my understanding there should be no cyclic dependency as the build.rs script from crate B uses directly crate A which uses B and crate B doesn't use code from A, only its build script does so.

Is this a bug in Cargo or I'm getting this completely wrong?

Here is a Cargo test to demonstrate the problem:

fn build_script_cycle() {
    let p = project()
                name = "a"
                version = "0.1.0"


                b = { path = "../b" }
        ).file("a/src/lib.rs", "")
                name = "b"
                version = "0.1.0"


                a = { path = "../a" }
        ).file("b/src/lib.rs", "")
                members = [

B using code from A isn't the problem, it's that you need A to build B. This is the case whether it's a build dependency or a normal one. To build B you first need to build A to run the build script, and to build A you need to build B, and we're right back where we started.

Ah, that makes perfect sense. Thanks!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.