Skip to content

Commit

Permalink
use eraftpb from raft-rs (pingcap#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
BusyJay authored Mar 12, 2018
1 parent 7047aae commit 123051e
Show file tree
Hide file tree
Showing 15 changed files with 602 additions and 2,949 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ name = "kvproto"
protobuf = "1.*"
futures = "0.1"
grpcio = "0.2"
raft = "0.1"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Protocol buffer files for TiKV
# Usage

+ Write your own protocol file in proto folder.
+ If you need to update raft-rs, please download the proto file
respectively and overwrite the one in include folder.
+ Run `make` to generate go and rust code.
We generate all go codes in pkg folder and rust in src folder.
+ Update the dependent projects.
Expand Down
1 change: 0 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ machine:
RUST_TEST_THREADS: 1
RUST_BACKTRACE: 1
RUSTFLAGS: "-Dwarnings"
RUSTFMT_VERSION: "v0.6.0"
post:
- mkdir -p download
- test -e download/$GODIST || curl -o download/$GODIST https://storage.googleapis.com/golang/$GODIST
Expand Down
28 changes: 21 additions & 7 deletions generate_go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,32 @@ if ! cmd_exists protoc-gen-gofast; then
done
fi

cd proto
for file in `ls *.proto`
do
function collect() {
file=$(basename $1)
base_name=$(basename $file ".proto")
mkdir -p ../pkg/$base_name
if [ -z $GO_OUT_M ]; then
GO_OUT_M="M$file=$GO_PREFIX_PATH/$base_name"
else
GO_OUT_M="$GO_OUT_M,M$file=$GO_PREFIX_PATH/$base_name"
fi
}

# Although eraftpb.proto is copying from raft-rs, however there is no
# official go code ship with the crate, so we need to generate it manually.
collect include/eraftpb.proto
cd proto
for file in `ls *.proto`
do
collect $file
done

echo "generate go code..."
ret=0
for file in `ls *.proto`
do
base_name=$(basename $file ".proto")
protoc -I.:${GOGO_ROOT}:${GOGO_ROOT}/protobuf --gofast_out=plugins=grpc,$GO_OUT_M:../pkg/$base_name $file || ret=$?

function gen() {
base_name=$(basename $1 ".proto")
protoc -I.:${GOGO_ROOT}:${GOGO_ROOT}/protobuf:../include --gofast_out=plugins=grpc,$GO_OUT_M:../pkg/$base_name $1 || ret=$?
cd ../pkg/$base_name
sed -i.bak -E 's/import _ \"gogoproto\"//g' *.pb.go
sed -i.bak -E 's/import fmt \"fmt\"//g' *.pb.go
Expand All @@ -64,5 +72,11 @@ for file in `ls *.proto`
rm -f *.bak
goimports -w *.pb.go
cd ../../proto
}

gen ../include/eraftpb.proto
for file in `ls *.proto`
do
gen $file
done
exit $ret
17 changes: 11 additions & 6 deletions generate_rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,22 @@ if ! cmd_exists protoc-gen-gofast; then
done
fi

protoc -I.:${GOGO_ROOT}:${GOGO_ROOT}/protobuf --rust_out ../src *.proto || exit $?
protoc -I.:${GOGO_ROOT}:${GOGO_ROOT}/protobuf --grpc_out ../src --plugin=protoc-gen-grpc=`which grpc_rust_plugin` *.proto || exit $?
protoc -I.:${GOGO_ROOT}:${GOGO_ROOT}/protobuf:../include --rust_out ../src *.proto || exit $?
protoc -I.:${GOGO_ROOT}:${GOGO_ROOT}/protobuf:../include --grpc_out ../src --plugin=protoc-gen-grpc=`which grpc_rust_plugin` *.proto || exit $?
pop

push src
LIB_RS=`mktemp`
rm -f lib.rs
echo "extern crate protobuf;" > ${LIB_RS}
echo "extern crate futures;" >> ${LIB_RS}
echo "extern crate grpcio;" >> ${LIB_RS}
echo >> ${LIB_RS}
cat <<EOF > ${LIB_RS}
extern crate futures;
extern crate grpcio;
extern crate protobuf;
extern crate raft;
use raft::eraftpb;
EOF
for file in `ls *.rs`
do
base_name=$(basename $file ".rs")
Expand Down
2 changes: 0 additions & 2 deletions proto/eraftpb.proto → include/eraftpb.proto
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
syntax = "proto3";
package eraftpb;

option java_package = "com.pingcap.tikv.kvproto";

enum EntryType {
EntryNormal = 0;
EntryConfChange = 1;
Expand Down
Loading

0 comments on commit 123051e

Please sign in to comment.