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

building workspaces can't use --features flag #5015

Closed
SamPeng87 opened this issue Feb 6, 2018 · 22 comments · Fixed by #8074
Closed

building workspaces can't use --features flag #5015

SamPeng87 opened this issue Feb 6, 2018 · 22 comments · Fixed by #8074
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. A-features Area: features — conditional compilation A-workspaces Area: workspaces C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@SamPeng87
Copy link

SamPeng87 commented Feb 6, 2018

i define feature in some sub-create

    [features]
    default=["product","dangerous_configuration"]
    dangerous_configuration=[]
    develop=[]
    product=[]

then,execute cargo cargo build --features="develop"

it can't work,only work in sub-create default features selectors.

cargo build --no-default-features --all not work too

Is it a Bug?

@alexcrichton
Copy link
Member

Yes right now [features] is only allowed on individual crates rather than workspace configurations.

@alexcrichton alexcrichton added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Feb 6, 2018
@SamPeng87
Copy link
Author

Thank your report.Wish this feature can quick complete. I use two [[bin]] point some other needed feature.it is too low.but thank god this can good work.

@SamPeng87
Copy link
Author

En..Can I push feature arguments with 'cargo build' pass to sub-creat?like my example. I think that looks very natural

@SamPeng87 SamPeng87 reopened this Feb 6, 2018
@alexcrichton
Copy link
Member

You should be able to do --features foo/bar I think?

@sanmai-NL
Copy link

@SamPeng87: could you please test alexcrichton’s suggestion, so that the issue can perhaps be closed?

@Nemo157
Copy link
Member

Nemo157 commented Mar 5, 2018

Attempting to reference a feature in a member of a virtual manifest/workspace does not work (testing with cargo 0.26.0-nightly (1d6dfea44 2018-01-26) and almost rust-lang/futures-rs@2666a72):

.../futures-rs > cargo build --features futures-core/std -p futures-core -v
error: Package `futures-core v0.2.0 (file:///.../futures-rs/futures-core)` does not have these features: `futures-core`

.../futures-rs > cd futures-core

.../futures-rs/futures-core > cargo build --features futures-core/std -p futures-core -v
error: Package `futures-core v0.2.0 (file:///.../futures-rs/futures-core)` does not have these features: `futures-core`

