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

Cargo ignores indirect dependency feature selection #8253

Closed
theunkn0wn1 opened this issue May 18, 2020 · 3 comments
Closed

Cargo ignores indirect dependency feature selection #8253

theunkn0wn1 opened this issue May 18, 2020 · 3 comments
Labels
C-bug Category: bug

Comments

@theunkn0wn1
Copy link

Problem
When building project dependencies, feature selection from indirect dependencies appear to be ignored, which can result in build failures in circumstances where features get opted-into that were configured to be opted-out. This can produce build failures as some std requiring features in otherwise no_std crates are turned on.

What Currently happens:
When building the upstream library against a target that does not have the std crate, the build succeeds (As expected).

When building the downstream application against the same target, WITH the upstream library specified as a dependency, the build fails (cannot find crate for std)

What I expect to happen:
building the downstream should succeed, and the upstream dependencies retain their feature configuration (unless explicitly overridden by the downstream application).

Steps

  1. git clone https://github.com/theunkn0wn1/cargo_bug_repo_0.git
  2. cd cargo_bug_report_0
  3. docker build .
$ docker build .                  
Sending build context to Docker daemon    194kB
Step 1/7 : FROM rust
 ---> 84ba1f55dee3
Step 2/7 : ADD project /project
 ---> Using cache
 ---> 49126adfc4e2
Step 3/7 : RUN  rustup target add thumbv7em-none-eabihf
 ---> Using cache
 ---> 295dc9ff58c9
Step 4/7 : WORKDIR /project/upstream_lib/my_lib
 ---> Running in fa11316d7cab
Removing intermediate container fa11316d7cab
 ---> aec209d34f56
Step 5/7 : RUN cargo build --target thumbv7em-none-eabihf
 ---> Running in 96adcf9c0e9f
    Updating git repository `https://github.com/danburkert/prost.git`
    Updating crates.io index
 Downloading crates ...
  Downloaded proc-macro2 v1.0.13
  Downloaded quote v1.0.6
  Downloaded syn v1.0.22
  Downloaded itertools v0.9.0
  Downloaded anyhow v1.0.31
  Downloaded bytes v0.5.4
  Downloaded unicode-xid v0.2.0
  Downloaded either v1.5.3
   Compiling proc-macro2 v1.0.13
   Compiling unicode-xid v0.2.0
   Compiling syn v1.0.22
   Compiling anyhow v1.0.31
   Compiling either v1.5.3
   Compiling bytes v0.5.4
   Compiling itertools v0.9.0
   Compiling quote v1.0.6
   Compiling prost-derive v0.6.1 (https://github.com/danburkert/prost.git#80256277)
   Compiling prost v0.6.1 (https://github.com/danburkert/prost.git#80256277)
   Compiling prost-types v0.6.1 (https://github.com/danburkert/prost.git#80256277)
   Compiling my_lib v0.1.0 (/project/upstream_lib/my_lib)
    Finished dev [unoptimized + debuginfo] target(s) in 36.82s
Removing intermediate container 96adcf9c0e9f
 ---> 45072de0df9a
Step 6/7 : WORKDIR /project/downstream_application/some_application
 ---> Running in 2966d4c24da3
Removing intermediate container 2966d4c24da3
 ---> 4864d7d17ac8
Step 7/7 : RUN cargo build --target thumbv7em-none-eabihf
 ---> Running in f0fb3dc89155
   Compiling proc-macro2 v1.0.13
   Compiling unicode-xid v0.2.0
   Compiling anyhow v1.0.31
   Compiling syn v1.0.22
   Compiling either v1.5.3
   Compiling bytes v0.5.4
   Compiling itertools v0.9.0
   Compiling quote v1.0.6
   Compiling prost-derive v0.6.1 (https://github.com/danburkert/prost.git#80256277)
   Compiling prost v0.6.1 (https://github.com/danburkert/prost.git#80256277)
   Compiling prost-types v0.6.1 (https://github.com/danburkert/prost.git#80256277)
   Compiling my_lib v0.1.0 (/project/upstream_lib/my_lib)
   Compiling some_application v0.1.0 (/project/downstream_application/some_application)
error[E0463]: can't find crate for `std`
  |
  = note: the `thumbv7em-none-eabihf` 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 `some_application`.

To learn more, run the command again with --verbose.
The command '/bin/sh -c cargo build --target thumbv7em-none-eabihf' returned a non-zero code: 101

Possible Solution(s)

Notes
This occurs regardless of how the upstream dependency is specified, occurs with local paths, crates.io dependencies, and private Git dependencies.

Output of cargo version:

$ cargo --version
cargo 1.43.0 (3532cf738 2020-03-17)

Additional context:
I am targeting an embedded platform, specifically using the thumbv7em-none-eabihf toolchain.
While prost was used as the example for my above demonstration, this has also hit me with other, unrelated dependencies that also deselect features in their dependencies.

Issue reproduced in docker, however is reproduce-able outside containers.

OS: Ubuntu 19.10 x64

@theunkn0wn1 theunkn0wn1 added the C-bug Category: bug label May 18, 2020
@ehuss
Copy link
Contributor

ehuss commented May 18, 2020

Have you tried the new feature resolver? It looks like you have some build dependencies, maybe those are adding the features you don't want? There is documentation for it here, and there is a new global opt-in documented here where you add resolver = "2" to your package definition.

@theunkn0wn1
Copy link
Author

Switched to nightly and built my project using
cargo -Zfeatures=all build
and the project compiled successfully; appears nightly's new resolver does a better job at handling feature selections.
also builds if resolver = "2" is specified in my downstream's Cargo.toml

applying these changes to my above docker example fixes the above build error as well.

@ehuss
Copy link
Contributor

ehuss commented May 18, 2020

Sounds good. You can follow the tracking issue #8088 if you want updates.

@ehuss ehuss closed this as completed May 18, 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