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

Specifying features of dependencies on the command line #13199

Closed
dhardy opened this issue Dec 23, 2023 · 4 comments
Closed

Specifying features of dependencies on the command line #13199

dhardy opened this issue Dec 23, 2023 · 4 comments
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@dhardy
Copy link

dhardy commented Dec 23, 2023

From #3058 it sounds like one is not supposed to be able to specify features of dependencies on the command-line, though it's not clear since the example involves transitive features (two slashes).

Attempt to replicate that fails, as expected:

$ git clone https://github.com/kas-gui/kas.git && cd kas
$ cargo check --features kas-widgets/kas-core/winit
error: multiple slashes in feature `kas-widgets/kas-core/winit` is not allowed

However, using a single slash is currently functional:

$ cd crates/kas-widgets
$ cargo test --features kas/winit,kas/wayland
[...]
test result: ok.

Should this be supported?

Aside: in this particular case, this approach feels justifiable since kas-widgets is only ever intended to be used in addition to kas-core (here renamed kas), thus it makes no sense to re-export its features under kas-widgets.

This came up on docs.rs: it would appear that their build process does not support correct dependency retrieval for features enabled in this way.

@dhardy dhardy added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Dec 23, 2023
@ehuss
Copy link
Contributor

ehuss commented Dec 23, 2023

Thanks for the report!

Features of packages in a workspace can be specified with the / syntax. That is documented here, that is the expected behavior.

When building a standalone package (like kas-resvg) outside of the workspace (like what docs.rs does), dependencies like kas-core are no longer workspace members. It is not intended that you can specify features like kas/winit from the command-line if nothing else enables that feature when that is a registry dependency. This is a known bug that it is allowed in some circumstances (#3629).

I would recommend configuring your dependencies (like kas-resvg) to enable the necessary features on kas-core, either in the kas-core dependency declaration, or in the [features] table. That will tell cargo that you need the dependencies that those features enable.

@dhardy
Copy link
Author

dhardy commented Dec 23, 2023

Thanks for the clarification...

... however, docs.rs is building from the workspace, right?

In particular, the feature resolution should never be a problem in any other circumstance I can foresee since it is never intended that kas-widgets be used without also having a direct dependency on kas-core. Of course, docs.rs does not support specification of additional dependencies, thus to me it seems that it should support feature specification of workspace members like this.

@ehuss
Copy link
Contributor

ehuss commented Dec 23, 2023

... however, docs.rs is building from the workspace, right?

I do not think so. I believe it just downloads and extracts the .crate file from crates.io and builds it directly.

@dhardy
Copy link
Author

dhardy commented Dec 23, 2023

Thanks @ehuss; that concludes this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants