Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Cargo.lock
target/
src/proto/proof.rs
27 changes: 24 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
language: rust
cache: cargo # https://docs.travis-ci.com/user/caching/#Rust-Cargo-cache
cache:
directories:
- $HOME/.cargo
- $HOME/protobuf
- $TRAVIS_BUILD_DIR/target

rust:
- stable
Expand All @@ -15,12 +19,23 @@ matrix:
include:
- env: NAME='nightly'
rust: nightly
- env: NAME='rustfmt'
- env:
- NAME='rustfmt'
- PROTOBUF_CODEGEN_VERSION=2.0.0
- PATH=$PATH:$HOME/.cargo/bin:$HOME/protobuf/bin
rust: nightly
before_script:
- rustup component add rustfmt-preview
# Protoc plugin needed to generate proof.rs from proof.proto
- cargo install protobuf-codegen --version $PROTOBUF_CODEGEN_VERSION || echo "protobuf-codegen already installed"
# TODO: see if we can avoid installing protobuf-codegen and generating
# proof.rs in this build by using rustfmt options (see
# https://github.com/SpinResearch/merkle.rs/pull/38#issuecomment-391336829,
# paragraph 2).
- protoc --version
- protoc --rust_out src/proto/ protobuf/proof.proto
script:
- cargo fmt --all -- --write-mode=diff
- cargo fmt --all -- --check
- env: NAME='kcov'
sudo: required # travis-ci/travis-ci#9061
before_script:
Expand Down Expand Up @@ -54,6 +69,12 @@ env:
- RUSTFLAGS="-C link-dead-code"

script:
- cargo update
- cargo build --verbose --all-features
- cargo test --verbose --all-features
- cargo doc --verbose --all-features --no-deps

before_install:
- export PATH=$PATH:$HOME/protobuf/bin
- export PROTOC_VERSION=$(cat PROTOC_VERSION)
- bash install_protobuf.sh
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ categories = ["data-structures", "cryptography"]

[dependencies]
ring = "^0.12.0"
protobuf = { version = "^1.6.0", optional = true }
protobuf = { version = "^2.0.2", optional = true }
serde = { version = "^1.0.55", optional = true }
serde_derive = { version = "^1.0.55", optional = true }

[build-dependencies]
protoc-rust = { version = "^2.0.2", optional = true }

[dev-dependencies]
serde_json = "1.0.17"

[features]
serialization-protobuf = [ "protobuf" ]
serialization-protobuf = [ "protobuf", "protoc-rust" ]
serialization-serde = [ "serde", "serde_derive" ]

[package.metadata.release]
Expand Down
1 change: 1 addition & 0 deletions PROTOC_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libprotoc 3.5.1
50 changes: 50 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#[cfg(feature = "serialization-protobuf")]
extern crate protoc_rust;

#[cfg(feature = "serialization-protobuf")]
fn assert_protobuf_version(version: String) {
use std::process::{Command, Stdio};
let protoc = Command::new("protoc")
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.args(&["--version"])
.spawn()
.unwrap();
let version_output = protoc.wait_with_output().unwrap();
assert!(version_output.status.success());
assert_eq!(
String::from_utf8(version_output.stdout).unwrap().trim(),
version.trim()
);
}

#[cfg(feature = "serialization-protobuf")]
fn build_protobuf(out_dir: &str, input: &[&str], includes: &[&str]) {
use self::protoc_rust::{run, Args};
run(Args {
out_dir,
input,
includes,
customize: Default::default(),
}).expect("protoc");
}

#[cfg(feature = "serialization-protobuf")]
fn build_protobuf_schemata() {
use std::fs::File;
use std::io::Read;
let mut version_string = String::new();
let mut version_pin =
File::open("PROTOC_VERSION").expect("protoc version pin `PROTOC_VERSION` file is missing");
version_pin
.read_to_string(&mut version_string)
.expect("cannot read protoc pin file");
assert_protobuf_version(version_string);
build_protobuf("src/proto", &["protobuf/proof.proto"], &[]);
}

fn main() {
#[cfg(feature = "serialization-protobuf")]
build_protobuf_schemata();
}
18 changes: 18 additions & 0 deletions install_protobuf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/bash
set -e

PROTOC_VERSION=$(cat PROTOC_VERSION)

check_protoc_version () {
this_version=`protoc --version`
return `[ "$PROTOC_VERSION" = "$this_version" ]`
}

if check_protoc_version; then
echo $PROTOC_VERSION detected.
exit
fi

wget https://github.com/google/protobuf/archive/v3.5.1.tar.gz
tar -xzvf v3.5.1.tar.gz
cd protobuf-3.5.1 && ./autogen.sh && ./configure --prefix=$HOME/protobuf && make && make install
3 changes: 3 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ignore = [
"src/proto/proof.rs",
]
4 changes: 3 additions & 1 deletion src/merkletree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ pub struct MerkleTree<T> {
impl<T: PartialEq> PartialEq for MerkleTree<T> {
#[allow(trivial_casts)]
fn eq(&self, other: &MerkleTree<T>) -> bool {
self.root == other.root && self.height == other.height && self.count == other.count
self.root == other.root
&& self.height == other.height
&& self.count == other.count
&& (self.algorithm as *const Algorithm) == (other.algorithm as *const Algorithm)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/proto/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(missing_debug_implementations)]
mod proof;

use ring::digest::Algorithm;
Expand Down
Loading