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

Tracking issue for -Z features=dev_dep #7916

Closed
4 tasks
ehuss opened this issue Feb 21, 2020 · 5 comments · Fixed by #8997
Closed
4 tasks

Tracking issue for -Z features=dev_dep #7916

ehuss opened this issue Feb 21, 2020 · 5 comments · Fixed by #8997
Labels
A-features2 Area: issues specifically related to the v2 feature resolver C-tracking-issue Category: A tracking issue for something unstable.

Comments

@ehuss
Copy link
Contributor

ehuss commented Feb 21, 2020

Implementation: #7820
Documentation: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#features

Summary
-Z features=dev_dep causes the feature resolver to prevent features enabled on dev dependencies from being enabled for normal dependencies. For example:

[dependencies]
serde = {version = "1.0", default-features = false}

[dev-dependencies]
serde = {version = "1.0", features = ["std"]}

In this example, the library will normally link against serde without the std feature. However, when built as a test or example, it will include the std feature.

This mode is ignored if you are building any test, bench, or example. That is, dev dependency features will still be unified if you run commands like cargo test or cargo build --all-targets.

Unresolved issues

  • Update cargo metadata
  • Does this cause existing projects to fail?
    • Projects can add missing features as a backwards-compatible workaround. However, if it causes problems for too many projects, we may need to find some way to opt-in.
  • Does this significantly increase build times?
    • This can cause cargo test to rebuild some dependencies after a cargo build, where previously those dependencies were built once. Projects can add features to re-unify if they want, but it may not be clear or obvious what to add and when. We may need something that identifies these duplicate dependencies, and give suggestions on how to unify them. Or, we may need to make this opt-in somehow so the user needs to make this an explicit decision.
  • Is it OK that this is a global mode?
    • For example, when running cargo test, binaries will use dependencies with the dev-dependency features. Changing this would be very difficult, requiring major changes to how Cargo builds its unit graph. It may also cause longer build times when it is not necessary, since common dependencies with different features would need to be built twice during cargo test.
@ehuss ehuss added C-tracking-issue Category: A tracking issue for something unstable. A-features2 Area: issues specifically related to the v2 feature resolver labels Feb 21, 2020
sunshowers added a commit to sunshowers/cargo-guppy that referenced this issue Mar 28, 2020
This is a complete overhaul of the way platform-specific dependencies are
handled. Based on my experimentation and reading the Cargo source code, I
believe that this is now correct.

Doing so also required feature graph construction to be updated, so the
feature graph construction is ready for the new feature resolver, and is now
platform-sensitive as well. The APIs for the feature graph are still to
come, but making the data model be full-fidelity allows for both the current
and new feature resolvers to be implemented.

For more about the new feature resolver, see:

* https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#features
* rust-lang/cargo#7914
* rust-lang/cargo#7915
* rust-lang/cargo#7916
sunshowers added a commit to sunshowers/cargo-guppy that referenced this issue Mar 28, 2020
This is a complete overhaul of the way platform-specific dependencies are
handled. Based on my experimentation and reading the Cargo source code, I
believe that this is now correct.

Doing so also required feature graph construction to be updated, so the
feature graph construction is ready for the new feature resolver, and is now
platform-sensitive as well. The APIs for the feature graph are still to
come, but making the data model be full-fidelity allows for both the current
and new feature resolvers to be implemented.

For more about the new feature resolver, see:

* https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#features
* rust-lang/cargo#7914
* rust-lang/cargo#7915
* rust-lang/cargo#7916
sunshowers added a commit to sunshowers/cargo-guppy that referenced this issue Mar 28, 2020
This is a complete overhaul of the way platform-specific dependencies are
handled. Based on my experimentation and reading the Cargo source code, I
believe that this is now correct.

Doing so also required feature graph construction to be updated, so the
feature graph construction is ready for the new feature resolver, and is now
platform-sensitive as well. The APIs for the feature graph are still to
come, but making the data model be full-fidelity allows for both the current
and new feature resolvers to be implemented.

Now that target logic is internalized in guppy, cargo-guppy no longer needs
to do its own evaluation.

For more about the new feature resolver, see:

* https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#features
* rust-lang/cargo#7914
* rust-lang/cargo#7915
* rust-lang/cargo#7916
sunshowers added a commit to sunshowers/cargo-guppy that referenced this issue Mar 28, 2020
This is a complete overhaul of the way platform-specific dependencies are
handled. Based on my experimentation and reading the Cargo source code, I
believe that this is now correct.

Doing so also required feature graph construction to be updated, so the
feature graph construction is ready for the new feature resolver, and is now
platform-sensitive as well. The APIs for the feature graph are still to
come, but making the data model be full-fidelity allows for both the current
and new feature resolvers to be implemented.

Now that target logic is internalized in guppy, cargo-guppy no longer needs
to do its own evaluation.

