forked from hacl-star/hacl-star
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefault.nix
172 lines (152 loc) · 4.64 KB
/
default.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
{ dotnet-runtime, dune_3, enableParallelBuilding ? true, fstar, git, karamel
, nodePackages, nodejs, ocamlPackages, openssl, python3, stdenv, time, vale
, which, writeTextFile, z3, }:
let
hacl = stdenv.mkDerivation {
name = "hacl-star";
src = ./.;
postPatch = ''
patchShebangs tools
patchShebangs dist/configure
patchShebangs dist/package-mozilla.sh
substituteInPlace Makefile --replace "NOSHORTLOG=1" ""
echo "0.3.19" > vale/.vale_version
'';
nativeBuildInputs = [
z3
fstar
python3
which
dotnet-runtime
time
nodejs
nodePackages.jsdoc
dune_3
] ++ (with ocamlPackages; [
ocaml
findlib
batteries
pprint
stdint
yojson
zarith
ppxlib
ppx_deriving
ppx_deriving_yojson
ctypes
cppo
odoc
alcotest
qcheck-core
secp256k1-internal
]);
buildInputs = [ openssl.dev ];
VALE_HOME = vale;
FSTAR_HOME = fstar;
KRML_HOME = karamel;
configurePhase = ''
export HACL_HOME=$(pwd)
export OCAMLPATH=$HACL_HOME/dist:$OCAMLPATH
export OCAMLFIND_OPTS="-destdir $HACL_HOME/dist"
export LD_LIBRARY_PATH=$HACL_HOME/dist/hacl-star-raw
'';
inherit enableParallelBuilding;
buildPhase = ''
rm -rf dist/*/*
make -j$NIX_BUILD_CORES ci 2>&1 | tee log.txt
'';
installPhase = ''
cp -r ./. $out
'';
dontFixup = true;
passthru = rec {
info = writeTextFile {
name = "INFO.txt";
text = ''
This code was generated with the following toolchain.
F* version: ${fstar.version}
Karamel version: ${karamel.version}
Vale version: ${vale.version}
'';
};
dist-compare = stdenv.mkDerivation {
name = "hacl-diff-compare";
src = "${hacl.build-products}/dist.tar";
phases = [ "unpackPhase" "buildPhase" "installPhase" ];
buildPhase = ''
for file in ./*/*.c ./*/*.h
do
if ! diff $file ${hacl.src}/dist/$file 2>&1 > /dev/null
then
echo "*** $file"
diff -y --suppress-common-lines $file ${hacl.src}/dist/$file || true
fi
done
'';
installPhase = ''
touch $out
'';
};
dist-list = stdenv.mkDerivation {
name = "hacl-diff-list";
src = "${hacl.build-products}/dist.tar";
phases = [ "unpackPhase" "buildPhase" "installPhase" ];
buildPhase = ''
diff -rq . ${hacl.src}/dist 2>&1 \
| sed 's/\/nix\/store\/[a-z0-9]\{32\}-//g' \
| sed 's/^Files \([^ ]*\).*/\1/' \
| sed 's/^Only in source\/dist\([^\:]*\)\: \(.*\)/\.\1\/\2/' \
| sed 's/^Only in \.\([^\:]*\)\: \(.*\)/\.\1\/\2/' \
| grep '\.\/[^\/]*\/' \
| grep -v INFO.txt
'';
installPhase = ''
touch $out
'';
};
build-products = stdenv.mkDerivation {
name = "hacl-build-products";
src = hacl;
buildInputs = [ git ];
buildPhase = ''
rm -r dist/hacl-star-raw
sed -i 's/\#\!.*/\#\!\/usr\/bin\/env bash/' dist/configure
sed -i 's/\#\!.*/\#\!\/usr\/bin\/env bash/' dist/package-mozilla.sh
for target in gcc-compatible msvc-compatible portable-gcc-compatible
do
sed -i 's/\#\!.*/\#\!\/usr\/bin\/env bash/' dist/$target/configure
done
for target in gcc-compatible mozilla msvc-compatible portable-gcc-compatible wasm
do
cp ${info} dist/$target/INFO.txt
done
git init
git config --local user.name "John Doe"
git config --local user.email [email protected]
git add *
git commit -m "initial commit"
git archive HEAD hints > hints.tar
git archive HEAD dist/* > dist.tar
'';
installPhase = ''
mkdir -p $out/nix-support
cp hints.tar dist.tar $out
echo "file hints $out/hints.tar" >> $out/nix-support/hydra-build-products
echo "file dist $out/dist.tar" >> $out/nix-support/hydra-build-products
'';
};
stats = stdenv.mkDerivation {
name = "hacl-stats";
phases = [ "installPhase" ];
installPhase = ''
mkdir -p $out/nix-support
echo "file stats $out/stats.txt" >> $out/nix-support/hydra-build-products
cat ${hacl}/log.txt \
| grep "^\[VERIFY\]" \
| sed 's/\[VERIFY\] \(.*\), \(.*\)/\2 \1/' \
| sort -rg - > $out/stats.txt
'';
};
};
};
in hacl