-
Notifications
You must be signed in to change notification settings - Fork 707
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
Add a feature to make which dependency optional #1615
Conversation
This feature controls whether bindgen will use the which crate to detect the rustfmt binary. This makes which an optional dependency. which-rustfmt is a default feature which makes this change backward compatible.
This commit changes the API of rustfmt_path to return Result<Option<Cow<PathBuf>>>. Ok(None) is returned in the case where which is disabled and no rustfmt command is supplied explicitly either via configuration or env variable. Downstream code checks for the presence of None to directly return the source without emitting an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks pretty good :)
I think it could be simpler, and it'd be great to tweak .travis.yml
to also at least build with this configuration.
Thank you!
@@ -54,7 +54,7 @@ lazy_static = "1" | |||
peeking_take_while = "0.1.2" | |||
quote = { version = "1", default-features = false } | |||
regex = "1.0" | |||
which = ">=1.0, <3.0" | |||
which = { version = ">=1.0, <3.0", optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about just leaving this change, then the feature will be automatically called which
(you get a feature for each optional dependency).
@@ -70,9 +70,11 @@ optional = true | |||
version = "0.4" | |||
|
|||
[features] | |||
default = ["logging", "clap"] | |||
default = ["logging", "clap", "which-rustfmt"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So then you replace which-rustfmt
by which
here...
logging = ["env_logger", "log"] | ||
static = [] | ||
# Dynamically discover a `rustfmt` binary using the `which` crate | ||
which-rustfmt = ["which"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And remove this line.
@@ -32,6 +32,7 @@ extern crate quote; | |||
extern crate proc_macro2; | |||
extern crate regex; | |||
extern crate shlex; | |||
#[cfg(feature = "which-rustfmt")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And s/which-rustfmt/which
here.
Err(e) => Err(io::Error::new(io::ErrorKind::Other, format!("{}", e))), | ||
} | ||
#[cfg(not(feature = "which-rustfmt"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just return an error here, like Err(io::Error::new(io::ErrorKind::Other, "which wasn't enabled, and no rustfmt binary specified")))
, then the patch becomes much simpler, wdyt?
The error is not fatal so you'd still generate bindings.
Hi @emilio I'm a bit confused. This PR is approved but you've left feedback. Who is responsible for pushing this forward? Your feedback on the name of the feature seems to ignore my justification for my decision from the PR description and the recommendation from the cargo docs. I'm happy to make this change but the
I found the codebase more difficult to contribute to than it should be because my reasonable editor configuration makes massive diffs when formatting on save. I've filed GH-1618 to address this. |
I expected you to address the comments before I merge it, though if you don't have the cycles I'm happy to fix it.
That's fair, sorry about it. I'd be happy to do that, but probably worth waiting until this is merged so you don't have to rebase conflicts. |
Ah, sorry, had missed this... Let's add build this on |
@emilio (pending Travis passing) I think this is ready to be looked at again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
Thanks for merging @emilio 😄 |
This PR adds a new feature, enabled by default, called
which-rustfmt
. When enabled, this feature enables using thewhich
crate to search for therustfmt
binary.which
is now an optional dependency. Disabling this feature trims some dependencies in the case that bindings are generated at build time and never checked in.This PR changes the API of
rustfmt_path
to returnResult<Option<Cow<PathBuf>>>
.Ok(None) is returned in the case where
which
is disabled and norustfmt
command issupplied explicitly either via configuration or env variable.
Downstream code checks for the presence of None to directly return the source without
emitting an error.
Fixes GH-1614.
I named the feature
which-rustfmt
instead ofwhich
because the feature is tied to the functionality, not the crate. If this functionality for some reason requires additional dependencies in the future, they can be added to this feature and excluded in a backwards compatible way. This is also the suggested way to name features by the cargo documentation.@emilio I have
rustfmt
enabled by default on save in my editor and there was quite a lot of diff to ignore to make this PR minimal. Can we eitherrustfmt
bindgen and add a step to CI to enforce code is formatted or add arustfmt.toml
so the formatting is preserved?