Hi fellow rustaceans
While using cargo, I noticed something that seemed strange to me: After building a workspace using cargo build --workspace
, there were some executables where cargo run
still needed to build something before executing them.
As far as I see, this is connected to different executables in the workspace using different features for depending crates, e.g.
app1/Cargo.toml:
[dependencies]
proc-macro2 = { version = "1.0.46", features = ["span-locations"] }
app2/Cargo.toml:
[dependencies]
proc-macro2 = "1.0.46"
So for this example workspace, I can do this:
simon@machina ~/repos/cargo-workspace-build-mwe (git)-[main] % cargo build -p app1 -p app2
Compiling proc-macro2 v1.0.46
Compiling unicode-ident v1.0.4
Compiling app2 v0.1.0 (/Users/simon/repos/cargo-workspace-build-mwe/app2)
Compiling app1 v0.1.0 (/Users/simon/repos/cargo-workspace-build-mwe/app1)
Finished dev [unoptimized + debuginfo] target(s) in 2.83s
Notice that proc-macro2 is only built one time. Furthermore, I can now find target/debug/app1
as well as target/debug/app2
on disk.
simon@machina ~/repos/cargo-workspace-build-mwe (git)-[main] % cargo build -p app1
Finished dev [unoptimized + debuginfo] target(s) in 0.08s
As expected, nothing to do for app1
.
simon@machina ~/repos/cargo-workspace-build-mwe (git)-[main] % cargo build -p app2
Compiling proc-macro2 v1.0.46
Compiling app2 v0.1.0 (/Users/simon/repos/cargo-workspace-build-mwe/app2)
Finished dev [unoptimized + debuginfo] target(s) in 2.11s
For app2
however, the app as well as its dependency is being rebuilt. That is at least not what I expected
Can you tell me whether this is intended behavior or a bug?