From 86c42787ef76126025e9b1b40d9f82abf7e1e369 Mon Sep 17 00:00:00 2001 From: Konstantin G Date: Fri, 27 Dec 2024 13:49:29 +0000 Subject: [PATCH 1/4] Add a config option to avoid passing include_source_info --- prost-build/src/config.rs | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/prost-build/src/config.rs b/prost-build/src/config.rs index 896726b16..7927e6b6e 100644 --- a/prost-build/src/config.rs +++ b/prost-build/src/config.rs @@ -48,6 +48,7 @@ pub struct Config { pub(crate) disable_comments: PathMap<()>, pub(crate) skip_debug: PathMap<()>, pub(crate) skip_protoc_run: bool, + pub(crate) skip_source_info: bool, pub(crate) include_file: Option, pub(crate) prost_path: Option, #[cfg(feature = "format")] @@ -597,6 +598,26 @@ impl Config { self } + /// This can be used to avoid passing ``--include_source_info`` argument when the `protoc` + /// command is invoked to generate the `FileDescriptorSet`. The ``--include_source_info`` + /// flag is passed by default, however it results in vastly larger descriptors that + /// include information about the original location of each decl in the source file as + /// well as surrounding comments. + /// + /// In `build.rs`: + /// + /// ```rust + /// # let mut config = prost_build::Config::new(); + /// config.file_descriptor_set_path("path/from/build/system") + /// .skip_source_info() + /// .compile_protos(&["src/items.proto"], &["src/"]); + /// ``` + /// + pub fn skip_source_info(&mut self) -> &mut Self { + self.skip_source_info = true; + self + } + /// Configures the code generator to not strip the enum name from variant names. /// /// Protobuf enum definitions commonly include the enum name as a prefix of every variant name. @@ -902,10 +923,11 @@ impl Config { if !self.skip_protoc_run { let mut cmd = Command::new(&self.protoc_executable); - cmd.arg("--include_imports") - .arg("--include_source_info") - .arg("-o") - .arg(&file_descriptor_set_path); + cmd.arg("--include_imports"); + if !self.skip_source_info { + cmd.arg("--include_source_info"); + } + cmd.arg("-o").arg(&file_descriptor_set_path); for include in includes { if include.as_ref().exists() { @@ -1170,6 +1192,7 @@ impl default::Default for Config { disable_comments: PathMap::default(), skip_debug: PathMap::default(), skip_protoc_run: false, + skip_source_info: false, include_file: None, prost_path: None, #[cfg(feature = "format")] From f1ae540bddd6e54389e33ba8103bf089a8938f7e Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Mon, 30 Dec 2024 10:38:32 -0500 Subject: [PATCH 2/4] Update prost-build/src/config.rs Co-authored-by: David Barsky --- prost-build/src/config.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/prost-build/src/config.rs b/prost-build/src/config.rs index 7927e6b6e..4b68cf204 100644 --- a/prost-build/src/config.rs +++ b/prost-build/src/config.rs @@ -598,11 +598,13 @@ impl Config { self } - /// This can be used to avoid passing ``--include_source_info`` argument when the `protoc` - /// command is invoked to generate the `FileDescriptorSet`. The ``--include_source_info`` - /// flag is passed by default, however it results in vastly larger descriptors that - /// include information about the original location of each decl in the source file as - /// well as surrounding comments. + /// Configures the code generator to remove surrounding comments and documentation. + /// + /// If enabled, this will cause `protoc` to not be passed the `--include_source_info` argument. + /// Typically, `--include_source_info` is passed by default, but it results in larger + /// [`FileDescriptorSet`s](https://github.com/protocolbuffers/protobuf/blob/cff254d32f850ba8186227ce6775b3f01a1f8cf8/src/google/protobuf/descriptor.proto#L54-L66) that include information about the + /// original location of each declaration in the source file as well as surrounding + /// comments and documentation. /// /// In `build.rs`: /// From db0e5f96becb7c40323bf17f03399ef67fac4c5c Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Mon, 30 Dec 2024 10:57:45 -0500 Subject: [PATCH 3/4] Update prost-build/src/config.rs Co-authored-by: David Barsky --- prost-build/src/config.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/prost-build/src/config.rs b/prost-build/src/config.rs index 4b68cf204..218f5ccf1 100644 --- a/prost-build/src/config.rs +++ b/prost-build/src/config.rs @@ -614,7 +614,6 @@ impl Config { /// .skip_source_info() /// .compile_protos(&["src/items.proto"], &["src/"]); /// ``` - /// pub fn skip_source_info(&mut self) -> &mut Self { self.skip_source_info = true; self From 357da782efc076f199b17fbed7729742d054692f Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Mon, 30 Dec 2024 11:00:37 -0500 Subject: [PATCH 4/4] fix fmt --- prost-build/src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prost-build/src/config.rs b/prost-build/src/config.rs index 218f5ccf1..bb9f8697a 100644 --- a/prost-build/src/config.rs +++ b/prost-build/src/config.rs @@ -599,7 +599,7 @@ impl Config { } /// Configures the code generator to remove surrounding comments and documentation. - /// + /// /// If enabled, this will cause `protoc` to not be passed the `--include_source_info` argument. /// Typically, `--include_source_info` is passed by default, but it results in larger /// [`FileDescriptorSet`s](https://github.com/protocolbuffers/protobuf/blob/cff254d32f850ba8186227ce6775b3f01a1f8cf8/src/google/protobuf/descriptor.proto#L54-L66) that include information about the