Skip to content

Commit f622312

Browse files
committed
Rename protoc-rust-ttrpc and update it for publish
Change its name to ttrpc-codegen. Signed-off-by: Tim Zhang <[email protected]>
1 parent f9646ed commit f622312

File tree

9 files changed

+103
-54
lines changed

9 files changed

+103
-54
lines changed

protoc-rust-ttrpc/Cargo.toml

Lines changed: 0 additions & 13 deletions
This file was deleted.

ttrpc-codegen/Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "ttrpc-codegen"
3+
version = "0.1.1"
4+
edition = "2018"
5+
authors = ["The AntFin Kata Team <[email protected]>"]
6+
license = "Apache-2.0"
7+
keywords = ["codegen", "ttrpc", "protobuf"]
8+
description = "Rust codegen for ttrpc using ttrpc-compiler crate"
9+
categories = ["network-programming", "development-tools::build-utils"]
10+
repository = "https://github.com/containerd/ttrpc-rust/tree/master/ttrpc-codegen"
11+
homepage = "https://github.com/containerd/ttrpc-rust/tree/master/ttrpc-codegen"
12+
readme = "README.md"
13+
14+
15+
[dependencies]
16+
protobuf = { version = "2.14.0" }
17+
protobuf-codegen-pure = "2.14.0"
18+
protobuf-codegen = "2.14.0"
19+
ttrpc-compiler = "0.3"

ttrpc-codegen/LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
Copyright (c) 2020 Ant Financial
3+
Copyright (c) 2019 Stepan Koltsov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21+
OR OTHER DEALINGS IN THE SOFTWARE.

ttrpc-codegen/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# API to generate .rs files for ttrpc from protobuf
2+
3+
API to generate `.rs` files to be used e. g. [from build.rs](../example/build.rs).
4+
5+
Example code:
6+
7+
```rust
8+
use ttrpc_codegen::Codegen;
9+
use ttrpc_codegen::Customize;
10+
11+
fn main() {
12+
Codegen::new()
13+
.out_dir("protocols/sync")
14+
.inputs(&protos)
15+
.include("protocols/protos")
16+
.rust_protobuf()
17+
.customize(Customize {
18+
..Default::default()
19+
})
20+
.run()
21+
.expect("Gen code failed.");
22+
}
23+
24+
```
25+
26+
And in `Cargo.toml`:
27+
28+
```
29+
[build-dependencies]
30+
ttrpc-codegen = "0.3"
31+
```
32+
33+
The alternative is to use
34+
[protoc-rust crate](https://github.com/stepancheg/rust-protobuf/tree/master/protoc-rust),
35+
which relies on `protoc` command to parse descriptors. Both crates should produce the same result,
36+
otherwise please file a bug report.
File renamed without changes.

protoc-rust-ttrpc/src/lib.rs renamed to ttrpc-codegen/src/lib.rs

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
//! API to generate .rs files for ttrpc from protobuf
2+
//!
3+
//!
4+
//!```
5+
//!use ttrpc_codegen::Codegen;
6+
//!use ttrpc_codegen::Customize;
7+
//!
8+
//!fn main() {
9+
//! Codegen::new()
10+
//! .out_dir("protocols/sync")
11+
//! .inputs(&protos)
12+
//! .include("protocols/protos")
13+
//! .rust_protobuf()
14+
//! .customize(Customize {
15+
//! ..Default::default()
16+
//! })
17+
//! .run()
18+
//! .expect("Gen code failed.");
19+
//!}
20+
//!
21+
//!```
22+
123
use protobuf_codegen::Customize as ProtobufCustomize;
224
use std::collections::HashMap;
325
use std::error::Error;
@@ -14,6 +36,7 @@ mod model;
1436
mod parser;
1537
mod str_lit;
1638

39+
/// Invoke pure rust codegen.
1740
#[derive(Debug, Default)]
1841
pub struct Codegen {
1942
/// --lang_out= param
@@ -26,6 +49,7 @@ pub struct Codegen {
2649
rust_protobuf: bool,
2750
/// Customize rust-protobuf codegen
2851
pub rust_protobuf_customize: ProtobufCustomize,
52+
/// Customize code generation
2953
customize: Customize,
3054
}
3155

@@ -69,18 +93,19 @@ impl Codegen {
6993
self
7094
}
7195

72-
/// Generate rust-protobuf files along with rust-gprc.
96+
/// Generate rust-protobuf files along with ttrpc-rust.
7397
pub fn rust_protobuf(&mut self) -> &mut Self {
7498
self.rust_protobuf = true;
7599
self
76100
}
77101

78-
/// Specify rust-protobuf generated code [`Customize`] object.
102+
/// Customize code generated by rust-protobuf.
79103
pub fn rust_protobuf_customize(&mut self, customize: ProtobufCustomize) -> &mut Self {
80104
self.rust_protobuf_customize = customize;
81105
self
82106
}
83107

108+
/// Customize code generation.
84109
pub fn customize(&mut self, customize: Customize) -> &mut Self {
85110
self.customize = customize;
86111
self
@@ -102,13 +127,6 @@ impl Codegen {
102127
.expect("Gen rust protobuf failed.");
103128
}
104129

105-
// let relative_paths: Vec<String> = p
106-
// .relative_paths
107-
// .iter()
108-
// .filter_map(|p| p.to_str())
109-
// .map(|p| p.to_string())
110-
// .collect();
111-
112130
ttrpc_compiler::codegen::gen_and_write(
113131
&p.file_descriptors,
114132
&p.relative_paths,
@@ -118,21 +136,6 @@ impl Codegen {
118136
}
119137
}
120138

121-
/// Arguments for pure rust codegen invocation.
122-
// TODO: merge with protoc-rust def
123-
#[derive(Debug, Default)]
124-
#[deprecated(since = "2.14", note = "Use Codegen object instead")]
125-
pub struct Args<'a> {
126-
/// --lang_out= param
127-
pub out_dir: &'a str,
128-
/// -I args
129-
pub includes: &'a [&'a str],
130-
/// List of .proto files to compile
131-
pub input: &'a [&'a str],
132-
/// Customize code generation
133-
pub customize: ProtobufCustomize,
134-
}
135-
136139
/// Convert OS path to protobuf path (with slashes)
137140
/// Function is `pub(crate)` for test.
138141
pub(crate) fn relative_path_to_protobuf_path(path: &Path) -> String {
@@ -344,23 +347,6 @@ pub fn parse_and_typecheck(
344347
})
345348
}
346349

347-
/// Like `protoc --rust_out=...` but without requiring `protoc` or `protoc-gen-rust`
348-
/// commands in `$PATH`.
349-
#[deprecated(since = "2.14", note = "Use Codegen instead")]
350-
#[allow(deprecated)]
351-
pub fn run(args: Args) -> io::Result<()> {
352-
let includes: Vec<&Path> = args.includes.iter().map(|p| Path::new(p)).collect();
353-
let inputs: Vec<&Path> = args.input.iter().map(|p| Path::new(p)).collect();
354-
let p = parse_and_typecheck(&includes, &inputs)?;
355-
356-
protobuf_codegen::gen_and_write(
357-
&p.file_descriptors,
358-
&p.relative_paths,
359-
&Path::new(&args.out_dir),
360-
&args.customize,
361-
)
362-
}
363-
364350
#[cfg(test)]
365351
mod test {
366352
use super::*;
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)