forked from NilFoundation/crypto3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
251 lines (229 loc) · 9.28 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
{
description = "Nix flake for Crypto3 header-only C++ library by =nil; Foundation";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
nix-3rdparty = {
url = "github:NilFoundation/nix-3rdparty";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
};
outputs = { self
, nixpkgs
, nix-3rdparty
, ... }:
let
supportedSystems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
makeCrypto3Derivation = { system }:
let
pkgs = import nixpkgs {
overlays = [ nix-3rdparty.overlays.${system}.default ];
inherit system;
};
in
pkgs.stdenv.mkDerivation {
name = "Crypto3";
src = self;
nativeBuildInputs = with pkgs; [
cmake
cmake_modules
ninja
pkg-config
];
propagatedBuildInputs = with pkgs; [
boost183
];
cmakeFlags = [
"-B build"
"-G Ninja"
"-DCMAKE_INSTALL_PREFIX=${placeholder "out"}"
];
dontBuild = true; # nothing to build, header-only lib
doCheck = false; # tests are inside crypto3-tests derivation
installPhase = ''
cmake --build build --target install
'';
};
makeCrypto3Shell = { system }:
let
pkgs = import nixpkgs {
overlays = [ nix-3rdparty.overlays.${system}.default ];
inherit system;
};
in
pkgs.mkShell {
buildInputs = with pkgs; [
cmake
cmake_modules
ninja
clang
gcc
boost183
];
shellHook = ''
PS1="\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
echo "Welcome to Crypto3 development environment!"
'';
};
makeCrypto3Tests = { system }:
let
pkgs = import nixpkgs {
overlays = [ nix-3rdparty.overlays.${system}.default ];
inherit system;
};
isDarwin = builtins.match ".*-darwin" system != null; # Used only to exclude gcc from macOS.
testCompilers = [
"clang"
# TODO: fix gcc linkage on macOS, remove optional condition
] ++ nixpkgs.lib.optional (!isDarwin) "gcc";
# We have lots of failing tests. Modules with such tests are kept here. Built as separate targets.
brokenModuleToTestsNames = {
pubkey = [
"pubkey_ecdsa_test"
"pubkey_bls_test"
];
zk = [
"crypto3_zk_commitment_fold_polynomial_test"
"crypto3_zk_commitment_fri_test"
"crypto3_zk_commitment_lpc_test"
"crypto3_zk_systems_plonk_placeholder_placeholder_circuits_test"
"crypto3_zk_systems_plonk_placeholder_placeholder_curves_test"
"crypto3_zk_systems_plonk_placeholder_placeholder_gate_argument_test"
"crypto3_zk_systems_plonk_placeholder_placeholder_goldilocks_test"
"crypto3_zk_systems_plonk_placeholder_placeholder_hashes_test"
"crypto3_zk_systems_plonk_placeholder_placeholder_kzg_test"
"crypto3_zk_systems_plonk_placeholder_placeholder_lookup_argument_test"
"crypto3_zk_systems_plonk_placeholder_placeholder_permutation_argument_test"
"crypto3_zk_systems_plonk_placeholder_placeholder_quotient_polynomial_chunks_test"
# "crypto3_zk_commitment_powers_of_tau_test"
"crypto3_zk_commitment_proof_of_knowledge_test"
"crypto3_zk_commitment_r1cs_gg_ppzksnark_mpc_test"
"crypto3_zk_math_expression_test"
"crypto3_zk_systems_plonk_plonk_constraint_test"
];
# Everything is built successfully, just can't use regex to distinguish from other marshalling tests
# TODO: change prefix to marshalling_core inside module, move to moduleToTestsRegex
marshalling-core = [
"marshalling_processing_test"
"marshalling_interfaces_test"
"marshalling_types_test"
];
# Ditto
marshalling-zk = [
"marshalling_fri_commitment_test"
"marshalling_lpc_commitment_test"
"marshalling_placeholder_common_data_test"
"marshalling_placeholder_proof_test"
"marshalling_sparse_vector_test"
"marshalling_accumulation_vector_test"
"marshalling_plonk_constraint_system_test"
"marshalling_plonk_assignment_table_test"
"marshalling_plonk_gates_test"
"marshalling_r1cs_gg_ppzksnark_primary_input_test"
"marshalling_r1cs_gg_ppzksnark_proof_test"
"marshalling_r1cs_gg_ppzksnark_verification_key_test"
"marshalling_merkle_proof_test"
];
# Ditto
marshalling-algebra = [
"marshalling_field_element_test"
"marshalling_field_element_non_fixed_size_container_test"
"marshalling_curve_element_fixed_size_container_test"
"marshalling_curve_element_non_fixed_size_container_test"
"marshalling_curve_element_test"
];
};
# Modules with no failing tests are kept here. Built as `tests-crypto3-<module_name>` targets
moduleToTestsRegex = {
algebra = "algebra_.*_test";
containers = "crypto3_containers_.*_test";
hash = "hash_.*_test";
math = "math_.*_test";
block = "block_.*_test";
multiprecision = "multiprecision_.*_test";
};
makeTestDerivation = { name, compiler, targets ? [ ], buildTargets ? targets, testTargets ? targets }:
(makeCrypto3Derivation { inherit system; }).overrideAttrs (oldAttrs: {
name = "Crypto3-${name}-tests";
nativeBuildInputs = oldAttrs.nativeBuildInputs ++ oldAttrs.propagatedBuildInputs ++ [
(if compiler == "gcc" then pkgs.gcc else pkgs.clang)
];
propagatedBuildInputs = [];
cmakeFlags = [
"-G Ninja"
"-DCMAKE_CXX_COMPILER=${if compiler == "gcc" then "g++" else "clang++"}"
"-DCMAKE_BUILD_TYPE=Release" # TODO: change to Debug after build fix
"-DCMAKE_ENABLE_TESTS=TRUE"
];
dontBuild = false;
# working dir is already set to build dir
buildPhase = ''
cmake --build . --parallel $NIX_BUILD_CORES --target ${nixpkgs.lib.concatStringsSep " " buildTargets}
'';
doCheck = true;
checkPhase = ''
# JUNIT file without explicit file name is generated after the name of the master test suite inside `CMAKE_CURRENT_SOURCE_DIR` (/build/source)
export BOOST_TEST_LOGGER=JUNIT:HRF
ctest --verbose -j $NIX_BUILD_CORES --output-on-failure -R "${nixpkgs.lib.concatStringsSep "|" (map (target: "^" + target + "$") testTargets)}"
mkdir -p ${placeholder "out"}/test-logs
find .. -type f -name '*_test.xml' -exec cp {} ${placeholder "out"}/test-logs \;
'';
dontInstall = true;
});
compilerBrokenModuleTestsNamesPairs = pkgs.lib.cartesianProductOfSets {
compiler = testCompilers;
module = pkgs.lib.attrNames brokenModuleToTestsNames;
};
compilerModuleTestsRegexPairs = pkgs.lib.cartesianProductOfSets {
compiler = testCompilers;
module = pkgs.lib.attrNames moduleToTestsRegex;
};
in
pkgs.lib.listToAttrs (
builtins.map
(pair: {
name = "${pair.module}-${pair.compiler}";
value = makeTestDerivation {
name = pair.module;
compiler = pair.compiler;
targets = brokenModuleToTestsNames.${pair.module};
};
})
compilerBrokenModuleTestsNamesPairs
++
builtins.map
(pair: {
name = "${pair.module}-${pair.compiler}";
value = makeTestDerivation {
name = pair.module;
compiler = pair.compiler;
buildTargets = [ "tests-crypto3-${pair.module}" ];
testTargets = [ moduleToTestsRegex.${pair.module} ];
};
})
compilerModuleTestsRegexPairs
);
in
{
packages = forAllSystems (system: {
default = makeCrypto3Derivation { inherit system; };
});
checks = forAllSystems (system:
makeCrypto3Tests { inherit system; }
);
devShells = forAllSystems (system: {
default = makeCrypto3Shell { inherit system; };
});
};
}
# `nix flake -L check .?submodules=1#` to run all tests (-L to output build logs)
# `nix build -L .?submodules=1#checks.x86_64-linux.hash-clang` for partial testing
# `nix flake show` to show derivations tree
# If build fails due to OOM, run `export NIX_CONFIG="cores = 2"` to set desired parallel level