For more about the new feature resolver, see:

* https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#features
* rust-lang/cargo#7914
* rust-lang/cargo#7915
* rust-lang/cargo#7916
sunshowers added a commit to sunshowers/cargo-guppy that referenced this issue Mar 28, 2020
This is a complete overhaul of the way platform-specific dependencies are
handled. Based on my experimentation and reading the Cargo source code, I
believe that this is now correct.

Doing so also required feature graph construction to be updated, so the
feature graph construction is ready for the new feature resolver, and is now
platform-sensitive as well. The APIs for the feature graph are still to
come, but making the data model be full-fidelity allows for both the current
and new feature resolvers to be implemented.

Now that target logic is internalized in guppy, cargo-guppy no longer needs
to do its own evaluation.

For more about the new feature resolver, see:

* https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#features
* rust-lang/cargo#7914
* rust-lang/cargo#7915
* rust-lang/cargo#7916
sunshowers added a commit to sunshowers/cargo-guppy that referenced this issue Mar 28, 2020
This is a complete overhaul of the way platform-specific dependencies are
handled. Based on my experimentation and reading the Cargo source code, I
believe that this is now correct.

Doing so also required feature graph construction to be updated, so the
feature graph construction is ready for the new feature resolver, and is now
platform-sensitive as well. The APIs for the feature graph are still to
come, but making the data model be full-fidelity allows for both the current
and new feature resolvers to be implemented.

Now that target logic is internalized in guppy, cargo-guppy no longer needs
to do its own evaluation.

For more about the new feature resolver, see:

* https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#features
* rust-lang/cargo#7914
* rust-lang/cargo#7915
* rust-lang/cargo#7916
sunshowers added a commit to sunshowers/cargo-guppy that referenced this issue Mar 30, 2020
This is a complete overhaul of the way platform-specific dependencies are
handled. Based on my experimentation and reading the Cargo source code, I
believe that this is now correct.

Doing so also required feature graph construction to be updated, so the
feature graph construction is ready for the new feature resolver, and is now
platform-sensitive as well. The APIs for the feature graph are still to
come, but making the data model be full-fidelity allows for both the current
and new feature resolvers to be implemented.

Now that target logic is internalized in guppy, cargo-guppy no longer needs
to do its own evaluation.

For more about the new feature resolver, see:

* https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#features
* rust-lang/cargo#7914
* rust-lang/cargo#7915
* rust-lang/cargo#7916
sunshowers added a commit to sunshowers/cargo-guppy that referenced this issue Apr 1, 2020
This is a complete overhaul of the way platform-specific dependencies are
handled. Based on my experimentation and reading the Cargo source code, I
believe that this is now correct.

Doing so also required feature graph construction to be updated, so the
feature graph construction is ready for the new feature resolver, and is now
platform-sensitive as well. The APIs for the feature graph are still to
come, but making the data model be full-fidelity allows for both the current
and new feature resolvers to be implemented.

Now that target logic is internalized in guppy, cargo-guppy no longer needs
to do its own evaluation.

For more about the new feature resolver, see:

* https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#features
* rust-lang/cargo#7914
* rust-lang/cargo#7915
* rust-lang/cargo#7916
sunshowers added a commit to sunshowers/cargo-guppy that referenced this issue Apr 1, 2020
This is a complete overhaul of the way platform-specific dependencies are
handled. Based on my experimentation and reading the Cargo source code, I
believe that this is now correct.

Doing so also required feature graph construction to be updated, so the
feature graph construction is ready for the new feature resolver, and is now
platform-sensitive as well. The APIs for the feature graph are still to
come, but making the data model be full-fidelity allows for both the current
and new feature resolvers to be implemented.

Now that target logic is internalized in guppy, cargo-guppy no longer needs
to do its own evaluation.

For more about the new feature resolver, see:

* https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#features
* rust-lang/cargo#7914
* rust-lang/cargo#7915
* rust-lang/cargo#7916
sunshowers added a commit to facebookarchive/cargo-guppy that referenced this issue Apr 1, 2020
This is a complete overhaul of the way platform-specific dependencies are
handled. Based on my experimentation and reading the Cargo source code, I
believe that this is now correct.

Doing so also required feature graph construction to be updated, so the
feature graph construction is ready for the new feature resolver, and is now
platform-sensitive as well. The APIs for the feature graph are still to
come, but making the data model be full-fidelity allows for both the current
and new feature resolvers to be implemented.

Now that target logic is internalized in guppy, cargo-guppy no longer needs
to do its own evaluation.

For more about the new feature resolver, see:

* https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#features
* rust-lang/cargo#7914
* rust-lang/cargo#7915
* rust-lang/cargo#7916
@kvinwang
Copy link

kvinwang commented Apr 2, 2020

