diff --git a/CHANGELOG.md b/CHANGELOG.md index a611ea4080..aac313e76a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -184,7 +184,9 @@ them. To make the escaping clear and consistent, backslashes are also escaped. * Updated `bitflags` dependency to 2.2.1. This changes the API of `CodegenConfig`. - +* Prettyplease formatting is gated by an optional, enabled by default Cargo + feature when depending on `bindgen` as a library. + ## Removed ## Fixed diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index fd20049e78..eeaccf84ee 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -35,7 +35,7 @@ quote = { version = "1", default-features = false } syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"]} regex = { version = "1.5", default-features = false , features = ["std", "unicode"] } which = { version = "4.2.1", optional = true, default-features = false } -prettyplease = { version = "0.2.0" } +prettyplease = { version = "0.2.0", optional = true } annotate-snippets = { version = "0.9.1", features = ["color"], optional = true } shlex = "1" rustc-hash = "1.0.1" @@ -43,7 +43,7 @@ proc-macro2 = { version = "1", default-features = false } log = { version = "0.4", optional = true } [features] -default = ["logging", "runtime", "which-rustfmt"] +default = ["logging", "prettyplease", "runtime", "which-rustfmt"] logging = ["log"] static = ["clang-sys/static"] runtime = ["clang-sys/runtime"] diff --git a/bindgen/lib.rs b/bindgen/lib.rs index e4b71b0496..2eb4486dac 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -172,6 +172,7 @@ pub enum Formatter { None, /// Use `rustfmt` to format the bindings. Rustfmt, + #[cfg(feature = "prettyplease")] /// Use `prettyplease` to format the bindings. Prettyplease, } @@ -189,6 +190,7 @@ impl FromStr for Formatter { match s { "none" => Ok(Self::None), "rustfmt" => Ok(Self::Rustfmt), + #[cfg(feature = "prettyplease")] "prettyplease" => Ok(Self::Prettyplease), _ => Err(format!("`{}` is not a valid formatter", s)), } @@ -200,6 +202,7 @@ impl std::fmt::Display for Formatter { let s = match self { Self::None => "none", Self::Rustfmt => "rustfmt", + #[cfg(feature = "prettyplease")] Self::Prettyplease => "prettyplease", }; @@ -964,6 +967,7 @@ impl Bindings { match self.options.formatter { Formatter::None => return Ok(tokens.to_string()), + #[cfg(feature = "prettyplease")] Formatter::Prettyplease => { return Ok(prettyplease::unparse(&syn::parse_quote!(#tokens))); }