Skip to content

Commit

Permalink
Merge pull request zcash#100 from filecoin-project/better-ci
Browse files Browse the repository at this point in the history
chore(ci): switch to custom docker image + better clippy config
  • Loading branch information
dignifiedquire authored Jul 26, 2018
2 parents 90b8139 + c349e42 commit 55b3cfb
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 141 deletions.
59 changes: 18 additions & 41 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,38 @@ version: 2
jobs:
cargo_fetch:
docker:
- image: rust:latest
- image: dignifiedquire/rust:latest
working_directory: /mnt/crate
steps:
- checkout
- restore_cache:
keys:
- cargo-v1-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
- cargo-v3-{{ checksum "Cargo.toml" }}
- run: cargo update
- run: cargo fetch
- persist_to_workspace:
root: "."
paths:
- Cargo.lock
- save_cache:
key: cargo-v1-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
key: cargo-v3-{{ checksum "Cargo.toml" }}
paths:
- /usr/local/cargo/registry
- /usr/local/cargo/git
- /root/.cargo
- /root/.rustup
test:
docker:
- image: rust:latest
- image: dignifiedquire/rust:latest
working_directory: /mnt/crate
steps:
- checkout
- attach_workspace:
at: "."
- restore_cache:
keys:
- cargo-v1-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
- run:
name: Print version information
command: rustc --version; cargo --version
- cargo-v3-{{ checksum "Cargo.toml" }}
- run:
name: Build and test
command: cargo test --verbose --frozen
command: cargo +stable test --verbose --frozen
- run:
name: Prune the output files
command: |
Expand All @@ -50,78 +47,58 @@ jobs:
- target/debug/*
test_release:
docker:
- image: rust:latest
- image: dignifiedquire/rust:latest
working_directory: /mnt/crate
steps:
- checkout
- attach_workspace:
at: "."
- restore_cache:
keys:
- cargo-v1-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
- run:
name: Print version information
command: rustc --version; cargo --version
- cargo-v3-{{ checksum "Cargo.toml" }}
- run:
name: Build and test in release profile
command: cargo test --verbose --frozen --release
command: cargo +stable test --verbose --release --frozen
test_nightly:
docker:
- image: rustlang/rust:nightly
- image: dignifiedquire/rust:latest
working_directory: /mnt/crate
steps:
- checkout
- attach_workspace:
at: "."
- restore_cache:
keys:
- cargo-v1-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
- run:
name: Print version information
command: rustc --version; cargo --version
- cargo-v3-{{ checksum "Cargo.toml" }}
- run:
name: Build and test with nightly Rust
command: cargo test --verbose --frozen
command: cargo +nightly test --verbose --frozen
rustfmt:
docker:
- image: rustlang/rust:nightly
- image: dignifiedquire/rust:latest
working_directory: /mnt/crate
steps:
- checkout
- attach_workspace:
at: "."
- restore_cache:
keys:
- cargo-v1-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
- run:
name: Print version information
command: rustc --version; cargo --version
- run:
name: Install rustfmt-nightly
# this is not cheap, but I did not find a better way
command: cargo install rustfmt-nightly --version=0.8.3 --force
- cargo-v3-{{ checksum "Cargo.toml" }}
- run:
name: Run cargo fmt
command: cargo fmt -- --check

clippy:
docker:
- image: rustlang/rust:nightly
- image: dignifiedquire/rust:latest
working_directory: /mnt/crate
steps:
- checkout
- attach_workspace:
at: "."
- restore_cache:
keys:
- cargo-v1-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
- run:
name: Print version information
command: rustc --version; cargo --version
- run:
name: Install clippy
# this is not cheap, but I did not find a better way
command: cargo install clippy --force
- cargo-v3-{{ checksum "Cargo.toml" }}
- run:
name: Run cargo clippy
command: cargo clippy
Expand Down
30 changes: 30 additions & 0 deletions Dockerfile-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Dockerfile for CircleCI
# build with
# `docker build -t dignfiedquire/rust:latest -f ./Dockerfile-ci .`

FROM debian:stretch

# Some of the dependencies I need to build a few libraries,
# personalize to your needs. You can use multi-stage builds
# to produce a lightweight image.
RUN apt-get update && \
apt-get install -y curl file gcc g++ git make openssh-client \
autoconf automake cmake libtool libcurl4-openssl-dev libssl-dev \
libelf-dev libdw-dev binutils-dev zlib1g-dev libiberty-dev wget \
xz-utils pkg-config python

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y

ENV PATH "$PATH:/root/.cargo/bin"
ENV RUSTFLAGS "-C link-dead-code"
ENV CFG_RELEASE_CHANNEL "nightly"

RUN rustup update && \
rustup install nightly && \
rustup default nightly && \
rustup component add rustfmt-preview && \
rustup component add clippy-preview

RUN bash -l -c 'echo $(rustc --print sysroot)/lib >> /etc/ld.so.conf'
RUN bash -l -c 'echo /usr/local/lib >> /etc/ld.so.conf'
RUN ldconfig
72 changes: 30 additions & 42 deletions examples/drgporep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,25 @@ impl DrgPoRepApp {
lambda: usize,
m: usize,
) -> BenchCS<Bls12> {
let (
prover_id,
replica_node,
replica_node_path,
replica_root,
replica_parents,
replica_parents_paths,
data_node,
data_node_path,
data_root,
) = fake_drgpoprep_proof(rng, tree_depth, m, SLOTH_ROUNDS);

let prover_bytes = fr_into_bytes::<Bls12>(&prover_id);
let f = fake_drgpoprep_proof(rng, tree_depth, m, SLOTH_ROUNDS);

let prover_bytes = fr_into_bytes::<Bls12>(&f.prover_id);
// create an instance of our circut (with the witness)
let c = DrgPoRepExample {
params: engine_params,
lambda: lambda * 8,
replica_node: Some(&replica_node),
replica_node_path: &replica_node_path,
replica_root: Some(replica_root),
replica_parents: replica_parents.iter().map(|parent| Some(parent)).collect(),
replica_parents_paths: &replica_parents_paths,
data_node: Some(&data_node),
data_node_path: data_node_path.clone(),
data_root: Some(data_root),
replica_node: Some(&f.replica_node),
replica_node_path: &f.replica_node_path,
replica_root: Some(f.replica_root),
replica_parents: f
.replica_parents
.iter()
.map(|parent| Some(parent))
.collect(),
replica_parents_paths: &f.replica_parents_paths,
data_node: Some(&f.data_node),
data_node_path: f.data_node_path.clone(),
data_root: Some(f.data_root),
prover_id: Some(prover_bytes.as_slice()),
m,
};
Expand Down Expand Up @@ -155,32 +149,26 @@ impl Example<Bls12> for DrgPoRepApp {
lambda: usize,
m: usize,
) -> Proof<Bls12> {
let (
prover_id,
replica_node,
replica_node_path,
replica_root,
replica_parents,
replica_parents_paths,
data_node,
data_node_path,
data_root,
) = fake_drgpoprep_proof(rng, tree_depth, m, SLOTH_ROUNDS);

let prover_bytes = fr_into_bytes::<Bls12>(&prover_id);
let f = fake_drgpoprep_proof(rng, tree_depth, m, SLOTH_ROUNDS);

let prover_bytes = fr_into_bytes::<Bls12>(&f.prover_id);

// create an instance of our circut (with the witness)
let c = DrgPoRepExample {
params: engine_params,
lambda: lambda * 8,
replica_node: Some(&replica_node),
replica_node_path: &replica_node_path,
replica_root: Some(replica_root),
replica_parents: replica_parents.iter().map(|parent| Some(parent)).collect(),
replica_parents_paths: &replica_parents_paths,
data_node: Some(&data_node),
data_node_path: data_node_path.clone(),
data_root: Some(data_root),
replica_node: Some(&f.replica_node),
replica_node_path: &f.replica_node_path,
replica_root: Some(f.replica_root),
replica_parents: f
.replica_parents
.iter()
.map(|parent| Some(parent))
.collect(),
replica_parents_paths: &f.replica_parents_paths,
data_node: Some(&f.data_node),
data_node_path: f.data_node_path.clone(),
data_root: Some(f.data_root),
prover_id: Some(prover_bytes.as_slice()),
m,
};
Expand Down
15 changes: 11 additions & 4 deletions src/circuit/bench/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fn eval_lc<E: Engine>(terms: &[(Variable, E::Fr)], inputs: &[E::Fr], aux: &[E::F
acc
}

#[derive(Debug)]
pub struct BenchCS<E: Engine> {
inputs: Vec<E::Fr>,
aux: Vec<E::Fr>,
Expand All @@ -57,6 +58,16 @@ pub struct BenchCS<E: Engine> {

impl<E: Engine> BenchCS<E> {
pub fn new() -> Self {
BenchCS::default()
}

pub fn num_constraints(&self) -> usize {
self.a.len()
}
}

impl<E: Engine> Default for BenchCS<E> {
fn default() -> Self {
BenchCS {
inputs: vec![E::Fr::one()],
aux: vec![],
Expand All @@ -65,10 +76,6 @@ impl<E: Engine> BenchCS<E> {
c: vec![],
}
}

pub fn num_constraints(&self) -> usize {
self.a.len()
}
}

impl<E: Engine> ConstraintSystem<E> for BenchCS<E> {
Expand Down
35 changes: 13 additions & 22 deletions src/drgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,21 @@ pub fn hash_leaf(data: &Hashable<TreeAlgorithm>) -> TreeHash {
let mut a = TreeAlgorithm::default();
data.hash(&mut a);
let item_hash = a.hash();
let leaf_hash = a.leaf(item_hash);

leaf_hash
a.leaf(item_hash)
}

pub fn hash_node(data: &Hashable<TreeAlgorithm>) -> TreeHash {
let mut a = TreeAlgorithm::default();
data.hash(&mut a);
let item_hash = a.hash();

item_hash
a.hash()
}

pub fn make_proof_for_test(
root: TreeHash,
leaf: TreeHash,
path: Vec<(TreeHash, bool)>,
) -> MerkleProof {
MerkleProof {
path: path,
root: root,
leaf: leaf,
}
MerkleProof { path, root, leaf }
}

impl MerkleProof {
Expand Down Expand Up @@ -91,19 +83,18 @@ impl MerkleProof {
return false;
}

self.root()
== (0..self.path.len()).fold(self.leaf, |h, i| {
a.reset();
let is_right = self.path[i].1;
self.root() == (0..self.path.len()).fold(self.leaf, |h, i| {
a.reset();
let is_right = self.path[i].1;

let (left, right) = if is_right {
(self.path[i].0, h)
} else {
(h, self.path[i].0)
};
let (left, right) = if is_right {
(self.path[i].0, h)
} else {
(h, self.path[i].0)
};

a.node(left, right, i)
})
a.node(left, right, i)
})
}

/// Validates that the data hashes to the leaf of the merkle path.
Expand Down
3 changes: 1 addition & 2 deletions src/example_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ fn prettyb(num: usize) -> String {
);
let pretty_bytes = format!("{:.2}", num / delimiter.powi(exponent))
.parse::<f64>()
.unwrap()
* 1_f64;
.unwrap() * 1_f64;
let unit = units[exponent as usize];
format!("{}{} {}", negative, pretty_bytes, unit)
}
Expand Down
Loading

0 comments on commit 55b3cfb

Please sign in to comment.