Skip to content

Commit

Permalink
Merge branch 'master' into fix-learner-index
Browse files Browse the repository at this point in the history
  • Loading branch information
nolouch authored Apr 18, 2019
2 parents 3c983cc + 3309b6b commit a1d4dd8
Show file tree
Hide file tree
Showing 45 changed files with 3,518 additions and 4,758 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ tmp
harness/target

Cargo.lock
rust-toolchain
*.rs.bk
*.rs.fmt
42 changes: 16 additions & 26 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
branches:
only:
# This is where pull requests from "bors r+" are built.
- staging
# This is where pull requests from "bors try" are built.
- trying
# Enable building pull requests.
- master
sudo: false

language: rust
sudo: false
os:
- linux
- windows
- osx
rust:
- stable
- nightly
# First Rust 2018 Stable. Officially the oldest compiler we support.
- 1.31.0
env:
global:
- RUST_BACKTRACE=1
- RUSTFLAGS="-D warnings"
cache: cargo

rust:

matrix:
include:
# This build uses stable and checks rustfmt and clippy.
# We don't check them on nightly since their lints and formatting may differ.
- rust: stable
install:
- rustup component add rustfmt-preview
- rustup component add clippy-preview
before_script:
- cargo fmt --all -- --check
- cargo clippy --all -- -D clippy
# Since many users will use nightlies, also test that.
- rust: nightly

install:
- if [[ $TRAVIS_RUST_VERSION == "stable" && $TRAVIS_OS_NAME == "linux" ]]; then rustup component add rustfmt; fi
- if [[ $TRAVIS_RUST_VERSION == "stable" && $TRAVIS_OS_NAME == "linux" ]]; then rustup component add clippy; fi

script:
- if [[ $TRAVIS_RUST_VERSION == "stable" && $TRAVIS_OS_NAME == "linux" ]]; then cargo fmt -- --check; fi
- if [[ $TRAVIS_RUST_VERSION == "stable" && $TRAVIS_OS_NAME == "linux" ]]; then cargo clippy -- -D clippy::all; fi
- cargo test --all -- --nocapture
# Validate benches still work.
- cargo bench --all -- --test
# Because failpoints inject failure in code path, which will affect all concurrently running tests, Hence they need to be synchronized, which make tests slow.
- cargo test --tests --features failpoint -- --nocapture
- cargo test --tests --features failpoint -- --nocapture
12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@ homepage = "https://github.com/pingcap/raft-rs"
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.4.1"

[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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ A complete Raft model contains 4 essential parts:
## Developing the Raft crate

`raft` is intended to track the latest `stable`, though you'll need to use `nightly` to simulate a full CI build with `clippy`.
`Raft` is built using the latest version of `stable` Rust, using [the 2018 edition](https://doc.rust-lang.org/edition-guide/rust-2018/).

Using `rustup` you can get started this way:

```bash
rustup component add clippy-preview
rustup component add rustfmt-preview
rustup component add clippy
rustup component add rustfmt
```

In order to have your PR merged running the following must finish without error:

```bash
cargo test --all && \
cargo clippy --all -- -D clippy && \
cargo clippy --all -- -D clippy::all && \
cargo fmt --all -- --check
```

Expand Down
32 changes: 0 additions & 32 deletions appveyor.yml

This file was deleted.

4 changes: 0 additions & 4 deletions benches/benches.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#![allow(dead_code)] // Due to criterion we need this to avoid warnings.
#![cfg_attr(feature = "cargo-clippy", allow(clippy::let_and_return))] // Benches often artificially return values. Allow it.

extern crate criterion;
extern crate env_logger;
extern crate raft;

use criterion::Criterion;
use std::time::Duration;

Expand Down
2 changes: 1 addition & 1 deletion benches/suites/progress_set.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::DEFAULT_RAFT_SETS;
use criterion::{Bencher, Criterion};
use raft::{Progress, ProgressSet};
use DEFAULT_RAFT_SETS;

pub fn bench_progress_set(c: &mut Criterion) {
bench_progress_set_new(c);
Expand Down
2 changes: 1 addition & 1 deletion benches/suites/raft.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::DEFAULT_RAFT_SETS;
use criterion::{Bencher, Criterion};
use raft::{storage::MemStorage, Config, Raft};
use DEFAULT_RAFT_SETS;

pub fn bench_raft(c: &mut Criterion) {
bench_raft_new(c);
Expand Down
3 changes: 1 addition & 2 deletions benches/suites/raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ pub fn bench_raw_node(c: &mut Criterion) {

fn quick_raw_node() -> RawNode<MemStorage> {
let id = 1;
let peers = vec![];
let storage = MemStorage::default();
let config = Config::new(id);
RawNode::new(&config, storage, peers).unwrap()
RawNode::new(&config, storage).unwrap()
}

pub fn bench_raw_node_new(c: &mut Criterion) {
Expand Down
82 changes: 82 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// 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",
GenOpt::All,
);
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");
}
Loading

0 comments on commit a1d4dd8

Please sign in to comment.