*: support rust-protobuf

Signed-off-by: Ping Yu <yuping@pingcap.com>
This commit is contained in:
Ping Yu 2022-12-22 00:20:24 +08:00
parent 85c59fbe16
commit c72a079b65
6 changed files with 49 additions and 19 deletions

View File

@ -9,10 +9,12 @@ description = "The Rust language implementation of TiKV client."
edition = "2018"
[features]
default = []
default = [ "protobuf-codec" ]
# Enable integration tests with a running TiKV and PD instance.
# Use $PD_ADDRS, comma separated, to set the addresses the tests use.
integration-tests = []
protobuf-codec = ["tikv-client-proto/protobuf-codec", "grpcio/protobuf-codec"]
prost-codec = ["tikv-client-proto/prost-codec", "grpcio/prost-codec"]
[lib]
name = "tikv_client"
@ -24,7 +26,7 @@ either = "1.6"
fail = "0.4"
futures = { version = "0.3", features = ["async-await", "thread-pool"] }
futures-timer = "3.0"
grpcio = { version = "0.10", features = [ "prost-codec", "openssl-vendored" ], default-features = false }
grpcio = { version = "0.10", features = [ "openssl-vendored" ], default-features = false }
lazy_static = "1"
log = "0.4"
prometheus = { version = "0.12", features = [ "push", "process" ], default-features = false }
@ -70,3 +72,8 @@ members = [
name = "failpoint_tests"
path = "tests/failpoint_tests.rs"
required-features = ["fail/failpoints"]
[patch.crates-io]
raft-proto = { git = "https://github.com/tikv/raft-rs", rev="95c532612ee6a83591fce9a8b51d6afe87b58835"}
protobuf-codegen = { git = "https://github.com/pingcap/rust-protobuf", rev="82b49fea7e696fd647b5aca0a6c6ec944eab3189" }
protobuf = { git = "https://github.com/pingcap/rust-protobuf", rev="82b49fea7e696fd647b5aca0a6c6ec944eab3189" }

View File

@ -2,21 +2,36 @@ export RUSTFLAGS=-Dwarnings
.PHONY: default check unit-test integration-tests test doc docker-pd docker-kv docker all
ENABLE_FEATURES ?=
PD_ADDRS ?= "127.0.0.1:2379"
MULTI_REGION ?= 1
# Use Rust-protobuf instead of Prost to encode and decode protocol buffers.
ifeq ($(RUST_PROTOBUF),1)
ENABLE_FEATURES += protobuf-codec
else
ENABLE_FEATURES += prost-codec
endif
ALL_FEATURES := ${ENABLE_FEATURES} integration-tests
INTEGRATION_TEST_ARGS := --no-default-features --features "${ENABLE_FEATURES} integration-tests"
default: check
check:
cargo check --all --all-targets --all-features
cargo check --all --all-targets --no-default-features --features "${ALL_FEATURES}"
cargo fmt -- --check
cargo clippy --all-targets --all-features -- -D clippy::all
cargo clippy --all-targets --no-default-features --features "${ALL_FEATURES}" -- -D clippy::all
unit-test:
cargo test --all
cargo test --all --no-default-features --features "${ENABLE_FEATURES}"
integration-test:
# MULTI_REGION shall be set manually if needed
PD_ADDRS="127.0.0.1:2379" cargo test txn_ --all --features integration-tests -- --nocapture
PD_ADDRS="127.0.0.1:2379" cargo test raw_ --all --features integration-tests -- --nocapture
PD_ADDRS="127.0.0.1:2379" cargo test misc_ --all --features integration-tests -- --nocapture
cargo test txn_ --all ${INTEGRATION_TEST_ARGS} -- --nocapture
cargo test raw_ --all ${INTEGRATION_TEST_ARGS} -- --nocapture
cargo test misc_ --all ${INTEGRATION_TEST_ARGS} -- --nocapture
test: unit-test integration-test
@ -36,3 +51,7 @@ tiup:
tiup playground nightly --mode tikv-slim --kv 3 --without-monitor --kv.config $(shell pwd)/config/tikv.toml --pd.config $(shell pwd)/config/pd.toml &
all: check doc test
clean:
cargo clean
rm -rf target

View File

@ -596,9 +596,7 @@ async fn txn_pessimistic_rollback() -> Result<()> {
#[serial]
async fn txn_pessimistic_delete() -> Result<()> {
init().await?;
let client =
TransactionClient::new_with_config(vec!["127.0.0.1:2379"], Default::default(), None)
.await?;
let client = TransactionClient::new_with_config(pd_addrs(), Default::default(), None).await?;
// The transaction will lock the keys and must release the locks on commit,
// even when values are not written to the DB.

View File

@ -8,13 +8,18 @@ repository = "https://github.com/tikv/client-rust"
description = "Protobuf specs for the TiKV Rust client"
build = "build.rs"
[features]
protobuf-codec = ["protobuf-build/grpcio-protobuf-codec", "raft-proto/protobuf-codec", "grpcio/protobuf-codec"]
prost-codec = ["prost", "prost-derive", "protobuf-build/grpcio-prost-codec", "grpcio/prost-codec", "raft-proto/prost-codec"]
[build-dependencies]
protobuf-build = { version = "0.13", default-features = false, features = ["grpcio-prost-codec"] }
protobuf-build = { version = "0.13", default-features = false }
[dependencies]
protobuf = "2.8"
prost = { version = "0.9" }
prost-derive = { version = "0.9" }
prost = { version = "0.9", optional = true }
prost-derive = { version = "0.9", optional = true }
futures = "0.3"
grpcio = { version = "0.10", features = [ "prost-codec" ], default-features = false }
grpcio = { version = "0.10", default-features = false }
lazy_static = { version = "1" }
raft-proto = { version = "0.7.0", default-features = false }

View File

@ -4,7 +4,7 @@ use protobuf_build::Builder;
fn main() {
Builder::new()
.search_dir_for_protos("./proto")
.includes(&["./include", "./proto"])
.search_dir_for_protos("proto")
.append_to_black_list("eraftpb")
.generate()
}

View File

@ -1,10 +1,11 @@
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0.
use protos::*;
pub use protos::{coprocessor, errorpb, kvrpcpb, metapb, mpp, pdpb, raft_serverpb, tikvpb};
pub use protos::*;
#[allow(dead_code)]
#[allow(clippy::all)]
mod protos {
include!(concat!(env!("OUT_DIR"), "/protos/mod.rs"));
use raft_proto::eraftpb;
}