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

Feature dependencies #2325

Closed
wants to merge 2 commits into from
Closed

Conversation

JanLikar
Copy link
Contributor

Fix #1570 based on commits from PR #2056 by @tsurai to master.

test_cargo_test::selective_test_optional_dep fails with features cannot be modified when the main package is not being built. Any ideas?

@rust-highfive
Copy link

r? @huonw

(rust_highfive has picked a reviewer for you, use r? to override)

@JanLikar
Copy link
Contributor Author

r? @alexcrichton

@rust-highfive rust-highfive assigned alexcrichton and unassigned huonw Jan 28, 2016
@@ -299,6 +309,7 @@ impl Target {
pub fn crate_name(&self) -> String { self.name.replace("-", "_") }
pub fn src_path(&self) -> &Path { &self.src_path }
pub fn metadata(&self) -> Option<&Metadata> { self.metadata.as_ref() }
pub fn features(&self) -> Option<&Vec<String>> { self.features.as_ref() }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this change to returning Option<&[T]> instead of Option<&Vec<T>>? (generally a little more ergonomic)

@alexcrichton
Copy link
Member

Thanks @JanLikar! Can you also add some tests involving example and test targets with feature dependencies as well?

@alexcrichton
Copy link
Member

I'm also wondering if we want to rename this key in the manifest because features kinda says to me "if you're building this target, enable these features". That's at least the interpretation of the features key in dependencies. This leads me to a few thoughts:

  • Perhaps something that invokes thoughts of "this requires these features to be enabled" or something like that.
  • We may want to make sure that cargo build --bin foo has a good error message. Right now I think the error message says that foo doesn't exist, but it'll just have a feature dependency in this case.
  • Either that, or perhaps we could say cargo build --bin foo activates the features required by foo because it was explicitly requested. I'd probably prefer to not take this route though...

Thoughts?

@JanLikar
Copy link
Contributor Author

  1. Well, I don't think the features key is a particularly bad idea. Something like requires or required-features could also work, but I'm not sure.
  2. I think cargo build --bin foo would be friendlier if it would automatically enable required features, but it would create confusion with beginners, as in "cargo run --bin foo works, but cargo build doesn't produce the foo binary!" Automatic enabling can also be painlessly added in the future...

@alexcrichton
Copy link
Member

Ah and of course cc @rust-lang/tools, surely more opinions!

@brson
Copy link
Contributor

brson commented Feb 2, 2016

No strong opinion but the docs should be updated somewhere.

@alexcrichton
Copy link
Member

It's perhaps most advantageous to take the conservative route for now and have cargo build --bin foo fail if foo requires some features (but providing a nicer error message).

@alexcrichton
Copy link
Member

Ok, had a chance to chat with @wycats about this, and the conclusion was:

  • Let's call this required-features to distinguish from the features key
  • Let's not implicitly enable features for now, but still ensure that the error message is of sufficiently high quality to prevent too much confusion

@mitchmindtree
Copy link

Just came across #1570 which led me here - just thought I'd give this a big +1! Very keen to use this required-features key in conrod.

@JanLikar
Copy link
Contributor Author

@mitchmindtree and others, I didn't find enough time to actually complete this, but I think I will be able to in the next couple of days.

@alexcrichton
Copy link
Member

Closing due to inactivity, but feel free to resubmit with fixes!

@branan
Copy link

branan commented Apr 7, 2016

I ran into wanting this over the weekend, so I've started looking at taking it over and fixing up the comments. I have never touched the cargo source before, so I might give up, but so far the tweaks have been easy enough

@alexcrichton
Copy link
Member

Awesome! Let me know if you need any help @branan!

bors added a commit that referenced this pull request Feb 10, 2017
Added required_features for issue #1570.

Based on PR #2056 by @tsurai and PR #2325 by @JanLikar

I tried to fix most everything that was talked about in the previous pull requests. Docs still need to be updated though.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Release-note worthy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants