Skip to content

Commit da8166f

Browse files
justxueweijokemanfire
authored andcommitted
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 c8bacbd commit da8166f

File tree

12 files changed

+107
-33
lines changed

12 files changed

+107
-33
lines changed

.github/workflows/bvt.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ jobs:
1212
uses: actions/checkout@v3
1313
- name: Check
1414
run: |
15-
make check-all
15+
make deps
16+
make check
17+
make -C compiler check
18+
make -C ttrpc-codegen check
19+
make -C codegen check
1620
1721
make:
1822
name: Build
@@ -29,9 +33,7 @@ jobs:
2933
make -C compiler
3034
make -C ttrpc-codegen
3135
make -C example build-examples
32-
# It's important for windows to fail correctly
33-
# https://github.com/actions/runner-images/issues/6668
34-
shell: bash
36+
make -C example2 build-examples
3537
3638
deny:
3739
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ tokio-vsock = { version = "0.7.0", optional = true }
3535
# lock home to avoid conflict with latest version
3636
home = "=0.5.9"
3737
protobuf-codegen = "3.1.0"
38-
prost-build = "0.11"
38+
prost-build = { version = "0.11", optional = true }
3939

4040
[features]
4141
default = ["sync"]
4242
async = ["dep:async-trait", "dep:tokio", "dep:futures", "dep:tokio-vsock"]
4343
sync = []
44-
prost = ["dep:prost"]
44+
prost = ["dep:prost", "dep:prost-build"]
4545

4646
[package.metadata.docs.rs]
4747
all-features = true

Makefile

Lines changed: 11 additions & 8 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
25-
24+
cargo test --features sync,async --verbose
25+
cargo test --features sync,async,prost --verbose
26+
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

31-
.PHONY: check-all
32-
check-all:
33-
$(MAKE) check
34-
$(MAKE) -C compiler check
35-
$(MAKE) -C ttrpc-codegen check
33+
.PHONY: deps
34+
deps:
35+
rustup update stable
36+
rustup default stable
37+
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
@@ -706,9 +706,10 @@ impl HandlerContext {
706706
};
707707
#[cfg(feature = "prost")]
708708
let resp = {
709-
let mut resp = Response::default();
710-
resp.status = Some(status);
711-
resp
709+
Response {
710+
status: Some(status),
711+
..Default::default()
712+
}
712713
};
713714
Self::respond(tx, stream_id, resp)
714715
.await

src/context.rs

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

7171
for (k, vl) in kvs {
7272
for v in vl {
73+
#[cfg(not(feature = "prost"))]
7374
let key = KeyValue {
7475
key: k.clone(),
7576
value: v.clone(),
7677
..Default::default()
7778
};
79+
#[cfg(feature = "prost")]
80+
let key = KeyValue {
81+
key: k.clone(),
82+
value: v.clone(),
83+
};
7884
meta.push(key);
7985
}
8086
}
@@ -96,11 +102,17 @@ mod tests {
96102
("key1", "value1-2"),
97103
("key2", "value2"),
98104
] {
105+
#[cfg(not(feature = "prost"))]
99106
let key = KeyValue {
100107
key: i.0.to_string(),
101108
value: i.1.to_string(),
102109
..Default::default()
103110
};
111+
#[cfg(feature = "prost")]
112+
let key = KeyValue {
113+
key: i.0.to_string(),
114+
value: i.1.to_string(),
115+
};
104116
src.push(key);
105117
}
106118

src/error.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ pub fn get_status(c: Code, msg: impl ToString) -> Status {
7878
#[cfg(feature = "prost")]
7979
/// Get ttrpc::Status from ttrpc::Code and a message.
8080
pub fn get_status(c: Code, msg: impl ToString) -> Status {
81-
let mut status = Status::default();
82-
status.code = c as i32;
83-
status.message = msg.to_string();
84-
85-
status
81+
Status {
82+
code: c as i32,
83+
message: msg.to_string(),
84+
..Default::default()
85+
}
8686
}
8787

8888
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
@@ -493,18 +493,17 @@ mod tests {
493493

494494
#[cfg(feature = "prost")]
495495
fn new_protobuf_request() -> Request {
496-
let mut creq = Request::default();
497-
creq.service = "grpc.TestServices".to_string();
498-
creq.method = "Test".to_string();
499-
creq.timeout_nano = 20 * 1000 * 1000;
500496
let meta = vec![KeyValue {
501497
key: "test_key1".to_string(),
502498
value: "test_value1".to_string(),
503-
..Default::default()
504499
}];
505-
creq.metadata = meta;
506-
creq.payload = vec![0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9];
507-
creq
500+
Request {
501+
service: "grpc.TestServices".to_owned(),
502+
method: "Test".to_owned(),
503+
timeout_nano: 20 * 1000 * 1000,
504+
metadata: meta,
505+
payload: vec![0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9],
506+
}
508507
}
509508

510509
#[test]

0 commit comments

Comments
 (0)