-
Notifications
You must be signed in to change notification settings - Fork 16
/
flake.nix
175 lines (167 loc) · 5.47 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
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
charon = {
url = "github:aeneasverif/charon";
inputs.nixpkgs.follows = "eurydice/nixpkgs";
};
eurydice = {
url = "github:aeneasverif/eurydice";
inputs.charon.follows = "charon";
};
fstar.follows = "eurydice/fstar";
karamel.follows = "eurydice/karamel";
hax.url = "github:hacspec/hax";
};
outputs =
inputs:
inputs.flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import inputs.nixpkgs { inherit system; };
googletest = pkgs.fetchFromGitHub {
owner = "google";
repo = "googletest";
rev = "release-1.11.0";
sha256 = "SjlJxushfry13RGA7BCjYC9oZqV4z6x8dOiHfl/wpF0=";
};
benchmark = pkgs.fetchFromGitHub {
owner = "google";
repo = "benchmark";
rev = "v1.8.4";
sha256 = "O+1ZHaNHSkKz3PlKDyI94LqiLtjyrKxjOIi8Q236/MI=";
};
json = pkgs.fetchFromGitHub {
owner = "nlohmann";
repo = "json";
rev = "v3.10.3";
sha256 = "EBzwaHyDWF8h/z3Zfq4p/n5Vpz7Ozlc3eoWDKXWv2YY=";
};
tools-environment = {
CHARON_HOME = inputs.charon.packages.${system}.default;
EURYDICE_HOME = pkgs.runCommand "eurydice-home" { } ''
mkdir -p $out
cp -r ${inputs.eurydice.packages.${system}.default}/bin/eurydice $out
cp -r ${inputs.eurydice}/include $out
'';
FSTAR_HOME = inputs.fstar.packages.${system}.default;
KRML_HOME = inputs.karamel.packages.${system}.default.home;
CHARON_REV = inputs.charon.rev;
EURYDICE_REV = inputs.eurydice.rev;
KRML_REV = inputs.karamel.rev;
FSTAR_REV = inputs.fstar.rev;
};
craneLib = inputs.crane.mkLib pkgs;
ml-kem = pkgs.callPackage
({ lib
, clang-tools
, cmake
, mold-wrapped
, ninja
, python3
, runCommand
, craneLib
, hax
, googletest
, benchmark
, json
, tools-environment
, cargoLock ? ./Cargo.lock
, checkHax ? true
, runBenchmarks ? true
}:
let
src = runCommand "libcrux-src" { } ''
cp -r ${./.} $out
chmod u+w $out
rm -f $out/Cargo.lock
cp ${cargoLock} $out/Cargo.lock
'';
cargoArtifacts = craneLib.buildDepsOnly { inherit src; };
in
craneLib.buildPackage (tools-environment // {
name = "ml-kem";
inherit src cargoArtifacts;
nativeBuildInputs = [
clang-tools
cmake
mold-wrapped
ninja
python3
] ++ lib.optional checkHax [
hax
];
buildPhase = ''
cd libcrux-ml-kem
${lib.optionalString checkHax ''
python hax.py extract
''}
bash c.sh
cd c
${lib.optionalString runBenchmarks "LIBCRUX_BENCHMARKS=1"} \
cmake \
-DFETCHCONTENT_SOURCE_DIR_GOOGLETEST=${googletest} \
-DFETCHCONTENT_SOURCE_DIR_BENCHMARK=${benchmark} \
-DFETCHCONTENT_SOURCE_DIR_JSON=${json} \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=mold" \
-DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=mold" \
-G "Ninja Multi-Config" -B build
cmake --build build --config Release
build/Release/ml_kem_test
build/Release/sha3_test
rm -rf build/_deps
'';
checkPhase = ''
build/Release/ml_kem_test
'' + lib.optionalString runBenchmarks ''
build/Release/ml_kem_bench
'';
installPhase = ''
cd ./..
cp -r . $out
'';
})
)
{
inherit
googletest benchmark json
craneLib tools-environment;
hax =
inputs.hax.packages.${system}.default;
};
in
rec {
packages = {
inherit ml-kem;
};
devShells.default = craneLib.devShell (tools-environment // {
packages = [
pkgs.clang
inputs.fstar.packages.${system}.default
];
# Can't use `inputsFrom` because the `Cargo.lock` is not tracked by git on first evaluation.
buildInputs = [
pkgs.clang-tools
pkgs.cmake
pkgs.mold-wrapped
pkgs.ninja
pkgs.python3
inputs.hax.packages.${system}.default
];
shellHook = ''
# `Cargo.lock` need to be known to git for the flake to find it.
# Note: run `cargo generate-lockfile` to generate a real
# `Cargo.lock`. Without that nix builds will error.
touch Cargo.lock
${pkgs.git}/bin/git add --intent-to-add --force Cargo.lock
${pkgs.git}/bin/git update-index --assume-unchanged Cargo.lock
'';
});
}
);
}