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

13 changes: 11 additions & 2 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 @@ -12,6 +16,7 @@ matrix:
allow_failures:
- env: NAME='nightly'
- env: NAME='kcov'
- env: NAME='rustfmt' # temporarily allow rustfmt to fail until it can recognise conditional cfgs properly
include:
- env: NAME='nightly'
rust: nightly
Expand All @@ -20,7 +25,7 @@ matrix:
before_script:
- rustup component add rustfmt-preview
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 +62,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
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ 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 = "1.7.1"

[dev-dependencies]
serde_json = "1.0.17"

Expand Down
15 changes: 15 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extern crate protoc_rust;

fn build_protobuf<'a>(out_dir: &'a str, input: &'a [&'a str], includes: &'a [&'a str]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works fine without the 'a.

use self::protoc_rust::{run, Args};
run(Args {
out_dir,
input,
includes,
}).expect("protoc");
}

fn main() {
#[cfg(feature = "serialization-protobuf")]
build_protobuf("src/proto", &["protobuf/proof.proto"], &[]);
}
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
Loading