@@ -1079,6 +1079,12 @@ impl Builder {
1079
1079
self
1080
1080
}
1081
1081
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
+
1082
1088
/// Generate the Rust bindings using the options built up thus far.
1083
1089
pub fn generate ( mut self ) -> Result < Bindings , ( ) > {
1084
1090
self . options . input_header = self . input_headers . pop ( ) ;
@@ -1216,6 +1222,9 @@ struct BindgenOptions {
1216
1222
/// generated code.
1217
1223
opaque_types : RegexSet ,
1218
1224
1225
+ /// The explicit rustfmt path.
1226
+ rustfmt_path : Option < PathBuf > ,
1227
+
1219
1228
/// The set of types that we should have bindings for in the generated
1220
1229
/// code.
1221
1230
///
@@ -1441,6 +1450,7 @@ impl Default for BindgenOptions {
1441
1450
rust_features : rust_target. into ( ) ,
1442
1451
blacklisted_types : Default :: default ( ) ,
1443
1452
opaque_types : Default :: default ( ) ,
1453
+ rustfmt_path : Default :: default ( ) ,
1444
1454
whitelisted_types : Default :: default ( ) ,
1445
1455
whitelisted_functions : Default :: default ( ) ,
1446
1456
whitelisted_vars : Default :: default ( ) ,
@@ -1709,10 +1719,19 @@ impl Bindings {
1709
1719
return Ok ( Cow :: Borrowed ( source) ) ;
1710
1720
}
1711
1721
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
+ } ;
1714
1733
1715
- let mut cmd = Command :: new ( rustfmt) ;
1734
+ let mut cmd = Command :: new ( & * rustfmt) ;
1716
1735
1717
1736
cmd
1718
1737
. stdin ( Stdio :: piped ( ) )
0 commit comments