Skip to content

Commit 4d1c954

Browse files
author
bors-servo
authored
Auto merge of #1236 - emilio:with-rustfmt, r=fitzgen
lib: Add a way to override rustfmt path. I'll need it to format some stuff on mozilla-central.
2 parents 56bbbb0 + b16e09c commit 4d1c954

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ name = "bindgen"
1313
readme = "README.md"
1414
repository = "https://github.com/rust-lang-nursery/rust-bindgen"
1515
documentation = "https://docs.rs/bindgen"
16-
version = "0.32.2"
16+
version = "0.32.3"
1717
build = "build.rs"
1818

1919
include = [

src/lib.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,12 @@ impl Builder {
10791079
self
10801080
}
10811081

1082+
/// Sets an explicit path to rustfmt, to be used when rustfmt is enabled.
1083+
pub fn with_rustfmt<P: Into<PathBuf>>(mut self, path: P) -> Self {
1084+
self.options.rustfmt_path = Some(path.into());
1085+
self
1086+
}
1087+
10821088
/// Generate the Rust bindings using the options built up thus far.
10831089
pub fn generate(mut self) -> Result<Bindings, ()> {
10841090
self.options.input_header = self.input_headers.pop();
@@ -1216,6 +1222,9 @@ struct BindgenOptions {
12161222
/// generated code.
12171223
opaque_types: RegexSet,
12181224

1225+
/// The explicit rustfmt path.
1226+
rustfmt_path: Option<PathBuf>,
1227+
12191228
/// The set of types that we should have bindings for in the generated
12201229
/// code.
12211230
///
@@ -1441,6 +1450,7 @@ impl Default for BindgenOptions {
14411450
rust_features: rust_target.into(),
14421451
blacklisted_types: Default::default(),
14431452
opaque_types: Default::default(),
1453+
rustfmt_path: Default::default(),
14441454
whitelisted_types: Default::default(),
14451455
whitelisted_functions: Default::default(),
14461456
whitelisted_vars: Default::default(),
@@ -1709,10 +1719,19 @@ impl Bindings {
17091719
return Ok(Cow::Borrowed(source));
17101720
}
17111721

1712-
let rustfmt = which::which("rustfmt")
1713-
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_owned()))?;
1722+
let rustfmt = match self.options.rustfmt_path {
1723+
Some(ref p) => Cow::Borrowed(p),
1724+
None => {
1725+
let path = which::which("rustfmt")
1726+
.map_err(|e| {
1727+
io::Error::new(io::ErrorKind::Other, e.to_owned())
1728+
})?;
1729+
1730+
Cow::Owned(path)
1731+
}
1732+
};
17141733

1715-
let mut cmd = Command::new(rustfmt);
1734+
let mut cmd = Command::new(&*rustfmt);
17161735

17171736
cmd
17181737
.stdin(Stdio::piped())

0 commit comments

Comments
 (0)