Skip to content

Commit c72a079

Browse files
committed
*: support rust-protobuf
Signed-off-by: Ping Yu <[email protected]>
1 parent 85c59fb commit c72a079

File tree

6 files changed

+49
-19
lines changed

6 files changed

+49
-19
lines changed

Cargo.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ description = "The Rust language implementation of TiKV client."
99
edition = "2018"
1010

1111
[features]
12-
default = []
12+
default = [ "protobuf-codec" ]
1313
# Enable integration tests with a running TiKV and PD instance.
1414
# Use $PD_ADDRS, comma separated, to set the addresses the tests use.
1515
integration-tests = []
16+
protobuf-codec = ["tikv-client-proto/protobuf-codec", "grpcio/protobuf-codec"]
17+
prost-codec = ["tikv-client-proto/prost-codec", "grpcio/prost-codec"]
1618

1719
[lib]
1820
name = "tikv_client"
@@ -24,7 +26,7 @@ either = "1.6"
2426
fail = "0.4"
2527
futures = { version = "0.3", features = ["async-await", "thread-pool"] }
2628
futures-timer = "3.0"
27-
grpcio = { version = "0.10", features = [ "prost-codec", "openssl-vendored" ], default-features = false }
29+
grpcio = { version = "0.10", features = [ "openssl-vendored" ], default-features = false }
2830
lazy_static = "1"
2931
log = "0.4"
3032
prometheus = { version = "0.12", features = [ "push", "process" ], default-features = false }
@@ -70,3 +72,8 @@ members = [
7072
name = "failpoint_tests"
7173
path = "tests/failpoint_tests.rs"
7274
required-features = ["fail/failpoints"]
75+
76+
[patch.crates-io]
77+
raft-proto = { git = "https://github.com/tikv/raft-rs", rev="95c532612ee6a83591fce9a8b51d6afe87b58835"}
78+
protobuf-codegen = { git = "https://github.com/pingcap/rust-protobuf", rev="82b49fea7e696fd647b5aca0a6c6ec944eab3189" }
79+
protobuf = { git = "https://github.com/pingcap/rust-protobuf", rev="82b49fea7e696fd647b5aca0a6c6ec944eab3189" }

Makefile

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,36 @@ export RUSTFLAGS=-Dwarnings
22

33
.PHONY: default check unit-test integration-tests test doc docker-pd docker-kv docker all
44

5+
ENABLE_FEATURES ?=
6+
PD_ADDRS ?= "127.0.0.1:2379"
7+
MULTI_REGION ?= 1
8+
9+
# Use Rust-protobuf instead of Prost to encode and decode protocol buffers.
10+
ifeq ($(RUST_PROTOBUF),1)
11+
ENABLE_FEATURES += protobuf-codec
12+
else
13+
ENABLE_FEATURES += prost-codec
14+
endif
15+
16+
ALL_FEATURES := ${ENABLE_FEATURES} integration-tests
17+
18+
INTEGRATION_TEST_ARGS := --no-default-features --features "${ENABLE_FEATURES} integration-tests"
19+
520
default: check
621

722
check:
8-
cargo check --all --all-targets --all-features
23+
cargo check --all --all-targets --no-default-features --features "${ALL_FEATURES}"
924
cargo fmt -- --check
10-
cargo clippy --all-targets --all-features -- -D clippy::all
25+
cargo clippy --all-targets --no-default-features --features "${ALL_FEATURES}" -- -D clippy::all
1126

1227
unit-test:
13-
cargo test --all
28+
cargo test --all --no-default-features --features "${ENABLE_FEATURES}"
1429

1530
integration-test:
1631
# MULTI_REGION shall be set manually if needed
17-
PD_ADDRS="127.0.0.1:2379" cargo test txn_ --all --features integration-tests -- --nocapture
18-
PD_ADDRS="127.0.0.1:2379" cargo test raw_ --all --features integration-tests -- --nocapture
19-
PD_ADDRS="127.0.0.1:2379" cargo test misc_ --all --features integration-tests -- --nocapture
32+
cargo test txn_ --all ${INTEGRATION_TEST_ARGS} -- --nocapture
33+
cargo test raw_ --all ${INTEGRATION_TEST_ARGS} -- --nocapture
34+
cargo test misc_ --all ${INTEGRATION_TEST_ARGS} -- --nocapture
2035

2136
test: unit-test integration-test
2237

@@ -36,3 +51,7 @@ tiup:
3651
tiup playground nightly --mode tikv-slim --kv 3 --without-monitor --kv.config $(shell pwd)/config/tikv.toml --pd.config $(shell pwd)/config/pd.toml &
3752

3853
all: check doc test
54+
55+
clean:
56+
cargo clean
57+
rm -rf target

tests/integration_tests.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,7 @@ async fn txn_pessimistic_rollback() -> Result<()> {
596596
#[serial]
597597
async fn txn_pessimistic_delete() -> Result<()> {
598598
init().await?;
599-
let client =
600-
TransactionClient::new_with_config(vec!["127.0.0.1:2379"], Default::default(), None)
601-
.await?;
599+
let client = TransactionClient::new_with_config(pd_addrs(), Default::default(), None).await?;
602600

603601
// The transaction will lock the keys and must release the locks on commit,
604602
// even when values are not written to the DB.

tikv-client-proto/Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ repository = "https://github.com/tikv/client-rust"
88
description = "Protobuf specs for the TiKV Rust client"
99
build = "build.rs"
1010

11+
[features]
12+
protobuf-codec = ["protobuf-build/grpcio-protobuf-codec", "raft-proto/protobuf-codec", "grpcio/protobuf-codec"]
13+
prost-codec = ["prost", "prost-derive", "protobuf-build/grpcio-prost-codec", "grpcio/prost-codec", "raft-proto/prost-codec"]
14+
1115
[build-dependencies]
12-
protobuf-build = { version = "0.13", default-features = false, features = ["grpcio-prost-codec"] }
16+
protobuf-build = { version = "0.13", default-features = false }
1317

1418
[dependencies]
1519
protobuf = "2.8"
16-
prost = { version = "0.9" }
17-
prost-derive = { version = "0.9" }
20+
prost = { version = "0.9", optional = true }
21+
prost-derive = { version = "0.9", optional = true }
1822
futures = "0.3"
19-
grpcio = { version = "0.10", features = [ "prost-codec" ], default-features = false }
23+
grpcio = { version = "0.10", default-features = false }
2024
lazy_static = { version = "1" }
25+
raft-proto = { version = "0.7.0", default-features = false }

tikv-client-proto/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use protobuf_build::Builder;
44

55
fn main() {
66
Builder::new()
7-
.search_dir_for_protos("./proto")
8-
.includes(&["./include", "./proto"])
7+
.search_dir_for_protos("proto")
8+
.append_to_black_list("eraftpb")
99
.generate()
1010
}

tikv-client-proto/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0.
22

3-
use protos::*;
4-
pub use protos::{coprocessor, errorpb, kvrpcpb, metapb, mpp, pdpb, raft_serverpb, tikvpb};
3+
pub use protos::*;
54

65
#[allow(dead_code)]
76
#[allow(clippy::all)]
87
mod protos {
98
include!(concat!(env!("OUT_DIR"), "/protos/mod.rs"));
9+
10+
use raft_proto::eraftpb;
1011
}

0 commit comments

Comments
 (0)