Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 646c326

Browse files
authored
Merge pull request #203 from NilFoundation/202-blueprint-to-nix
Blueprint flake
2 parents f9ee41f + bdd8c9d commit 646c326

File tree

3 files changed

+155
-64
lines changed

3 files changed

+155
-64
lines changed

.github/workflows/run_tests.yml

Lines changed: 41 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,57 +11,11 @@ on:
1111
env:
1212
SUITE_REPO: "NilFoundation/crypto3"
1313
LIB_NAME: "blueprint"
14-
CACHE_NAME: "checkout-job-cache"
14+
CACHE_NAME: "blueprint-job-cache"
1515

1616
jobs:
17-
checkout:
18-
runs-on: [self-hosted, tests-runner]
19-
steps:
20-
- name: Cleanup # TODO - move to scripts on runner
21-
run: |
22-
rm -rf ./* || true
23-
rm -rf ./.??* || true
24-
25-
- name: Checkout suite
26-
uses: actions/checkout@v3
27-
with:
28-
repository: ${{ env.SUITE_REPO }}
29-
submodules: recursive
30-
31-
- name: Checkout source code
32-
uses: actions/checkout@v3
33-
with:
34-
path: ./libs/${{ env.LIB_NAME }}
35-
submodules: recursive
36-
37-
- name: Cmake and build
38-
env:
39-
CMAKE_ARGS: "
40-
-DCMAKE_BUILD_TYPE=Debug
41-
-DBUILD_SHARED_LIBS=FALSE
42-
-DBUILD_TESTS=TRUE
43-
"
44-
run: |
45-
mkdir build
46-
cd build
47-
cmake ${{ env.CMAKE_ARGS }} ..
48-
49-
- name: Archive build results
50-
run: |
51-
touch ${{ env.CACHE_NAME }}.tar.gz
52-
tar -czf ${{ env.CACHE_NAME }}.tar.gz --exclude=${{ env.CACHE_NAME }}.tar.gz .
53-
54-
- name: Cache archived job output
55-
uses: actions/upload-artifact@v3
56-
with:
57-
name: ${{ env.CACHE_NAME }}
58-
path: ${{ env.CACHE_NAME }}.tar.gz
59-
retention-days: 1
60-
61-
6217
run_tests:
63-
runs-on: [self-hosted]
64-
needs: [checkout]
18+
runs-on: ubuntu-latest
6519
strategy:
6620
fail-fast: false
6721
matrix:
@@ -101,29 +55,52 @@ jobs:
10155
blueprint_algebra_fields_plonk_sqrt_test,
10256
] # Tests to execute
10357
steps:
104-
- name: Cleanup # TODO - move to scripts on runner
105-
run: |
106-
rm -rf ./* || true
107-
rm -rf ./.??* || true
58+
- uses: cachix/install-nix-action@v23
59+
- uses: DeterminateSystems/magic-nix-cache-action@main
60+
- uses: DeterminateSystems/nix-installer-action@main
10861

109-
- name: Upload checkout job cache
110-
uses: actions/download-artifact@v3
62+
- name: Checkout suite
63+
uses: actions/checkout@v3
11164
with:
112-
name: ${{ env.CACHE_NAME }}
65+
repository: ${{ env.SUITE_REPO }}
66+
submodules: recursive
67+
fetch-depth: 0
11368

114-
- name: Extract artifacts
69+
- name: Checkout source code
70+
uses: actions/checkout@v3
71+
with:
72+
path: ./libs/${{ env.LIB_NAME }}
73+
submodules: recursive
74+
fetch-depth: 0
75+
76+
- name: Configure Nix
77+
run: |
78+
mkdir -p ~/.config/nix
79+
echo "extra-experimental-features = nix-command flakes" > ~/.config/nix/nix.conf
80+
81+
- name: Cmake and build
82+
env:
83+
CMAKE_ARGS: "
84+
-DCMAKE_CXX_STANDARD=17
85+
-DCMAKE_BUILD_TYPE=Debug
86+
-DBUILD_SHARED_LIBS=TRUE
87+
-DBUILD_TESTS=TRUE
88+
-DCMAKE_C_COMPILER=clang
89+
-DCMAKE_CXX_COMPILER=clang++
90+
"
11591
run: |
116-
tar -xf ${{ env.CACHE_NAME }}.tar.gz
117-
rm ${{ env.CACHE_NAME }}.tar.gz
92+
mkdir build
93+
nix develop ./libs/blueprint -c cmake -B build ${{ env.CMAKE_ARGS }} .
11894
11995
- name: Build
12096
working-directory: ./build
121-
run: cmake --build . -t ${{ matrix.target }}
97+
run: nix develop ../libs/blueprint -c cmake --build . -t ${{ matrix.target }}
12298

12399
- name: Run test
124100
working-directory: ./build
125-
run: |
126-
cd libs/${{ env.LIB_NAME }}/test
127-
COLOR='\033[0;33m'
128-
echo -e "${COLOR}${{ matrix.target }}"
129-
./${{ matrix.target }}
101+
run:
102+
nix develop ../libs/blueprint -c bash -c "
103+
cd libs/${{ env.LIB_NAME }}/test &&
104+
COLOR='\033[0;33m' &&
105+
echo -e "${COLOR}${{ matrix.target }}" &&
106+
./${{ matrix.target }}"

flake.lock

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
description = "Blueprint circuits library.";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs";
6+
};
7+
8+
outputs = { self, nixpkgs }:
9+
let
10+
revCount = self.revCount or 1;
11+
package_version = "0.1.0-${toString revCount}";
12+
13+
# Systems supported
14+
allSystems = [
15+
"x86_64-linux" # 64-bit Intel/AMD Linux
16+
"aarch64-linux" # 64-bit ARM Linux
17+
"x86_64-darwin" # 64-bit Intel macOS
18+
"aarch64-darwin" # 64-bit ARM macOS
19+
];
20+
21+
forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
22+
pkgs = import nixpkgs { inherit system; };
23+
});
24+
25+
26+
make_package = pkgs: with pkgs;
27+
let
28+
stdenv = pkgs.llvmPackages_16.stdenv;
29+
in
30+
stdenv.mkDerivation {
31+
name = "blueprint_circuits";
32+
src = self;
33+
dontFixCmake = true;
34+
env.CXXFLAGS = toString([
35+
"-fPIC"
36+
]);
37+
env.NIX_CFLAGS_COMPILE = toString([
38+
"-Wno-unused-but-set-variable"
39+
]);
40+
nativeBuildInputs = [
41+
cmake
42+
boost
43+
pkg-config
44+
clang-tools_16
45+
clang_16
46+
];
47+
cmakeFlags = [
48+
"-DCMAKE_CXX_STANDARD=17"
49+
"-DBUILD_SHARED_LIBS=TRUE"
50+
"-DBUILD_TESTS=TRUE"
51+
"-DBUILD_EXAMPLES=TRUE"
52+
"-DCMAKE_BUILD_TYPE=Debug"
53+
"-DCMAKE_CXX_COMPILER=clang++"
54+
"-DCMAKE_C_COMPILER=clang"
55+
];
56+
};
57+
in
58+
{
59+
packages = forAllSystems({ pkgs }: {
60+
blueprint_circuits = make_package pkgs;
61+
default = make_package pkgs;
62+
63+
devShell.x86_64-linux = pkgs.mkShell {
64+
buildInputs = [
65+
make_package pkgs
66+
];
67+
};
68+
69+
devShell.aarch64-linux = pkgs.mkShell {
70+
buildInputs = [
71+
make_package pkgs
72+
];
73+
};
74+
75+
devShell.x86_64-darwin = pkgs.mkShell {
76+
buildInputs = [
77+
make_package pkgs
78+
];
79+
};
80+
81+
devShell.aarch64-darwin = pkgs.mkShell {
82+
buildInputs = [
83+
make_package pkgs
84+
];
85+
};
86+
});
87+
};
88+
}

0 commit comments

Comments
 (0)