Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbz00 committed Mar 30, 2024
1 parent d23f2c5 commit 8fdf9f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions prost-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ tempfile = "3"
once_cell = "1.17.1"
regex = { version = "1.8.1", default-features = false, features = ["std", "unicode-bool"] }

# feature: format
prettyplease = { version = "0.2", optional = true }
syn = { version = "2", features = ["full"], optional = true }

Expand Down
10 changes: 4 additions & 6 deletions prost-build/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub struct Config {
pub(crate) skip_protoc_run: bool,
pub(crate) include_file: Option<PathBuf>,
pub(crate) prost_path: Option<String>,
#[cfg(feature = "format")]
pub(crate) fmt: bool,
}

Expand Down Expand Up @@ -736,9 +737,7 @@ impl Config {
}

/// Configures the code generator to format the output code via `prettyplease`.
///
/// By default, this is enabled but if the `format` feature is not enabled this does
/// nothing.
#[cfg(feature = "format")]
pub fn format(&mut self, enabled: bool) -> &mut Self {
self.fmt = enabled;
self
Expand Down Expand Up @@ -1056,6 +1055,7 @@ impl Config {
}
}

#[cfg(feature = "format")]
if self.fmt {
self.fmt_modules(&mut modules);
}
Expand All @@ -1080,9 +1080,6 @@ impl Config {
*buf = formatted;
}
}

#[cfg(not(feature = "format"))]
fn fmt_modules(&mut self, _: &mut HashMap<Module, String>) {}
}

impl default::Default for Config {
Expand Down Expand Up @@ -1110,6 +1107,7 @@ impl default::Default for Config {
skip_protoc_run: false,
include_file: None,
prost_path: None,
#[cfg(feature = "format")]
fmt: true,
}
}
Expand Down

0 comments on commit 8fdf9f6

Please sign in to comment.