Seems not working with build-dependencies?
Create a new empty crate with Cargo.toml:

[package]
name = "foo"
version = "0.1.0"
authors = ["Kevin Wang"]
edition = "2018"

[dependencies]
log = {version = "0.4", default-features = false}

[build-dependencies]
bindgen = "0.49"

Build it with:

cargo +nightly build -Z features=dev_dep -Z build-std=core,alloc --target=x86_64-linux-kernel

Output:

error[E0463]: can't find crate for `std`
  |
  = note: the `x86_64-linux-kernel` 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 `log`.

Cargo version:

cargo 1.44.0-nightly (7019b3ed3 2020-03-17)

@ehuss
Copy link
Contributor Author

ehuss commented Apr 2, 2020

@kvinwang there is a separate option for build dependencies (-Zfeatures=host_dep). Its tracking issue is #7915. dev_dep only affects dev-dependencies. See the link to the docs for more information.

@kvinwang
Copy link

kvinwang commented Apr 2, 2020

there is a separate option for build dependencies

Ohh,-Zfeatures=build_dep works. Thanks very much!

@nrxus
Copy link

nrxus commented Apr 17, 2020

Would feature flags in dev-dependencys propagate as feature flags in regular dependencies do today or would they only affect the current crate since dev dependencies themselves do no propagate.

i.e.,

# crate-a:
[dev-dependencies]
crate-b = "1.1.0"
crate-c = { version = "0.1.0", features = ["foo"] }
# crate-b:
[dev-dependencies]
crate-c = { version = "0.1.0", features = ["bar"] }

Will crate-a be using features foo and bar when doing a cargo test (similarly to how it happens with normal dependencies), or only the foo feature since dev dependencies features do not propagate?

For what is worth I expect the latter since dev dependencies do not propagate so the features shouldn't either.

@ehuss
Copy link
Contributor Author

ehuss commented Apr 17, 2020

dev-dependencies inside other dependencies are ignored the same as they are today.

zheland added a commit to zheland/typed-index-collections that referenced this issue Aug 6, 2020
Dev-dependency version-sync crate uses `serde/std` feature.
`cargo build` on CI build library with features from dev-deps.
Use `-Z features=dev_dep` on nightly to check build without `serde/std`.

See rust-lang/cargo#7916 for more details.
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this issue Sep 4, 2020
Updates to use the `group` crate. See: RustCrypto/traits#287.

This crate has a hard `rand_core` dependency so this commit gets rid of
the `rand` features across the board and makes them mandatory.

(Even if we don't end up shipping the `group` crate this release, that's
probably for the best to keep the number of features down)

This commit additionally splits out `no_std` build testing into
`tests/*_no_std` Cargo projects. This is a workaround until the Cargo
resolver is fixed upstream:

rust-lang/cargo#7915
rust-lang/cargo#7916
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this issue Sep 4, 2020
Updates to use the `group` crate. See: RustCrypto/traits#287.

This crate has a hard `rand_core` dependency so this commit gets rid of
the `rand` features across the board and makes them mandatory.

(Even if we don't end up shipping the `group` crate this release, that's
probably for the best to keep the number of features down)

This commit additionally splits out `no_std` build testing into
`tests/*_no_std` Cargo projects. This is a workaround until the Cargo
resolver is fixed upstream:

rust-lang/cargo#7915
rust-lang/cargo#7916
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this issue Sep 4, 2020
Updates to use the `group` crate. See: RustCrypto/traits#287.

This crate has a hard `rand_core` dependency so this commit gets rid of
the `rand` features across the board and makes them mandatory.

(Even if we don't end up shipping the `group` crate this release, that's
probably for the best to keep the number of features down)

This commit additionally splits out `no_std` build testing into
`tests/*_no_std` Cargo projects. This is a workaround until the Cargo
resolver is fixed upstream:

rust-lang/cargo#7915
rust-lang/cargo#7916
jonasbb added a commit to jonasbb/serde_with that referenced this issue Oct 7, 2020
This feature is explicitly enabled via the ron dev dependency. This is
cargo bug rust-lang/cargo#7916

This was reported on URLO
https://users.rust-lang.org/t/serde-hashmap-serialization-key-error/49776/5
@frewsxcv frewsxcv mentioned this issue Jan 1, 2021
2 tasks
@bors bors closed this as completed in 4aa5223 Jan 5, 2021
@bors bors closed this as completed in #8997 Jan 5, 2021
Fuuzetsu added a commit to Fuuzetsu/zstd-seekable-s3 that referenced this issue Jan 29, 2021
If we don't do this, package becomes unusable as dependency

rust-lang/cargo#1796
rust-lang/cargo#7916
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-features2 Area: issues specifically related to the v2 feature resolver C-tracking-issue Category: A tracking issue for something unstable.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants