Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
fix: utilize nix for clippy/test/fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kobyhallx committed Aug 2, 2023
1 parent 1d226b2 commit 451933f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 35 deletions.
66 changes: 40 additions & 26 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,23 @@ name: Rust
on: [push, pull_request]

jobs:
barretenberg-job:
runs-on: ubuntu-latest
clippy-n-test:
name: Test on ${{ matrix.os }}
runs-on: ${{ matrix.runner }}
timeout-minutes: 30

strategy:
fail-fast: false
matrix:
include:
- os: ubuntu
runner: ubuntu-latest
target: x86_64-linux

steps:
- name: Checkout
uses: actions/checkout@v3

- uses: cachix/install-nix-action@v22
with:
nix_path: nixpkgs=channel:nixos-22.11
Expand All @@ -15,28 +29,28 @@ jobs:
with:
name: barretenberg

- name: Checkout sources
uses: actions/checkout@v3

# barretenberg#wasm32 is needed by acvm_js crate so we need to build it first
# and ensure it's in $workspace_root/acvm_js/result/bin
# so acvm_js build.rs script can pick it up
- name: Run `nix build bb`
working-directory: ./acvm_js
- name: Restore nix store cache
id: nix-store-cache
uses: actions/cache@v3
with:
path: /tmp/nix-cache
key: ${{ runner.os }}-flake-${{ hashFiles('*.lock') }}

# Based on https://github.com/marigold-dev/deku/blob/b5016f0cf4bf6ac48db9111b70dd7fb49b969dfd/.github/workflows/build.yml#L26
- name: Copy cache into nix store
if: steps.nix-store-cache.outputs.cache-hit == 'true'
# We don't check the signature because we're the one that created the cache
run: |
for narinfo in /tmp/nix-cache/*.narinfo; do
path=$(head -n 1 "$narinfo" | awk '{print $2}')
nix copy --no-check-sigs --from "file:///tmp/nix-cache" "$path"
done
- name: Run `nix flake check`
run: |
nix flake check -L
- name: Export cache from nix store
if: steps.nix-store-cache.outputs.cache-hit != 'true'
run: |
nix build -L "github:AztecProtocol/barretenberg?rev=65e651d04c6092cb5ca079cd9e12ed9b5846fa3a#wasm32"
check_n_test:
needs: barretenberg-job
name: cargo check & test
uses: noir-lang/.github/.github/workflows/rust-test.yml@main

clippy:
needs: barretenberg-job
name: cargo clippy
uses: noir-lang/.github/.github/workflows/rust-clippy.yml@main

format:
needs: barretenberg-job
name: cargo fmt
uses: noir-lang/.github/.github/workflows/rust-format.yml@main
nix copy --to "file:///tmp/nix-cache?compression=zstd&parallel-compression=true" .#native-cargo-artifacts
37 changes: 28 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,18 @@
cargoToml = ./acvm_js/Cargo.toml;
};

crateACVMDefinitions = craneLib.crateNameFromCargoToml {
cargoToml = ./acvm/Cargo.toml;
};


sharedEnvironment = {
# Barretenberg fails if tests are run on multiple threads, so we set the test thread
# count to 1 throughout the entire project
#
# Note: Setting this allows for consistent behavior across build and shells, but is mostly
# hidden from the developer - i.e. when they see the command being run via `nix flake check`
RUST_TEST_THREADS = "1";
# RUST_TEST_THREADS = "1";
BARRETENBERG_BIN_DIR = "${pkgs.barretenberg-wasm}/bin";
};

Expand All @@ -99,17 +104,16 @@
GIT_DIRTY = if (self ? rev) then "false" else "true";

commonArgs = {

inherit (crateACVMDefinitions) pname version;
src = pkgs.lib.cleanSourceWith {
src = craneLib.path {
path = ./.;
# name = "acvm_js";
};
filter = sourceFilter;
};

# cargoClippyExtraArgs = "--package acvm_js --all-targets -- -D warnings";
# cargoTestExtraArgs = "--workspace";
cargoClippyExtraArgs = "--package acvm_js --all-targets -- -D warnings";
cargoTestExtraArgs = "--workspace";

# We don't want to run checks or tests when just building the project
doCheck = false;
Expand All @@ -131,7 +135,7 @@
};

# Build *just* the cargo dependencies, so we can reuse all of that work between runs
cargoArtifacts = craneLib.buildDepsOnly acvmjsWasmArgs;
cargoArtifacts = craneLib.buildDepsOnly commonArgs;

wasm-bindgen-cli = pkgs.callPackage ./acvm_js/nix/wasm-bindgen-cli/default.nix {
rustPlatform = pkgs.makeRustPlatform {
Expand All @@ -143,13 +147,28 @@
in
rec {
checks = {
cargo-clippy = craneLib.cargoClippy (acvmjsWasmArgs // {
inherit cargoArtifacts
;

cargo-clippy = craneLib.cargoClippy (commonArgs // sharedEnvironment // {
inherit GIT_COMMIT GIT_DIRTY;

cargoArtifacts = cargoArtifacts;
doCheck = true;
});

cargo-test = craneLib.cargoTest (commonArgs // sharedEnvironment // {
inherit GIT_COMMIT GIT_DIRTY;

cargoArtifacts = cargoArtifacts;
doCheck = true;
});

cargo-fmt = craneLib.cargoFmt (commonArgs // sharedEnvironment // {
inherit GIT_COMMIT GIT_DIRTY;

cargoArtifacts = cargoArtifacts;
doCheck = true;
});

};

packages.default = craneLib.mkCargoDerivation (acvmjsWasmArgs // rec {
Expand Down

0 comments on commit 451933f

Please sign in to comment.