Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upBuild Deps getting mixed in with dependencies #2589
Comments
This comment has been minimized.
This comment has been minimized.
|
Interesting! This is, unfortunately, intended behavior. The resolution phase of Cargo doesn't know about target-specific or build dependencies, it just resolves everything, so the standard feature activation applies where features are all unioned. That is, To disable default features you'll have to ensure that all crates in the dependency graph don't use the default feature, regardless of whether they're part of a build script or not. |
This comment has been minimized.
This comment has been minimized.
|
I don't actually know how I would fix this though, as I can't turn off Or when cross compiling, it should make absolutely no difference how the packages are compiled in build deps phase, as they are going to be running on a different machine afterwards, so it's not like you need to try and re-use artifacts between the two. I feel like the build deps should be sealed off from the rest of your deps completely, as there are two completely different environments they are running in. As a short term workaround, I could clone the log crate and create a |
This comment has been minimized.
This comment has been minimized.
|
Unfortunately this just isn't how features work in Cargo. When you depend on something you can't depend on it only with one set of features as all other features get unioned. This means that if a dependency is shared then both dependants will receive the same feature set. |
This comment has been minimized.
This comment has been minimized.
|
I'm not happy, as at the end of the day, I can't use the log crate. I see a couple of places that might be at fault.
If I made an RFC for proposing My possible workarounds consist of duplicating crates under different names, or moving the build.rs in to a separate crate, which then depends on things as normal, and using a makefile to co-ordinate builds between them. Neither of these solutions are particularly nice. |
This comment has been minimized.
This comment has been minimized.
|
You should of course feel free too propose an RFC! I'd recommend trying to understand what's in play currently and think through how it can be changed first, however. Right now features are resolved at resolution time because they can introduce new dependencies which need to be applied. Features are also not a property of an edge in a dependency graph but a property of a node, which is to say that there is no way for you to depend on log with only some features activated, but rather you have to mutate the Along those lines, and RFC could perhaps tweak aspects like:
etc. |
This comment has been minimized.
This comment has been minimized.
|
I think the approach I'd take with the RFC would be to push to isolate build deps in the resolution phase. Essentially, I think it a project like
could be transformed into something looking like
where we run the main binary from build-dep in the directory of project automatically just like Of course, it would be nice to optimize for the common case where it's actually okay to share dependencies and not rebuild everything twice. Because I feel like the problem here is that there really are two distinct trees of dependencies, and any sharing they do is incidental. |
This comment has been minimized.
This comment has been minimized.
|
Oh, and I feel like features are actually not the main part of this, as I also had problems when the |
This comment has been minimized.
This comment has been minimized.
|
The "desugaring" you mentioned above is basically what happens today, the crux of this is indeed feature sharing. The same node in the dependency graph, |
This comment has been minimized.
This comment has been minimized.
pka
commented
Jun 8, 2016
|
I think I have the same problem, trying to use different features on Linux and Windows. I tried to declare it in different ways, here's the most explicit:
But cargo tries to compile unix_socket on Windows as well and fails. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
It seems to me that this also is causing a blocker for Servo, because it makes https://github.com/serde-rs/serde#using-serde-with-stable-rust-and-serde_codegen not work anymore. @alexcrichton You seem to be saying it has always been this way, but are you sure? How does anyone let users decide whether they want to go through serde_macros or just serde_codegen then? |
This comment has been minimized.
This comment has been minimized.
|
Try this on webrender_traits:
The intended result is that serde_codegen doesn't get build with syntex_syntax because it then gets pulled in only with default features through serde_macros. Unfortunately it doesn't happen and the with-syntex feature of serde_codegen still gets pulled in. |
This comment has been minimized.
This comment has been minimized.
This sounds like a regression because Serde seems to rely on this idiom. |
This comment has been minimized.
This comment has been minimized.
|
@nox I was under the impression that servo would only have one dependency on |
This comment has been minimized.
This comment has been minimized.
|
Oof, I just hit this with Do you foresee (a correct implementation of) separate dependency graphs causing any build problems or compatibility issues? |
This comment has been minimized.
This comment has been minimized.
cyplo
commented
Mar 4, 2017
|
Hello ! Any consensus/news on this one ? |
acmcarther
referenced this issue
Mar 17, 2017
Closed
Support linking multiple crates with the same name within a single build rule #39
This comment has been minimized.
This comment has been minimized.
ghost
commented
Mar 20, 2017
|
I just hit the same issue while cross-compiling for |
This comment has been minimized.
This comment has been minimized.
fallen751
commented
Sep 5, 2017
•
|
I wanted to second the fact that this is quite annoying to deal with when cross compiling. It makes using build scripts in a no_std environment quite cumbersome. Right now the "best" solution is to use manually specify the crate git in your [dependencies] section so you get two separate dependencies nodes. In general, it's very unintuitive that build dependencies for your host target and real dependencies for your cross-compilation target with different feature sets get resolved to the same dependency by cargo. |
carols10cents
added
A-build-dependencies
A-dependency-resolution
A-features
C-feature-request
labels
Sep 25, 2017
aturon
assigned
withoutboats
Jan 22, 2018
This comment has been minimized.
This comment has been minimized.
|
We talked about this in the cargo team meeting today. What surprises me about this is that we generate a single resolution graph and then figure out what kind of dependencies they are. I would expect that we would generate a resolution graph for build dependencies totally separate from normal dependencies. Then, when generating the lock file and build plan, after figuring out features and so on, we merge the sets of dependency nodes from the two graphs, to dedup dependencies where possible (but this is an optimization). |
This comment has been minimized.
This comment has been minimized.
valff
commented
Feb 16, 2018
|
I ran into the same issue in [dependencies.failure]
version = "0.1"
default-features = false
[build-dependencies.failure]
git = "https://github.com/withoutboats/failure"
branch = "version-0.1"
default-features = false
features = ["std"]It fails with I can't use |
valff
added a commit
to drone-os/drone-mirror-failure
that referenced
this issue
Feb 16, 2018
alexcrichton
referenced this issue
Mar 5, 2018
Merged
Emit Resolve.features_sorted in "cargo metadata" #5122
alexcrichton
referenced this issue
Apr 6, 2018
Closed
Crates used by proc-macro crates can change features enabled in normal crates #5304
This comment has been minimized.
This comment has been minimized.
et1975
commented
Jun 28, 2018
|
Not sure if it's in the same ballpark, but I'd like to build tests with different set of dev-dependencies from examples as I expect to run the tests on the build host, but examples on |
Pzixel
referenced this issue
Jul 16, 2018
Closed
pwasm-abi-derive is not compatible with no-std libs #54
This comment has been minimized.
This comment has been minimized.
wmiller848
commented
Aug 7, 2018
•
|
This has become a headache (among many) for a nostd project I am working on. We are building kernel extensions and mock out all of the kernel interface for testing in user land. The particular dependency causing us a lot of pain is The issue we run into is when the top level project wants to include a dev-dependancy of The work around is we can change our dev-dependency when we want to test vs compile a release but that of course only illustrates how crazy this behavior is. Welcome to nostd dev in rust |
This comment has been minimized.
This comment has been minimized.
lovesegfault
commented
Sep 10, 2018
|
Is there any update on this? It seems like a pretty important issue but apparently backlogged? |
sorpaas
added a commit
to sorpaas/bls
that referenced
this issue
Sep 28, 2018
emilio
referenced this issue
Oct 15, 2018
Closed
Remove serde_derive dependency, inlining expanded impls into source code #222
This comment has been minimized.
This comment has been minimized.
emilio
commented
Oct 15, 2018
|
@alexcrichton is there any update on this? Is there any chance you or anybody else could take it or explain a path forward to fixing this? This is a major pain for build-time dependencies, since it prevents us from using a lot of crates, or worse yet, from updating them. To be honest I'd rather spend a couple weeks fixing this than having to land stuff like eqrion/cbindgen#222, for example... |
This comment has been minimized.
This comment has been minimized.
emilio
commented
Oct 15, 2018
|
(Read that as an "I'm volunteering to take a look in my free time to this as long as I can ask questions to somebody" :P) |
This comment has been minimized.
This comment has been minimized.
|
@emilio I've been looking at this recently. The solution may take a while since it may require extensive changes. I feel like it's a high priority issue, so I'm going to continue pushing to make something happen. |
This comment has been minimized.
This comment has been minimized.
emilio
commented
Oct 16, 2018
|
@ehuss that's amazing to know, thank you! Let me know if you have cargo-begginner-friendly-ish work you could get a hand with :) |
ra-kete
added a commit
to ra-kete/cstr_core
that referenced
this issue
Oct 26, 2018
cuviper
referenced this issue
Nov 5, 2018
Closed
Update clang-sys, cexpr, which to latest versions #1407
emilio
referenced this issue
Nov 11, 2018
Closed
Adding bindgen to build-dependencies prevents crate from being no_std #1439
ignatenkobrain
referenced
this issue
in varlink/rust
Dec 10, 2018
alexcrichton
referenced this issue
Dec 18, 2018
Closed
`cargo test --all` passed but `cargo test` failed #6458
This comment has been minimized.
This comment has been minimized.
tarcieri
commented
Jan 27, 2019
This comment has been minimized.
This comment has been minimized.
|
Build and dev dependencies are slightly different. You can have a fully independent copy of a build dependency since they are never linked into the same binary. For dev dependencies you might be passing values from that dependency into the crate under test, which requires that you use the same instantiation of the crate. (Basically, it seems to me that the dev-dependency case is slightly more complex, so having a separate issue to discuss it would be useful). |
This comment has been minimized.
This comment has been minimized.
tarcieri
commented
Jan 27, 2019
•
|
@Nemo157 here is a reproduction of a build dependency (bindgen) triggering inclusion of https://github.com/coolreader18/rsspire/blob/weird-std/nspire-sys/Cargo.toml#L10 Here is a reddit thread about the above repro: https://www.reddit.com/r/rust/comments/a91qv0/for_a_no_std_crate_libstd_is_still_included_in/ In my personal observation many people are encountering this particular issue, especially in regard to tools like bindgen which use several dependencies which have an optional |
This comment has been minimized.
This comment has been minimized.
|
@tarcieri I’m referring to the eventual result of fixing these issues, not to the status quo, the implementation for each will be slightly different. |
This comment has been minimized.
This comment has been minimized.
tarcieri
commented
Jan 27, 2019
•
|
I'm looking into what it would take to actually fix this and will post my results on #4866 (my preferred writeup on this issue) |
tbelaire commentedApr 17, 2016
I am trying to depend on the
logcrate for my rust.ko project, butlogis already in use inbindgen, one of my build dependencies.bindgenuseslogwith theuse_stdfeature, which is totally fine as that's running normally. However, when I addlogto be build withdefault-features = falsefor the kernel module, which cannot usestd, I get errors where cargo tries to build, aslogtries to findstd.build transcript:
https://gist.github.com/tbelaire/a98527cf5d946e7c2fd4823dd16126a6
Cargo.lock:
https://gist.github.com/tbelaire/f0f89e8a21f9ce5498df07b6ec8e3a0c