-
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
Shared build+target dependency crates conflate features #4361
Comments
Okay, it looks like the underlying reason that libc fails to compile in the latter case is a misunderstanding on my part about compiling libc at all on os-less targets, but I still think there's something weird. :) |
IIRC there's another issue or two related to this in Cargo's issue tracker. It's related to how feature resolution works today which happens on a per-crate basis instead of just per-crate-within-a-target basis. |
This may be the same problem I'm hitting?
The build command incorrectly uses default features for
(error is because The only workaround I see is to remove Repo and version: https://github.com/dhardy/rand/tree/53ab77e320184b0950dfbdd44439fd44bdb57700 |
@dhardy I think that's the same issue, yes, but I believe it's because |
I don't really understand why That
|
Note, this is failing with |
@dhardy sorry for the delayed response but Cargo has the concept of a "current package", and flags like @cretz I think that may be unrelated? |
@alexcrichton, yes, likely... sorry |
@alexcrichton I wasn't building anything which depended on |
@dhardy try doing:
and you should see the same error. The |
@alexcrichton that's besides the point. As I understand it,
Yes, this may mean I guess the problem would be more apparent if there was a way to depend on another crate explicitly without certain features; that way there would be a feature resolution error if Cargo tried to build |
@dhardy heh sorry so this is when it quickly balloons into a larger design question! What I meant previously is just to explain what Cargo currently does, and then also what Cargo currently does is that it only ever compiles a crate once, never twice with different feature sets. Cargo by default unions all features for a crates so they're required to be additive, and this has been Cargo's behavior for quite some time as well! In that sense I believe right now |
Heh, yes it is a deeper Cargo design problem. Feature union (half) makes sense when crate X has multiple dependencies within the same build target (single lib or bin), but when the output targets are separate (libs or bins) it doesn't make sense IMO, but as you say Cargo can't do anything else for now. |
Given Rust's 2018 mission of being friendlier to use for embedded systems, I feel that this should be a higher priority. It basically renders it impossible to use any build-time crates which depend on |
This appears to be related to #2589 |
This is in line with best practices recommended by serde[1]. This will also resolve downstream crates depending on shiplift who enable the serde derive feature, due to Cargos unification of features for each crate[2]. [1]: serde-rs/serde#1441 [2]: rust-lang/cargo#4361 (comment)
This is in line with best practices recommended by serde[1]. This will also resolve downstream crates depending on shiplift who enable the serde derive feature, due to Cargos unification of features for each crate[2]. [1]: serde-rs/serde#1441 [2]: rust-lang/cargo#4361 (comment)
Non-unification of build-dependency features has been implemented and is available as a nightly-only feature on the latest nightly 2020-02-23. See the tracking issue at #7915. If people following this issue could try it out, and leave your feedback on the tracking issue (#7915), I would appreciate it. Particularly we'd like to know if it helps your project, does it cause any breakage, and does it significantly increase initial compile time. |
Sorry about the title, this one was hard for me to nail down.
I'm working on a project (embedded, no_std) that relies on both
bindgen
as a build-dependency andlibc
as a dependency. When I setdefault-features = false
in Cargo.toml forlibc
, the use ofbindgen
(which depends uponlibc
) influences the features enabled inlibc
when building for the target. To wit:When
bindgen
is specified as a build-dependency, thelibc
crate is built with the command line:this fails for want of
std
, namelyerror[E0463]: can't find crate for 'std'
.When bindgen is removed, the
libc
crate is build with the command line:this fails for reasons related to missing types (which appears to be a bug in
libc
?), e.g.error[E0412]: cannot find type
c_charin this scope
.The text was updated successfully, but these errors were encountered: