Skip to content

Commit 89b4dbc

Browse files
committed
Enable --rustfmt-bindings by default
This patch flips --rustfmt-bindings to --no-rustfmt-bindings and enables formatting by default. If rustfmt is not accessible, a warning is printed and the bindings are printed unformatted.
1 parent becdc79 commit 89b4dbc

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/lib.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ impl Builder {
492492
}
493493

494494
if !self.options.rustfmt_bindings {
495-
output_vector.push("--rustfmt-bindings".into());
495+
output_vector.push("--no-rustfmt-bindings".into());
496496
}
497497

498498
if let Some(path) = self.options
@@ -1412,7 +1412,7 @@ impl Default for BindgenOptions {
14121412
enable_mangling: true,
14131413
prepend_enum_name: true,
14141414
time_phases: false,
1415-
rustfmt_bindings: false,
1415+
rustfmt_bindings: true,
14161416
rustfmt_configuration_file: None,
14171417
no_partialeq_types: Default::default(),
14181418
}
@@ -1604,10 +1604,8 @@ impl Bindings {
16041604
let rustfmt = if let Ok(rustfmt) = which::which("rustfmt") {
16051605
rustfmt
16061606
} else {
1607-
return Err(io::Error::new(
1608-
io::ErrorKind::Other,
1609-
"Rustfmt activated, but it could not be found in global path.",
1610-
));
1607+
warn!("Not running rustfmt because it does not exist in PATH");
1608+
return Ok(());
16111609
};
16121610

16131611
let mut cmd = Command::new(rustfmt);

src/options.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,19 @@ where
257257
Useful when debugging bindgen, using C-Reduce, or when \
258258
filing issues. The resulting file will be named \
259259
something like `__bindgen.i` or `__bindgen.ii`."),
260+
Arg::with_name("no-rustfmt-bindings")
261+
.long("no-rustfmt-bindings")
262+
.help("Do not format the generated bindings with rustfmt."),
260263
Arg::with_name("rustfmt-bindings")
261264
.long("rustfmt-bindings")
262-
.help("Format the generated bindings with rustfmt. \
263-
Rustfmt needs to be in the global PATH."),
265+
.help("Format the generated bindings with rustfmt. DEPRECATED: \
266+
--rustfmt-bindings is now enabled by default. Disable \
267+
with --no-rustfmt-bindings."),
264268
Arg::with_name("rustfmt-configuration-file")
265269
.long("rustfmt-configuration-file")
266270
.help("The absolute path to the rustfmt configuration file. \
267271
The configuration file will be used for formatting the bindings. \
268-
Setting this parameter, will automatically set --rustfmt-bindings.")
272+
This parameter is incompatible with --no-rustfmt-bindings.")
269273
.value_name("path")
270274
.takes_value(true)
271275
.multiple(false)
@@ -529,13 +533,21 @@ where
529533
builder.dump_preprocessed_input()?;
530534
}
531535

532-
if matches.is_present("rustfmt-bindings") {
533-
builder = builder.rustfmt_bindings(true);
536+
let no_rustfmt_bindings = matches.is_present("no-rustfmt-bindings");
537+
if no_rustfmt_bindings {
538+
builder = builder.rustfmt_bindings(false);
534539
}
535540

536541
if let Some(path_str) = matches.value_of("rustfmt-configuration-file") {
537542
let path = PathBuf::from(path_str);
538543

544+
if no_rustfmt_bindings {
545+
return Err(Error::new(
546+
ErrorKind::Other,
547+
"Cannot supply both --rustfmt-configuration-file and --no-rustfmt-bindings"
548+
));
549+
}
550+
539551
if !path.is_absolute() {
540552
return Err(Error::new(
541553
ErrorKind::Other,

0 commit comments

Comments
 (0)