Skip to content
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

A dependency in both [dependencies] and [build-dependencies] has both feature sets combined #8759

Closed
chbaker0 opened this issue Oct 8, 2020 · 3 comments
Labels
C-bug Category: bug

Comments

@chbaker0
Copy link

chbaker0 commented Oct 8, 2020

Problem

I have a no_std crate which depends on another crate, arrayvec. arrayvec only uses std if the corresponding crate feature is enabled (which is on by default). I disable its default features in my crate's Cargo.toml, which should make it no_std.

My crate additionally has a build-dependency on nasm-rs which itself depends on arrayvec. It uses the default features, meaning nasm-rs's arrayvec should use std.

I'm finding that this combination makes my build fail. Cargo attempts to use arrayvec with std in my normal build.

I expected Cargo to build arrayvec without default features in the main build, and with default features for build.rs. It seems to be combining the feature sets instead.

A crate that repros this error: https://github.com/chbaker0/build-dep-failure-repro

Steps

  1. Attempt to build https://github.com/chbaker0/build-dep-failure-repro on latest nightly.
  2. Observe the failure:
   Compiling arrayvec v0.5.1
error[E0463]: can't find crate for `std`
  |
  = note: the `i686-unknown-none-4984653564076209026` target may not be installed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `arrayvec`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
  1. Comment out dependency nasm-rs:

...
[build-dependencies]
# Commenting out this dependency makes the build succeed.
# nasm-rs = "0.2.0"
  1. Observe successful build:
$ cargo build
   Compiling arrayvec v0.5.1
   Compiling build-dep-failure-repro v0.1.0 (/home/collin/development/build-dep-failure-repro)
    Finished dev [unoptimized + debuginfo] target(s) in 0.26s

Possible Solution(s)

Notes

Output of cargo version:
cargo 1.48.0-nightly (75615f8 2020-09-29)

I'm using a custom build target which might be part of the problem.

@chbaker0 chbaker0 added the C-bug Category: bug label Oct 8, 2020
@ehuss
Copy link
Contributor

ehuss commented Oct 8, 2020

Thanks for making the repro! There is an nightly-only feature (-Zfeatures=host_dep) which will decouple the features from build-dependencies. You can read about it in the docs and follow the tracking issue (#7915) for updates.

@chbaker0
Copy link
Author

chbaker0 commented Oct 8, 2020

Ah my bad! I should've searched more

@ehuss
Copy link
Contributor

ehuss commented Nov 30, 2020

Closing this in favor of the tracking issue #7915.

@ehuss ehuss closed this as completed Nov 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants