-
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
Linking to native library multiple times through build dependencies #5237
Comments
For the moment you can make |
I know. I am doing that at the moment. My question is whether the constellation where different dependencies of |
cc @Eh2406 Thanks for the report! Unfortunately this may be an exceedingly tricky one to solve. The resolver doesn't understand host/target distinctions as well as linkage, so it can't necessarily conclude the that the linkage here may actually work out.. |
You are quite welcome. If we are honest, I am not being completely selfless here. I know nothing about |
Ya this is going to be tricky to solve. It is related to #2589 but in this case it is a conflict between two different packages build dependencies. If we had a solution to rust-lang/rust#44663 then we would just list all build deps as private dependencies. But that is going to be hard to implement as we don't have any support for path of visibility. |
Oh sorry @bsteinb I misunderstood! It's true that these are both host dependencies which means that I'm not sure Cargo has ever supported this (I thought this may have been an accidenal recent regression) |
Well this is something that recently showed up for the Even if this was not and is not supported by cargo, I am trying to raise the question whether this behaviour might be too strict/pessimistic. |
I can confirm that this is not the new error we just added. So I don't think it is a regression. |
All right, for now I can live with the workaround of pinning my dependencies. When cargo is changed to loosen these restrictions, I can loosen the version specifications again. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The issue I initially described here is not related to what @klausi describes and I do not think it can be solved by #4978. In the case I described, (Just to be clear, I am not saying that the issue @klausi reported is not valid, just that I think it is a different issue from this one.) |
Sorry, yep I think I posted too early in this issue without understanding how the registry index works :) |
Hmm, this is an unfortunate issue. I just ran into it with more recent I've long thought that a crate at the top of the dependency tree could link in any arbitrary number of versions of |
This is to avoid a clash over clang-sys. Workaround for cargo bug rust-lang/cargo#5237.
This avoids a cargo issue rust-lang/cargo#5237 which prevents different build scripts using different versions of libclang-sys.
So if a project P depends on two crates X-sys and Y-sys from crates.io where X-sys and Y-sys are both bindgen generated but use different versions of bindgen that depend on different clang-sys crates, then P is unbuildable using Cargo? |
Tragically, yes, unless you can find older versions of One must almost wonder how this isn't an issue that pops up more frequently. I doubt the average person would ever think that updating their bindgen dependency could be a semver-breaking change... but it very well can be! |
Just ran into this again - I have a 3-way bindgen fight between libnfs-sys, libffi-sys and zstd-sys. |
Same problem, but: imgui-sdl2 -> sdl2-sys, ggez -> sdl2-sys |
I am running into this issue with bindgen and I thought I could work around it with [patch.crates-io]
bindgen = { git = "https://github.com/rust-lang/rust-bindgen", tag = "v0.50.0" } (since v0.50.0 is the more recent of the two versions at play), but evidently that didn't actually work - the 0.50.0 dependency was replaced but the older dependency was not. Is there a way to work around this issue without going to each transitive dependency and asking them to update bindgen? If build dependencies are only required while building the build script, then this definitely shouldn't be happening at all, since it's not like build scripts can depend on each other. If the resolver doesn't know about build vs. regular dependencies, that seems fixable; if anybody wants to point me towards where that would belong, I can take a stab at fixing it. I went ahead and took a look at changing it myself, but i'd probably have to change Cargo's "all the dependencies that matter are one big DAG" entirely, and that's a little audacious to take on myself. |
I've also just run into this, with a private crate conflicting with lttng-ust-generate (bindgen versions 0.51.0 and 0.32.3 respectively). |
Due to rust-lang/cargo#5237, upgrading bindgen is not backward compatible. Signed-off-by: Jay Lee <[email protected]>
Due to rust-lang/cargo#5237, upgrading bindgen is not backward compatible. Signed-off-by: Jay Lee <[email protected]>
Due to rust-lang/cargo#5237, upgrading bindgen is not backward compatible. Signed-off-by: Jay Lee <[email protected]>
I am getting this when trying to use
is there any solution to this, I mean other than trying out different version combinations in hopes of finding a working combination by chance? |
Same problem hit. Is there really any reason to insist on crate unification, when the different crate versions would really be used for building different binaries? |
If there were progress it would be listed here. It is still a hard problem. |
I don't see a description of the difficulty here, it would be great to see where this is heading. From an outsider point of view it looks like each Is it more than "just" finding the right criteria to get |
As you point out, once you have a complete dependency graph selected it is fairly easy to check before linking whether this particular call will lead to linking multiple crates with the same "links" field. Unfortunately, by the linking stage is far too late to determine if there is a different dependency graph that would allow the build to succeed. The much earlier stage that determines which complete dependency graph to select is called dependency resolution. We added functionality to ban a dependency graph that has two crates with the same "links" field. Most of the time this means that cargo automatically does the right thing, picking dependencies that will work, so that no error message needs to come to the user at all. This is one of the cases where that functionality creates a false positive. To make the functionality more accurate dependency resolution would need to keep track of not only the set of packages that have been chosen with the set of requirements not yet fulfilled, but also a fully constructed graph data structure. So that we can answer queries about "if I add Without a efficient encoding the dependency resolver ends up trying an exponential number of graphs in determining whether there is a solution that avoids the problem. Even if the encoding is efficient if it doesn't compose with other conflicts then situations like "three versions have links conflict and the other two are semver compatible with a prior selection" end up triggering an exponential number of graphs to try. |
Bindgen versions need to be compatible because of a cargo limitation: rust-lang/cargo#5237
Is this resolved by using resolver version 2? If not, why? https://doc.rust-lang.org/edition-guide/rust-2021/default-cargo-resolver.html |
"resolver version 2" is implemented as a "feature resolver" pass that runs after the "dependency resolution" where this error is coming from. My last comment explains why it is hard to allow within the "dependency resolution". |
Recently the
mpi
crate has stopped building because it transitively depends on different versions of theclang-sys
crate which links to the nativelibclang
. Here is the error message:I understand that this would be a problem if both versions of the
clang-sys
crate were to end up being linked to by thempi
crate, but they do not.bindgen
(and transitivelyclang-sys
) in both cases is a build dependency ofmpi-sys
andlibffi-sys
and is only linked to their respectivebuild
scripts and does not end up in thempi
crate. Should this really be an error, or iscargo
being too cautious here?The text was updated successfully, but these errors were encountered: