Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace rust-protobuf with prost #201

Merged
merged 58 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
3fe4369
Replace script with build script, use features
ice1000 Jan 30, 2019
39996ad
Cargo fmt
ice1000 Jan 30, 2019
9323c47
Apply some suggestions from rust clippy
ice1000 Jan 30, 2019
62d1f8e
Remove everything related to prost
ice1000 Jan 31, 2019
e63166a
Refactor build.rs
ice1000 Jan 31, 2019
3e5ecc3
Save progress
ice1000 Jan 31, 2019
96143b3
Refactor build.rs
ice1000 Jan 31, 2019
2e6afde
Merge branch 'master' into master
Hoverbear Feb 11, 2019
e14ae28
Refactor build.rs
ice1000 Jan 31, 2019
78e460f
Save progress
ice1000 Jan 31, 2019
ed462e3
Merge branch 'prost' of https://github.com/ice1000/raft-rs into prost
ice1000 Feb 14, 2019
e9ceaa4
Documentation in src/lib.rs
ice1000 Feb 15, 2019
d056ffe
Merge remote-tracking branch tikv/master
ice1000 Feb 15, 2019
e7e5ac0
Add [cfg(feature = "lib-rust-protobuf")] to every protobuf places
ice1000 Feb 15, 2019
2ffb284
Replace common.sh with rust code
ice1000 Feb 16, 2019
35da6d4
Merge branch 'master' into prost
ice1000 Feb 16, 2019
0993e17
Fix compilation error
ice1000 Feb 16, 2019
e1e5868
Fix typo
ice1000 Feb 16, 2019
a52bace
Cargo fmt
ice1000 Feb 16, 2019
54a29e3
Merge branch 'master' into master
Hoverbear Feb 20, 2019
7f064df
Merge branch 'master' into master
Hoverbear Feb 20, 2019
cdbfffa
Merge remote-tracking branch 'tikv/master'
ice1000 Feb 22, 2019
f98f212
Merge branch 'master' of https://github.com/ice1000/raft-rs
ice1000 Feb 22, 2019
824f6d9
Merge branch 'master' into prost
ice1000 Feb 22, 2019
b49d940
Fix typo-caused compilation error
ice1000 Feb 22, 2019
c95c4dc
Merge branch 'master' into prost
ice1000 Feb 22, 2019
7a322ca
Fix compilation errors
ice1000 Feb 22, 2019
90659f2
Merge remote-tracking branch 'origin/master' into prost
ice1000 Feb 24, 2019
e78a99c
Add rsprost file to git repo
ice1000 Feb 25, 2019
b406b3a
Save progress
ice1000 Mar 12, 2019
d5a6a2e
Merge remote-tracking branch 'origin/master' into prost
ice1000 Mar 12, 2019
995c775
Save progress
ice1000 Mar 12, 2019
08e408c
Successfully generate!
ice1000 Mar 12, 2019
76df7aa
Refactor, only one error is left now
ice1000 Mar 17, 2019
11fd985
Fix all errors occurred in `src`, start working on `tests`
ice1000 Mar 17, 2019
51ad68a
Test compiles, remove rust-protobuf support
ice1000 Mar 24, 2019
d3e1579
Merge
ice1000 Mar 24, 2019
57dba74
Merge remote-tracking branch 'tikv/master' into prost
ice1000 Mar 30, 2019
d050f12
Compatible with stable rust, pass 150 tests now
ice1000 Mar 30, 2019
139624d
Sounds like all tests are passed
ice1000 Mar 30, 2019
72da68c
Passing all doc-tests
ice1000 Mar 30, 2019
f3ea832
Use git dependency instead of relative path
ice1000 Mar 30, 2019
48724b4
Partially address comments
ice1000 Apr 1, 2019
6933ede
Merge remote-tracking branch 'tikv/master' into prost
ice1000 Apr 4, 2019
cc996af
Fix tests after merge
ice1000 Apr 4, 2019
19a42e2
Rename generated mod to `prost` from `rsprost`
ice1000 Apr 4, 2019
bf88990
Remove `RepeatedField::from_vec`
ice1000 Apr 4, 2019
3b9a8bb
Remove all uses of `protobuf::Message as Msg`
ice1000 Apr 4, 2019
28294fa
Remove `Codec` error and remove tests (not added for prost's errors b…
ice1000 Apr 4, 2019
64b3497
Remove even more protobuf stuff, apply some minor suggestions by clippy
ice1000 Apr 4, 2019
651dfd9
Clean up build script
ice1000 Apr 4, 2019
e56bbe7
Fix clippy warnings
ice1000 Apr 4, 2019
cf52151
Use `merge`
ice1000 Apr 4, 2019
f2c0219
Add rust-protobuf codes back
ice1000 Apr 4, 2019
f2dce76
Revert unexpected comment changes
ice1000 Apr 4, 2019
9cbda50
Merge branch 'master' into prost
ice1000 Apr 6, 2019
37ef7bd
Merge branch 'master' into prost
Hoverbear Apr 9, 2019
c0397c8
Merge branch 'master' into prost
Hoverbear Apr 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,25 @@ documentation = "https://docs.rs/raft"
description = "The rust language implementation of Raft algorithm."
categories = ["algorithms", "database-implementations"]
edition = "2018"
build = "build.rs"

[build-dependencies]
protobuf-build = "0.3"

[features]
default = []
gen = []
# Enable failpoints
failpoint = ["fail"]

# Make sure to synchronize updates with Harness.
[dependencies]
log = ">0.2"
protobuf = "~2.0-2.2"
protobuf = "~2.1-2.2"
lazy_static = "1.3.0"
prost = "0.5"
prost-derive = "0.5"
bytes = "0.4.11"
quick-error = "1.2.2"
rand = "0.5.4"
hashbrown = "0.1"
Expand Down
81 changes: 81 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

use protobuf_build::*;
use std::fs::{read_dir, File};
use std::io::Write;

fn main() {
// This build script creates files in the `src` directory. Since that is
// outside Cargo's OUT_DIR it will cause an error when this crate is used
// as a dependency. Therefore, the user must opt-in to regenerating the
// Rust files.
if !cfg!(feature = "gen") {
println!("cargo:rerun-if-changed=build.rs");
return;
}

check_protoc_version();

let file_names: Vec<_> = read_dir("proto")
.expect("Couldn't read proto directory")
.filter_map(|e| {
let e = e.expect("Couldn't list file");
if e.file_type().expect("File broken").is_dir() {
None
} else {
Some(format!("proto/{}", e.file_name().to_string_lossy()))
}
})
.collect();

for f in &file_names {
println!("cargo:rerun-if-changed={}", f);
}

// Generate Prost files.
generate_prost_files(&file_names, "src/prost");
let mod_names = module_names_for_dir("src/prost");
generate_wrappers(
&mod_names
.iter()
.map(|m| format!("src/prost/{}.rs", m))
.collect::<Vec<_>>(),
"src/prost",
);
generate_prost_rs(&mod_names);
}

fn generate_prost_rs(mod_names: &[String]) {
let mut text = "#![allow(dead_code)]\n\
#![allow(missing_docs)]\n\
#![allow(clippy::all)]\n\n"
.to_owned();

for mod_name in mod_names {
text.push_str("pub mod ");
text.push_str(mod_name);
text.push_str("{\n");
text.push_str("include!(\"prost/");
text.push_str(mod_name);
text.push_str(".rs\");");
text.push_str("include!(\"prost/wrapper_");
text.push_str(mod_name);
text.push_str(".rs\");");
text.push_str("}\n\n");
}

let mut lib = File::create("src/prost.rs").expect("Could not create prost.rs");
lib.write_all(text.as_bytes())
.expect("Could not write prost.rs");
}
8 changes: 4 additions & 4 deletions examples/five_mem_node/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#[macro_use]
extern crate log;
extern crate env_logger;
extern crate protobuf;
extern crate prost;
extern crate raft;
extern crate regex;

Expand All @@ -23,7 +23,7 @@ use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
use std::{str, thread};

use protobuf::Message as PbMessage;
use prost::Message as ProstMsg;
use raft::eraftpb::ConfState;
use raft::storage::MemStorage;
use raft::{prelude::*, StateRole};
Expand Down Expand Up @@ -224,8 +224,8 @@ fn on_ready(
}
if let EntryType::EntryConfChange = entry.get_entry_type() {
// For conf change messages, make them effective.
let mut cc = ConfChange::new();
cc.merge_from_bytes(entry.get_data()).unwrap();
let mut cc = ConfChange::new_();
ProstMsg::merge(&mut cc, entry.get_data()).unwrap();
let node_id = cc.get_node_id();
match cc.get_change_type() {
ConfChangeType::AddNode => raft_group.raft.add_node(node_id).unwrap(),
Expand Down
15 changes: 0 additions & 15 deletions generate-proto.sh

This file was deleted.

Loading