Skip to content

Commit c22744f

Browse files
committed
ci: Add codegen-related ci testing
Install protoc when executing `make deps` of the ttrpc. Add codegen's check and build, and example2' build to the ci testing. Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
1 parent d0f723d commit c22744f

File tree

12 files changed

+97
-23
lines changed

12 files changed

+97
-23
lines changed

.github/workflows/bvt.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
make check
1717
make -C compiler check
1818
make -C ttrpc-codegen check
19+
make -C codegen check
1920
2021
make:
2122
name: Build
@@ -33,6 +34,7 @@ jobs:
3334
make -C compiler
3435
make -C ttrpc-codegen
3536
make -C example build-examples
37+
make -C example2 build-examples
3638
3739
deny:
3840
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ tokio-vsock = { version = "0.3.1", optional = true }
2828

2929
[build-dependencies]
3030
protobuf-codegen = "3.1.0"
31-
prost-build = "0.11"
31+
prost-build = { version = "0.11", optional = true }
3232

3333
[features]
3434
default = ["sync"]
3535
async = ["dep:async-trait", "dep:tokio", "dep:futures", "dep:tokio-vsock"]
3636
sync = []
37-
prost = ["dep:prost"]
37+
prost = ["dep:prost", "dep:prost-build"]
3838

3939
[package.metadata.docs.rs]
4040
all-features = true

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@ build: debug
2121

2222
.PHONY: test
2323
test:
24-
cargo test --all-features --verbose
24+
cargo test --features sync,async --verbose
25+
cargo test --features sync,async,prost --verbose
2526

2627
.PHONY: check
2728
check:
2829
cargo fmt --all -- --check
29-
cargo clippy --all-targets --all-features -- -D warnings
30+
cargo clippy --all-targets --features sync,async -- -D warnings
31+
cargo clippy --all-targets --features sync,async,prost -- -D warnings
3032

3133
.PHONY: deps
3234
deps:
3335
rustup update stable
3436
rustup default stable
3537
rustup component add rustfmt clippy
38+
./install_protoc.sh

codegen/Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
all: debug test
2+
3+
#
4+
# Build
5+
#
6+
7+
.PHONY: debug
8+
debug:
9+
cargo build --verbose --all-targets
10+
11+
.PHONY: release
12+
release:
13+
cargo build --release
14+
15+
.PHONY: build
16+
build: debug
17+
18+
#
19+
# Tests and linters
20+
#
21+
22+
.PHONY: test
23+
test:
24+
cargo test --verbose
25+
26+
.PHONY: check
27+
check:
28+
cargo fmt --all -- --check
29+
cargo clippy --all-targets --all-features -- -D warnings
30+
31+
.PHONY: deps
32+
deps:
33+
rustup update stable
34+
rustup default stable
35+
rustup component add rustfmt clippy

example2/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
.PHONY: build
66
build:
7+
cargo build
8+
9+
.PHONY: build-examples
10+
build-examples: build
711
cargo build --example server
812
cargo build --example client
913
cargo build --example async-server

install_protoc.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
PB_REL="https://github.com/protocolbuffers/protobuf/releases"
4+
VERSION="22.0"
5+
6+
mkdir -p $HOME/protoc
7+
8+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
9+
ARCH="linux-x86_64"
10+
elif [[ "$OSTYPE" == "darwin"* ]]; then
11+
ARCH="osx-universal_binary"
12+
fi
13+
14+
curl -LO $PB_REL/download/v$VERSION/protoc-$VERSION-$ARCH.zip
15+
unzip protoc-$VERSION-$ARCH.zip -d $HOME/protoc
16+
rm -rf protoc-$VERSION-$ARCH.zip

src/asynchronous/server.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,10 @@ impl HandlerContext {
746746
};
747747
#[cfg(feature = "prost")]
748748
let resp = {
749-
let mut resp = Response::default();
750-
resp.status = Some(status);
751-
resp
749+
Response {
750+
status: Some(status),
751+
..Default::default()
752+
}
752753
};
753754
Self::respond(tx, stream_id, resp)
754755
.await

src/context.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,17 @@ pub fn to_pb(kvs: HashMap<String, Vec<String>>) -> Vec<KeyValue> {
6565

6666
for (k, vl) in kvs {
6767
for v in vl {
68+
#[cfg(not(feature = "prost"))]
6869
let key = KeyValue {
6970
key: k.clone(),
7071
value: v.clone(),
7172
..Default::default()
7273
};
74+
#[cfg(feature = "prost")]
75+
let key = KeyValue {
76+
key: k.clone(),
77+
value: v.clone(),
78+
};
7379
meta.push(key);
7480
}
7581
}
@@ -91,11 +97,17 @@ mod tests {
9197
("key1", "value1-2"),
9298
("key2", "value2"),
9399
] {
100+
#[cfg(not(feature = "prost"))]
94101
let key = KeyValue {
95102
key: i.0.to_string(),
96103
value: i.1.to_string(),
97104
..Default::default()
98105
};
106+
#[cfg(feature = "prost")]
107+
let key = KeyValue {
108+
key: i.0.to_string(),
109+
value: i.1.to_string(),
110+
};
99111
src.push(key);
100112
}
101113

src/error.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ pub fn get_status(c: Code, msg: impl ToString) -> Status {
5959
#[cfg(feature = "prost")]
6060
/// Get ttrpc::Status from ttrpc::Code and a message.
6161
pub fn get_status(c: Code, msg: impl ToString) -> Status {
62-
let mut status = Status::default();
63-
status.code = c as i32;
64-
status.message = msg.to_string();
65-
66-
status
62+
Status {
63+
code: c as i32,
64+
message: msg.to_string(),
65+
..Default::default()
66+
}
6767
}
6868

6969
pub fn get_rpc_status(c: Code, msg: impl ToString) -> Error {

src/proto.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -434,18 +434,17 @@ mod tests {
434434

435435
#[cfg(feature = "prost")]
436436
fn new_protobuf_request() -> Request {
437-
let mut creq = Request::default();
438-
creq.service = "grpc.TestServices".to_string();
439-
creq.method = "Test".to_string();
440-
creq.timeout_nano = 20 * 1000 * 1000;
441437
let meta = vec![KeyValue {
442438
key: "test_key1".to_string(),
443439
value: "test_value1".to_string(),
444-
..Default::default()
445440
}];
446-
creq.metadata = meta;
447-
creq.payload = vec![0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9];
448-
creq
441+
Request {
442+
service: "grpc.TestServices".to_owned(),
443+
method: "Test".to_owned(),
444+
timeout_nano: 20 * 1000 * 1000,
445+
metadata: meta,
446+
payload: vec![0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9],
447+
}
449448
}
450449

451450
#[test]

0 commit comments

Comments
 (0)