.../futures-rs/futures-core > cargo build --features std -p futures-core -v
   Compiling futures-core v0.2.0 (file:///.../futures-rs/futures-core)
     Running `rustc --crate-name futures_core futures-core/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=314425e352544566 -C extra-filename=-314425e352544566 --out-dir .../futures-rs/target/debug/deps -C incremental=.../futures-rs/target/debug/incremental -L dependency=.../futures-rs/target/debug/deps`
    Finished dev [unoptimized + debuginfo] target(s) in 0.85 secs

Also, --no-default-features does not work in a workspace (note the --cfg 'feature="default"' in the rustc line):

.../futures-rs > cargo build --no-default-features -p futures-core -v
   Compiling futures-core v0.2.0 (file:///.../futures-rs/futures-core)
     Running `rustc --crate-name futures_core futures-core/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=314425e352544566 -C extra-filename=-314425e352544566 --out-dir .../futures-rs/target/debug/deps -C incremental=.../futures-rs/target/debug/incremental -L dependency=.../futures-rs/target/debug/deps`
    Finished dev [unoptimized + debuginfo] target(s) in 0.41 secs

I'm not sure whether there's a good behaviour for these to all have, but if they're not going to apply when building from a virtual manifest then maybe they should warn/error to inform the user?

@Nemo157
Copy link
Member

Nemo157 commented Apr 16, 2018

See also #5364, that appears to cover most of the relevant behaviour and should hopefully close this.

@ehuss ehuss added the A-features Area: features — conditional compilation label Oct 20, 2018
@jhpratt
Copy link
Member

jhpratt commented Apr 16, 2019

@alexcrichton Passing a feature flag works for crates in a workspace, but how can one disable a default feature flag?

@alexcrichton
Copy link
Member

There is no way to selectively disable on default feature, rather you need to turn them all off with --no-default-features (or default-features = false) and then re-enable the other default features you still need manually

@jhpratt
Copy link
Member

jhpratt commented Apr 16, 2019

It is possible to use the --no-default-featurees flag when building a workspace though? When I tried yesterday it didn't seem to work.

@alexcrichton
Copy link
Member

Ah no, not currently, it has to be directed at a package not a workspace

@Manishearth
Copy link
Member

You should be able to do --features foo/bar I think?

@alexcrichton this isn't working for me in https://github.com/servo/webxr/ (try --features webxr/ipc, it compiles but doesn't pull in ipc_channel)

This bug is particularly annoying because this forces me to build from a subfolder, but cargo sets the error message root as the workspace root, so i can't click on the errors to have them open in my editor

@Manishearth
Copy link
Member

Ah, you can use --manifest-path to make it work (but you don't need to foo/bar it then)

@jonhoo
Copy link
Contributor

jonhoo commented Jul 28, 2019

I think having --features foo/bar work would still be better though. It would allow you to do things like "run all tests across all subcrates, and keep this feature enabled" without having to explicitly enumerate every crate (handy for things like general-purpose CI scripts).

@nox
Copy link
Contributor

nox commented Aug 17, 2019

Is there any ongoing work for --features foo/bar? Or guidelines as to where to look at in the code to implement such a thing?

geigerzaehler pushed a commit to oscoin/oscoin-parity-wasm-prototype that referenced this issue Aug 28, 2019
Before this change the ledger code was compiled _without_ `no_std` to
the Wasm target. This did not cause problems yet since we did not use
any `std` code. However, in the future we would have run into issues if
we inadvertently used `std` code.

The reason why `no_std` was not enabled was that the
`--no-default-features` flag was not respected in
`tool/build-ledger-wasm` because of
rust-lang/cargo#5015.
azasypkin added a commit to azasypkin/kroneum that referenced this issue Nov 26, 2019
ilammy added a commit to ilammy/themis that referenced this issue Dec 23, 2019
No idea what changed here, but for some reason Cargo does not allow to
use "--features" with virtual crates now. However, it has no issues with
it once we're in "themis" crate subdirectory and ask to document all
crates in the workspace anyway.

Apparently, "--features" was not supposed to work with workspaces in the
first place [1], but I have no clue it worked before.

[1]: rust-lang/cargo#5015
ilammy added a commit to cossacklabs/themis that referenced this issue Dec 23, 2019
* Fix clippy::needless-doctest-main

Recently released Clippy 1.40 ships with this lint enabled by default.
Since we run with "warnings as errors" policy, this lint causes build
failures which is not nice.

    error: needless `fn main` in doctest
      --> src/wrappers/themis/rust/libthemis-src/src/lib.rs:37:4
       |
    37 | //! fn main() {
       |    ^^^^^^^^^^^^
       |
       = note: `-D clippy::needless-doctest-main` implied by `-D warnings`
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_doctest_main

    error: aborting due to previous error

I wouldn't say that explicit main() here is needless and some people
share the same sentiment [1]. However, since this is top-level module
docs, we cannot disable this lint for this place specifically without
turning it off in the entire module. Okay, Clippy, you win.

[1]: rust-lang/rust-clippy#4858

* Fix Cargo with "--features"

No idea what changed here, but for some reason Cargo does not allow to
use "--features" with virtual crates now. However, it has no issues with
it once we're in "themis" crate subdirectory and ask to document all
crates in the workspace anyway.

Apparently, "--features" was not supposed to work with workspaces in the
first place [1], but I have no clue it worked before.

[1]: rust-lang/cargo#5015
@nixpulvis
Copy link

nixpulvis commented Mar 12, 2020

I'm sure there's a few reasons why this doesn't work, but a naive attempt to use --no-default-features in a workspace lead me here.

I feel like I'd expect a workspace to have effectively the union of the features of it's members. Members could even have the same features and they would be controlled as one. For example, in a workspace with:

[workspace]
members = [
    "foo",
    "bar",
]

I may have the following two manifests:

# foo/Cargo.toml
[features]
default = ["a", "c"]
a = []
b = []
c = []
d = []
# bar/Cargo.toml
[features]
default = ["a", "e"]
a = []
b = []
e = []
f = []

Here I think I'd expect the following:

  • cargo ... --no-default-features would disable all of foo/a, foo/c, bar/a and bar/e
  • cargo ... --features=b would enable both foo/b and bar/b
  • cargo ... --features=f would enable only bar/f

What am I missing? This seems somewhat straightforward. Could I take a stab at implementing this in cargo?

@recmo
Copy link

recmo commented Mar 18, 2020

I'm stuck on this one now too.

Due to a different but related shortcoming I have bench and test features for all packages in the workspace (because dev-dependencies would enable std on some main dependencies, breaking the no-std build). To build it, I would just use cargo test --all-features in the root, because I can not specifically enable the test feature.

But now one of the packages in the workspace has a nightly-only feature, and using --all-features breaks stable.

I'm stuck. Any advice is appreciated.

@gilescope
Copy link
Contributor

Isn't this a dupe of #4753 - can we close this one and continue the discussion there?

@nixpulvis
Copy link

@gilescope I tried collecting all the related (possibly duplicate) issues in https://internals.rust-lang.org/t/features-and-workspaces-request-for-meta-issue/11964 hoping to aggregate them. No responses as of yet however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. A-features Area: features — conditional compilation A-workspaces Area: workspaces C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

Successfully merging a pull request may close this issue.