[maybe a bug] common dependencies are not unified between main crate and proc-macro crate, if features differ #14740
Labels
A-features
Area: features — conditional compilation
C-bug
Category: bug
S-needs-info
Status: Needs more info, such as a reproduction or more background for a feature request.
Note
I found a simpler repro
If there are three crates, A depends on B and C, B, depends on C, and B is a proc-macro crate and A uses more/different features than B, then crate C is not unified, but instead compiled twice.
Please see the following three repositories:
https://github.com/rustlang-issue-14740/repo-A
https://github.com/rustlang-issue-14740/repo-B
https://github.com/rustlang-issue-14740/repo-C
Clone the last one, run
cargo tree -d
.Expected: empty result
Actual:
IF you edit cargo.toml (in crate C), remove the
, features = ["sub"]
and reruncargo tree -d
, then the result is empty, as expected.Note: there is no patching, there are no different branches. Every crate references only branch "main" of dependencies.
I believe I also understand why this is happening. The proc-macro is compiled and executed. After the macro is expanded, C does not use any exports from the crate B (it can't, since a proc macro crate can't export anything except the proc macros). Therefore I'd guess that from the perspective of cargo, they are two independent compilation targets?
BUT! In my original issue, the dependency chain is deeper, with the proc-macro crate referencing a different proc-macro crate, and using its macros inside the macro. Because the proc-macro and the main app have different features, these macro expansions are not compatible.
I'll try to add that to my example, but at this point I'm not even sure if it's actually a bug anymore. I guess it is, because whether it's a proc-macro crate or not shouldn't influence dependency resolution?
old report
Problem
I'm using a
patch
section to redirect an indirect dependency to my own fork. The main crate directly references this dependency.my main cargo.toml
gdext_coroutines
referencesgodot
from the original repository:https://github.com/0x53A/gdext_coroutines/blob/41fafbd58fb6694f42b67b1c2794461fed52aee3/rust/Cargo.toml#L19-L20
fe-o-godot-macros
referencesgodot
from my fork, but without the additional featureshttps://github.com/0x53A/fe-o-godot-macros/blob/4ef212df813bd166782213bef6fbcf6ffff6db47/Cargo.toml#L11-L12
When I run
cargo build
in my main project, I get compile errors related to the feature"lazy-function-tables"
, as one example:It seems like cargo has a duplicated reference to
0x53A/gdext
and loses the features ("experimental-wasm", "lazy-function-tables") at some point.here is the output of
cargo tree -d
, which I would expect to be emptySteps
cargo build
and observe that it fails,cargo tree -d
prints a list of duplicated dependencies# doesn't work
block and enable the# works
blockcargo build
and observe that it works,cargo tree -d
is emptyPossible Solution(s)
It works when I set the correct repository and features in all packages (inside
gdext_coroutines
andfe-o-godot-macros
.Then compilation succeeds and
cargo tree -d
returns an empty result as expected.Notes
There are a lot of git related issues already open, but most of them are about unifying slightly different urls (like tag vs rev). In my case, the url is exactly the same and they are still not unified.
Version
The text was updated successfully, but these errors were encountered: