-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
For this src/lib.rs
, compiling with various configurations produces some weird results. I'm using bitflags
as a random example, I don't think there's anything special about it:
use bitflags;
pub fn f() {}
This Cargo.toml fails, as expected (I am on linux, flip to cfg(unix)
or whatever if you're on windows):
[package]
name = "rusttest"
version = "0.1.0"
edition = "2018"
[target.'cfg(windows)'.dependencies]
bitflags = ""
# [target.'cfg(not(windows))'.build-dependencies]
# bitflags = ""
error[E0432]: unresolved import `bitflags`
--> src/lib.rs:1:5
|
1 | use bitflags;
| ^^^^^^^^ no external crate `bitflags`
This Cargo.toml also fails, as expected, with the same error.
[package]
name = "rusttest"
version = "0.1.0"
edition = "2018"
# [target.'cfg(windows)'.dependencies]
# bitflags = ""
[target.'cfg(not(windows))'.build-dependencies]
bitflags = ""
But, this Cargo.toml succeeds compilation, very unexpectedly (with a warning: unused import: bitflags
):
[package]
name = "rusttest"
version = "0.1.0"
edition = "2018"
[target.'cfg(windows)'.dependencies]
bitflags = ""
[target.'cfg(not(windows))'.build-dependencies]
bitflags = ""
Is this intended behavior? This seems really weird and not at all what I expected. The first example shows that target.'cfg(windows)'.dependencies
is not included in builds on linux. The second example shows that target.'cfg(not(windows))'.build-dependencies
(which is enabled on linux) does not "leak" into the main program. So why, when combined together, does the build succeed?
Output of cargo version
: cargo 1.50.0 (f04e7fab7 2021-02-04)
Also reproduces on cargo +nightly version
: cargo 1.52.0-nightly (572e20153 2021-02-24)
Discovered while trying to investigate the issues hit in EmbarkStudios/rust-gpu#423
Activity
khyperia commentedon Mar 1, 2021
@eddyb suggested adding
resolver = "2"
to the Cargo.toml:and uh,
Backtrace, click to expand
eddyb commentedon Mar 11, 2021
@ehuss @alexcrichton
resolver = "2"
is in beta, right? Seems like this might be important to prioritize for an investigation/fix before it gets into stable - but I can't any labels myself to nominate it or anything.ehuss commentedon Mar 11, 2021
This was an unintended regression introduced by #8777 (first released in 1.49). I can try to take a look.
Auto merge of #9255 - ehuss:fix-deps-filtering, r=Eh2406
Auto merge of rust-lang#9255 - ehuss:fix-deps-filtering, r=Eh2406