-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
cargo tree
doesn't handle transitive duplications properly
#9599
Comments
I also feel not right to replicate the logic. Love to know the downsides about reuse |
The main problem is that UnitGraph is based on compilation units, whereas For example, all the intra-package dependencies would need to be removed. Also, UnitGraph has multiple roots for a package (for example, if the package has multiple bins). Another example is build scripts, where the "run" unit depends on all transitive build scripts being run. Those are not real dependencies to be displayed. And conversely there is information missing from UnitGraph (like which dependencies are build-dependencies or dev-dependencies). That information is lost since the Resolve is discarded after the graph is computed. Another problem is that the Graph built for A concern is that attempting to share the code will end up needing more code to handle the impedance mismatch, and will be harder to maintain. So, I think this is a fairly hard problem, mostly trying to balance the maintainability of the code. I don't really know what the right solution is. |
Hello. I would like to pick this task up. I will timebox 1 week for this, before I start my new job. If I haven't made any progress by then, I will park it and let someone else have a go. (for context: I am currently using a copy-pasta of What should I be aiming for here? One possible approach might be:
This is quite an invasive approach, and probably isn't feasible in 1 week. I know I could just try to fix my immediate problem as a one-off, but it feels like it will be a game of whack-a-mole (see also #10651). Having a fuzzer would let me feel much more confident in the correctness of any fix I write). I wonder if we could write the UnitGraph -> Graph conversion function from (1) (but not its inverse), and then write a fuzzer that sets up a random cargo workspace, and then checks that I haven't quite put my finger on what a random workspace generator would look like, or whether it would be able to cover all of the cases that we care about. Does anyone have any thoughts, or should I just have a crack at it and see how far I get? |
Looks like a big plan! Previously I was asking using unit graph instead, but the reply from ehuss made me wonder it may be really challenging. I would recommend experimenting on what you list in the first step, and then assert against the current output first. Fuzzer/protest can be added after we're all happy with the change. I cannot guarantee things will get merged, though it is still great to explore any possibility to reduce code complexity and discrepancy between |
Thanks for your feedback. I will be working in the open on #11379, if you want to follow along (it's not very interesting at the moment though).
Yeah, it looks like there are already quite a lot of
That's fine - I need to build something like this for |
I wonder is this why I got such strange output from [dependencies]
async-compression = "=0.3.15"
nmea = "=0.2.0"
[build-dependencies]
bindgen = { version = "0.64.0", default-features = false, features = ["runtime"] }
according to |
cargo/src/cargo/ops/tree/graph.rs Lines 217 to 219 in 580dbc6
This is how it caculates duplicates currently, so by the implementation a dependency with a different feature set is considered a duplicate. |
Problem
There are some situations where
cargo tree
will mark a package as a duplicate(*)
when it probably shouldn't (and shows the wrong features with--no-dedupe
). This arises when a package is built twice with the same features, but with different dependencies.A real-world example is when looking at the following:
Running
cargo tree -f '{p} {f}'
results in:The problem is the diesel-issue → diesel_migrations → migrations_macros → migrations_internals. It has a
(*)
to indicate that it is duplicated. However, migrations_internals is built twice, and this is deceiving because the second migrations_internals has a dependency on diesel with no features.Running with
--no-dedupe
is even worse, because it shows the wrong features fordiesel
under migrations_internals.Steps
The following is an example in Cargo's testsuite format:
Possible Solution(s)
The issue is that
cargo tree
doesn't have the same logic that was added in #8701 to accommodate dependencies that are the same, but link to different dependencies.I have toyed with the idea of changing
cargo tree
to use theUnitGraph
computed for a normal build instead of trying to recreate how some of these things are computed. There are some complexities and downsides to that approach, but I continue to feel that trying to replicate this logic in multiple places is not a good idea.Notes
Output of
cargo version
: cargo 1.54.0-nightly (4445667 2021-06-12)The text was updated successfully, but these errors were encountered: