-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
154 lines (143 loc) · 4.8 KB
/
flake.nix
File metadata and controls
154 lines (143 loc) · 4.8 KB
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
{
description = "StarMalloc";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
fstar-src = {
url = "github:FStarLang/FStar";
inputs.nixpkgs.follows = "nixpkgs";
};
steel-src = {
url = "github:FStarLang/steel";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "fstar-src/flake-utils";
inputs.fstar.follows = "fstar-src";
};
krml-src = {
url = "github:FStarLang/karamel";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "fstar-src/flake-utils";
inputs.fstar.follows = "fstar-src";
};
};
outputs = inputs@{self, nixpkgs, fstar-src, krml-src, steel-src}:
let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
inherit (pkgs) lib;
z3 = fstar-src.packages.${system}.z3;
fstar = fstar-src.packages.${system}.fstar;
steel = steel-src.packages.${system}.steel;
karamel = krml-src.packages.${system}.karamel.home;
# light build: no verification involved, only compile C files
starmalloc-light = pkgs.stdenv.mkDerivation {
name = "StarMalloc (light build)";
src = lib.sourceByRegex ./. [
"dist(/.*)?"
"vendor(/.*)?"
"c(/.*)?"
"Makefile.include"
"Makefile"
];
enableParallelBuilding = true;
buildInputs = [ ];
# TODO: unaesthetic workaround, could this be improved?
STEEL_HOME = 1;
KRML_HOME = 1;
# use vendored files, as this would require Steel and KaRaMeL
VENDOR = 1;
# skip F* dependency check, as this would require F*
NODEPEND = 1;
installPhase = "mkdir $out && cp -r dist out/*.so $out";
buildFlags = [ "debug_light" "light" ];
};
# full build: verify, extract and compile
starmalloc = pkgs.stdenv.mkDerivation {
name = "StarMalloc (full build)";
src = lib.sourceByRegex ./. [
"lib_avl_common(/.*)?"
"lib_avl_mono(/.*)?"
"lib_bitmap(/.*)?"
"lib_list(/.*)?"
"lib_misc(/.*)?"
"lib_ringbuffer(/.*)?"
"src(/.*)?"
"vendor(/.*)?"
"c(/.*)?"
"Makefile.include"
"Makefile"
"spdx-header.txt"
];
enableParallelBuilding = true;
buildInputs = [ fstar steel karamel ];
STEEL_HOME = steel;
KRML_HOME = karamel;
installPhase = "mkdir $out && cp -r dist out/*.so $out";
buildFlags = [ "debug_lib" "lib" ];
};
# check whether dist/ is up-to-date
check-dist = pkgs.stdenv.mkDerivation {
name = "StarMalloc (dist/ check)";
src = lib.sourceByRegex ./. [
"dist(/.*)?"
];
buildInputs = [ starmalloc ];
installPhase = ''
if [[ -z $(diff -qr dist ${starmalloc}/dist) ]]; then
mkdir $out
else
diff --color=always -Naur dist ${starmalloc}/dist
exit 1
fi
'';
};
# check whether vendor/ is up-to-date
check-vendor = pkgs.stdenv.mkDerivation {
name = "StarMalloc (vendor/ check)";
src = lib.sourceByRegex ./. [
"vendor(/.*)?"
];
buildInputs = [ steel karamel ];
STEEL_HOME = steel;
KRML_HOME = karamel;
installPhase = ''
# Steel
mkdir -p temp_vendor/steel
mkdir -p temp_vendor/steel/include
cp -r $STEEL_HOME/include/steel/ temp_vendor/steel/include/steel/
mkdir -p temp_vendor/steel/src
cp -r $STEEL_HOME/src/c/ temp_vendor/steel/src/c/
# KaRaMeL
mkdir -p temp_vendor/karamel
cp -r $KRML_HOME/include temp_vendor/karamel/include
mkdir -p temp_vendor/karamel/krmllib/dist
cp -r $KRML_HOME/krmllib/dist/minimal temp_vendor/karamel/krmllib/dist/minimal
if [[ -z $(diff -qr vendor temp_vendor) ]]; then
mkdir $out
else
diff --color=always -Naur vendor temp_vendor
exit 1
fi
'';
};
# fast full build: extract and compile (verification is very light: SMT queries are admitted)
starmalloc-admit-smt = starmalloc.overrideAttrs (finalAttrs: previousAttrs: {
name = "StarMalloc (admit SMT queries build)";
OTHERFLAGS = "--admit_smt_queries true";
});
# check whether verification is stable
starmalloc-quake = starmalloc.overrideAttrs (finalAttrs: previousAttrs: {
name = "StarMalloc (stability check build)";
OTHERFLAGS = "--quake 5/5";
});
in
{
packages.${system} = {
inherit
starmalloc-light
starmalloc
starmalloc-admit-smt starmalloc-quake
check-dist check-vendor;
default=starmalloc;
};
};
}