Skip to content

Commit 089a378

Browse files
authored
Merge pull request #183 from Tim-Zhang/update-ttrpc-codegen
Update ttrpc-codegen
2 parents 1851aa0 + ed3ef2a commit 089a378

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

ttrpc-codegen/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ readme = "README.md"
1313

1414

1515
[dependencies]
16-
protobuf-support = "3.1.0"
16+
protobuf-support = "3.2.0"
1717
protobuf = { version = "2.27.1" }
18-
protobuf-codegen = "3.1.0"
18+
protobuf-codegen = "3.2.0"
1919
ttrpc-compiler = "0.6.1"

ttrpc-codegen/src/lib.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
//! .expect("Gen async code failed.");
2424
//! }
2525
26-
pub use protobuf_codegen::Customize as ProtobufCustomize;
26+
pub use protobuf_codegen::{
27+
Customize as ProtobufCustomize, CustomizeCallback as ProtobufCustomizeCallback,
28+
};
2729
use std::collections::HashMap;
2830
use std::error::Error;
2931
use std::fmt;
@@ -50,8 +52,8 @@ pub struct Codegen {
5052
inputs: Vec<PathBuf>,
5153
/// Generate rust-protobuf files along with rust-gprc
5254
rust_protobuf: bool,
53-
/// Customize rust-protobuf codegen
54-
pub rust_protobuf_customize: ProtobufCustomize,
55+
/// rust protobuf codegen
56+
rust_protobuf_codegen: protobuf_codegen::Codegen,
5557
/// Customize code generation
5658
customize: Customize,
5759
}
@@ -102,9 +104,18 @@ impl Codegen {
102104
self
103105
}
104106

105-
/// Customize code generated by rust-protobuf.
107+
/// Customize code generated by rust-protobuf-codegen.
106108
pub fn rust_protobuf_customize(&mut self, customize: ProtobufCustomize) -> &mut Self {
107-
self.rust_protobuf_customize = customize;
109+
self.rust_protobuf_codegen.customize(customize);
110+
self
111+
}
112+
113+
/// Callback for dynamic per-element customization of rust-protobuf-codegen.
114+
pub fn rust_protobuf_customize_callback(
115+
&mut self,
116+
customize: impl ProtobufCustomizeCallback,
117+
) -> &mut Self {
118+
self.rust_protobuf_codegen.customize_callback(customize);
108119
self
109120
}
110121

@@ -116,18 +127,17 @@ impl Codegen {
116127

117128
/// Like `protoc --rust_out=...` but without requiring `protoc` or `protoc-gen-rust`
118129
/// commands in `$PATH`.
119-
pub fn run(&self) -> io::Result<()> {
130+
pub fn run(&mut self) -> io::Result<()> {
120131
let includes: Vec<&Path> = self.includes.iter().map(|p| p.as_path()).collect();
121132
let inputs: Vec<&Path> = self.inputs.iter().map(|p| p.as_path()).collect();
122133
let p = parse_and_typecheck(&includes, &inputs)?;
123134

124135
if self.rust_protobuf {
125-
protobuf_codegen::Codegen::new()
136+
self.rust_protobuf_codegen
126137
.pure()
127138
.out_dir(&self.out_dir)
128139
.inputs(&self.inputs)
129140
.includes(&self.includes)
130-
.customize(self.rust_protobuf_customize.clone())
131141
.run()
132142
.expect("Gen rust protobuf failed.");
133143
}

0 commit comments

Comments
 (0)