Skip to content

New behavior of --feature + --package combination #5364

@matklad

Description

@matklad
Member

Docs: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#package-features

A tracking issue for #5353 and #5351. Historically, --feature and related flags applied to the current package, and not to the package, specified via --package. This is a bug, but fixing it could break someone's code, so currently new behavior exists under -Z package-features opt-in. We need to check if it breaks code in the wild to see what we should do next.

Activity

matklad

matklad commented on Apr 16, 2018

@matklad
MemberAuthor

#5362 is I think the manifestation of the old odd behavior.

matklad

matklad commented on Apr 16, 2018

@matklad
MemberAuthor

I think #4942 is also this issue.

matklad

matklad commented on Apr 16, 2018

@matklad
MemberAuthor

And #4753 as well

dwijnand

dwijnand commented on Apr 16, 2018

@dwijnand
changed the title [-]New behavior of `--feature` + `--pacakge` combination[/-] [+]New behavior of `--feature` + `--package` combination[/+] on Apr 16, 2018
matklad

matklad commented on Apr 28, 2018

@matklad
MemberAuthor

This broke Servo unfortunately, so we probably would need to back this out, at least in this, maximally aggressive, form.

However, I wonder what we plan to do with feature-selection problems in general?

I assume that we want to eventually fix the main problem with features. Currently, features are global per compilation, and that means that features bleed from dev-deps to normal deps and that cargo build -p foo and cargo build -p foo -p bar build the foo package differently.

Fixing that, however, would be a breaking change: suddenly, Cargo would select a smaller set of features :-(

But, if we do fix that, then behavior of the combination of --package and --features would necessary change as well. In other words, this PR is sort of a subset of that larger issue.

The core question I think is do we feel comfortable with eventually changing the set of activated features? If we are, then I think we can modify current fix to not flatly error-out, but to ignore the features argument for several packages, printing a warning like "this was accepted in previous versions of Cargo and activated features in surprising way, and not it is ignored".

pravic

pravic commented on Apr 28, 2018

@pravic

$ cargo +stable test --all --features xyz

Used to work. And expectation was "Enable the specified set of futures for crates that support it".

$ cargo +nightly test --all --features xyz
error: cannot specify features for more than one package

Now we see this (thanks to CI to catch it soon and not after Rust release) and it does not matter whether all of workspace members have xyz or not, error is the same.

How come that the original issue (cargo --package foo --feature feat) has affected builds without --package? #5390 wasn't a good idea without a compatibility explanation (what is it? how to fix that mystical error? how it will work in future?). That error must have contained at least the issue number (since it is a breaking future and it is in nightly (i.e. unstable) anyway).

matklad

matklad commented on Apr 28, 2018

@matklad
MemberAuthor

And expectation was "Enable the specified set of futures for crates that support it".

Not that this expectation is wrong. What actually happens is that the feature is enabled only for the package in the current working directory. In other words, it is irrelevant whether all members have the xyz feature, because this applies only to a single member, and not the one that is specified via the -p argument.

That error must have contained at least the issue number

That was definitely an oversight on my part :(

matklad

matklad commented on Apr 28, 2018

@matklad
MemberAuthor

Here's a small example which demonstrates the difference in behavior: https://github.com/matklad/features-behavior

matklad

matklad commented on Apr 28, 2018

@matklad
MemberAuthor

has affected builds without --package?

--all is a shorthand for --package member1 --package member2 --package member3 etc, and suffers the same problem: --feature flag does not apply to the selected packages. I've extended the example at https://github.com/matklad/features-behavior to show how this affects --all.

70 remaining items

added a commit that references this issue on Jan 5, 2021
4aa5223
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-featuresArea: features — conditional compilationC-tracking-issueCategory: A tracking issue for something unstable.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @ehuss@alexcrichton@Nemo157@dhardy@jonhoo

      Issue actions

        New behavior of `--feature` + `--package` combination · Issue #5364 · rust-lang/cargo