Skip to content

Features incorrectly handled when dependency of bindep under both dependencies and build-dependencies #12863

@benpye

Description

@benpye

Problem

Cargo is incorrectly using the features from build-dependencies rather than dependencies when building the crate, in this case it causes a failure as the build target is no_std.

benpye@Bens-MacBook-Pro bindep_repro % cargo build --manifest-path parent/Cargo.toml --target riscv32im-unknown-none-elf -Zbuild-std=core 
   Compiling compiler_builtins v0.1.101
   Compiling core v0.0.0 (/Users/benpye/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core)
   Compiling parent v0.1.0 (/Users/benpye/git/bindep_repro/parent)
   Compiling rustc-std-workspace-core v1.99.0 (/Users/benpye/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling common_dep v0.1.0 (/Users/benpye/git/bindep_repro/common_dep)
error[E0463]: can't find crate for `std`
  |
  = note: the `riscv32im-unknown-none-elf` target may not support the standard library
  = note: `std` is required by `common_dep` because it does not declare `#![no_std]`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

For more information about this error, try `rustc --explain E0463`.
error: could not compile `common_dep` (lib) due to previous error
warning: build failed, waiting for other jobs to finish...

Steps

A minimal repro is available at https://github.com/benpye/rust_bugs/tree/bindep_feature_resolution_bug

The issue can be reproduced with

cargo build --manifest-path parent/Cargo.toml --target riscv32im-unknown-none-elf -Zbuild-std=core

The repro is made up of three crates.

  • A has an artifact dependency on B with target = "target", and includes an (empty) build.rs script.
  • B has both a regular dependency and build dependency on C, the build dependency enables the std feature on C.
  • C is no_std when the std feature is not-enabled.

Possible Solution(s)

No response

Notes

Version

cargo 1.75.0-nightly (8eb8acbb1 2023-10-17)
release: 1.75.0-nightly
commit-hash: 8eb8acbb116e7923ea2ce33a50109933ed5ab375
commit-date: 2023-10-17
host: aarch64-apple-darwin
libgit2: 1.7.1 (sys:0.18.1 vendored)
libcurl: 8.1.2 (sys:0.4.68+curl-8.4.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1u  30 May 2023
os: Mac OS 14.0.0 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-featuresArea: features — conditional compilationC-bugCategory: bugS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Z-bindepsNightly: binary artifact dependencies

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions