Skip to content
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

Restore prettyplease feature gate to bindgen library crate #2537

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ 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"
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"]
Expand Down
4 changes: 4 additions & 0 deletions bindgen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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)),
}
Expand All @@ -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",
};

Expand Down Expand Up @@ -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)));
}
Expand Down
Loading