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
Changes from 2 commits
f64287d
b97192b
af4eebd
258940a
ebd8d4d
e627649
c22fcf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 } | ||
shlex = "0.1" | ||
fxhash = "0.2" | ||
# New validation in 0.3.6 breaks bindgen-integration: | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. So then you replace |
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. And remove this line. |
||
|
||
# These features only exist for CI testing -- don't use them if you're not hacking | ||
# on bindgen! | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. And |
||
extern crate which; | ||
|
||
#[cfg(feature = "logging")] | ||
|
@@ -1900,18 +1901,21 @@ impl Bindings { | |
} | ||
|
||
/// Gets the rustfmt path to rustfmt the generated bindings. | ||
fn rustfmt_path<'a>(&'a self) -> io::Result<Cow<'a, PathBuf>> { | ||
fn rustfmt_path<'a>(&'a self) -> io::Result<Option<Cow<'a, PathBuf>>> { | ||
debug_assert!(self.options.rustfmt_bindings); | ||
if let Some(ref p) = self.options.rustfmt_path { | ||
return Ok(Cow::Borrowed(p)); | ||
return Ok(Some(Cow::Borrowed(p))); | ||
} | ||
if let Ok(rustfmt) = env::var("RUSTFMT") { | ||
return Ok(Cow::Owned(rustfmt.into())); | ||
return Ok(Some(Cow::Owned(rustfmt.into()))); | ||
} | ||
#[cfg(feature = "which-rustfmt")] | ||
match which::which("rustfmt") { | ||
Ok(p) => Ok(Cow::Owned(p)), | ||
Ok(p) => Ok(Some(Cow::Owned(p))), | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. I'd just return an error here, like The error is not fatal so you'd still generate bindings. |
||
Ok(None) | ||
} | ||
|
||
/// Checks if rustfmt_bindings is set and runs rustfmt on the string | ||
|
@@ -1926,7 +1930,11 @@ impl Bindings { | |
return Ok(Cow::Borrowed(source)); | ||
} | ||
|
||
let rustfmt = self.rustfmt_path()?; | ||
let rustfmt = if let Some(rustfmt) = self.rustfmt_path()? { | ||
rustfmt | ||
} else { | ||
return Ok(Cow::Borrowed(source)); | ||
}; | ||
let mut cmd = Command::new(&*rustfmt); | ||
|
||
cmd | ||
|
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).