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

Auto protobuf build #38

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
24 changes: 21 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/protobuf
- $HOME/.cargo
- $TRAVIS_BUILD_DIR/target

rust:
- stable
Expand All @@ -15,12 +19,22 @@ matrix:
include:
- env: NAME='nightly'
rust: nightly
- env: NAME='rustfmt'
- env:
- NAME='rustfmt'
- PROTOBUF_CODEGEN_VERSION=2.0.0
- PATH=$PATH:$HOME/.cargo/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 --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 @@ -57,3 +71,7 @@ script:
- 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
- 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 = "1.7.1", optional = true }
serde = { version = "^1.0.55", optional = true }
serde_derive = { version = "^1.0.55", optional = true }

[build-dependencies]
protoc-rust = { version = "1.7.1", 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
41 changes: 41 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#[cfg(feature = "serialization-protobuf")]
extern crate protoc_rust;

#[cfg(feature = "serialization-protobuf")]
fn assert_protobuf_version(version: &str) {
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
);
}

#[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,
}).expect("protoc");
}

#[cfg(feature = "serialization-protobuf")]
fn build_protobuf_schemata() {
assert_protobuf_version("libprotoc 3.5.1");
build_protobuf("src/proto", &["protobuf/proof.proto"], &[]);
}

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

check_protoc_version () {
version="libprotoc $1"
PROTOC="$HOME/protobuf/bin/protoc"
if [ -f $PROTOC ]; then
this_version=`$PROTOC --version`
return `[ "$version" = "$this_version" ]`
else
return 1
fi
}

if check_protoc_version '3.5.1'; then
echo protoc version 3.5.1 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
Loading