`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:

#[cargo_test]
fn build_script_cycle() {
    let p = project()
        .file("a/Cargo.toml",
               r#"
                [project]
                name = "a"
                version = "0.1.0"

                [lib]

                [dependencies]
                b = { path = "../b" }
                "#,
        ).file("a/src/lib.rs", "")
        .file("b/Cargo.toml",
                r#"
                [project]
                name = "b"
                version = "0.1.0"

                [lib]

                [build-dependencies]
                a = { path = "../a" }
                "#,
        ).file("b/src/lib.rs", "")
        .file("Cargo.toml",
              r#"
                [workspace]
                members = [
                    "a",
                    "b"
                ]
              "#,
        ).build();
    p.cargo("check").run();
}

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!