nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 mkCoqDerivation,
4 coq,
5 flocq,
6 MenhirLib,
7 ocamlPackages,
8 fetchpatch,
9 makeWrapper,
10 coq2html,
11 stdenv,
12 tools ? stdenv.cc,
13 version ? null,
14}:
15
16let
17
18 # https://compcert.org/man/manual002.html
19 targets = {
20 x86_64-linux = "x86_64-linux";
21 aarch64-linux = "aarch64-linux";
22 x86_64-darwin = "x86_64-macos";
23 aarch64-darwin = "aarch64-macos";
24 riscv32-linux = "rv32-linux";
25 riscv64-linux = "rv64-linux";
26 };
27
28 target =
29 targets.${stdenv.hostPlatform.system}
30 or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
31
32 menhir_20260203 = fetchpatch {
33 url = "https://github.com/AbsInt/CompCert/commit/5fd8013305ecf6fa7cd2ea5a0a6fa3ebb2bc31c5.patch";
34 hash = "sha256-0bDqGSkvJM/rdCoFa6if/pJLJ4gYx2Bkld9wJaQDQOU=";
35 };
36
37 compcert = mkCoqDerivation {
38
39 pname = "compcert";
40 owner = "AbsInt";
41
42 inherit version;
43 releaseRev = v: "v${v}";
44
45 defaultVersion =
46 let
47 case = case: out: { inherit case out; };
48 in
49 with lib.versions;
50 lib.switch coq.version [
51 (case (range "8.15" "9.1") "3.17")
52 (case (range "8.14" "8.20") "3.15")
53 (case (isEq "8.13") "3.10")
54 (case (isEq "8.12") "3.9")
55 (case (range "8.8" "8.11") "3.8")
56 ] null;
57
58 release = {
59 "3.8".sha256 = "1gzlyxvw64ca12qql3wnq3bidcx9ygsklv9grjma3ib4hvg7vnr7";
60 "3.9".sha256 = "1srcz2dqrvmbvv5cl66r34zqkm0hsbryk7gd3i9xx4slahc9zvdb";
61 "3.10".sha256 = "sha256:19rmx8r8v46101ij5myfrz60arqjy7q3ra3fb8mxqqi3c8c4l4j6";
62 "3.11".sha256 = "sha256-ZISs/ZAJVWtxp9+Sg5qV5Rss1gI9hK769GnBfawLa6A=";
63 "3.12".sha256 = "sha256-hXkQ8UnAx3k50OJGBmSm4hgrnRFCosu4+PEMrcKfmV0=";
64 "3.13".sha256 = "sha256-ZedxgEPr1ZgKIcyhQ6zD1l2xr6RDNNUYq/4ZyR6ojM4=";
65 "3.13.1".sha256 = "sha256-ldXbuzVB0Z+UVTd5S4yGSg6oRYiKbXLMmUZcQsJLcns=";
66 "3.14".sha256 = "sha256-QXJMpp/BaPiK5okHeo2rcmXENToXKjB51UqljMHTDgw=";
67 "3.15".sha256 = "sha256-QFTueGZd0hAWUj+c5GZL/AyNpfN4FuJiIzCICmwRXJ8=";
68 "3.16".sha256 = "sha256-Ep8bcSFs3Cu+lV5qgo89JJU2vh4TTq66Or0c4evo3gM=";
69 "3.17".hash = "sha256-RRc39FUe2sHQdO/ybwA3B7o31qfxcUkgah6I20i0ElE=";
70 };
71
72 strictDeps = true;
73
74 nativeBuildInputs = with ocamlPackages; [
75 makeWrapper
76 ocaml
77 findlib
78 menhir
79 coq
80 coq2html
81 ];
82 buildInputs = with ocamlPackages; [ menhirLib ];
83 propagatedBuildInputs = [
84 flocq
85 MenhirLib
86 ];
87
88 postPatch = ''
89 substituteInPlace ./configure \
90 --replace \$\{toolprefix\}ar 'ar' \
91 --replace '{toolprefix}gcc' '{toolprefix}cc'
92 '';
93
94 configurePhase = ''
95 ./configure -clightgen \
96 -prefix $out \
97 -coqdevdir $lib/lib/coq/${coq.coq-version}/user-contrib/compcert/ \
98 -toolprefix ${tools}/bin/ \
99 -use-external-Flocq \
100 -use-external-MenhirLib \
101 ${target} \
102 ''; # don't remove the \ above, the command gets appended in override below
103
104 installTargets = "documentation install";
105 installFlags = [ ]; # trust ./configure
106 preInstall = ''
107 mkdir -p $out/share/man
108 mkdir -p $man/share
109 '';
110 postInstall = ''
111 # move man into place
112 mv $out/share/man/ $man/share/
113
114 # move docs into place
115 mkdir -p $doc/share/doc/compcert
116 mv doc/html $doc/share/doc/compcert/
117
118 # wrap ccomp to undefine _FORTIFY_SOURCE; ccomp invokes cc1 which sets
119 # _FORTIFY_SOURCE=2 by default, but undefines __GNUC__ (as it should),
120 # which causes a warning in libc. this suppresses it.
121 for x in ccomp clightgen; do
122 wrapProgram $out/bin/$x --add-flags "-U_FORTIFY_SOURCE"
123 done
124 '';
125
126 outputs = [
127 "out"
128 "lib"
129 "doc"
130 "man"
131 ];
132
133 meta = {
134 description = "Formally verified C compiler";
135 homepage = "https://compcert.org";
136 license = lib.licenses.inria-compcert;
137 platforms = builtins.attrNames targets;
138 maintainers = with lib.maintainers; [
139 thoughtpolice
140 jwiegley
141 vbgl
142 ];
143 };
144 };
145 patched_compcert = compcert.overrideAttrs (o: {
146 patches =
147 with lib.versions;
148 lib.switch [ coq.version o.version ]
149 [
150 {
151 cases = [
152 (range "8.12.2" "8.13.2")
153 "3.8"
154 ];
155 out = [
156 # Support for Coq 8.12.2
157 (fetchpatch {
158 url = "https://github.com/AbsInt/CompCert/commit/06956421b4307054af221c118c5f59593c0e67b9.patch";
159 sha256 = "1f90q6j3xfvnf3z830bkd4d8526issvmdlrjlc95bfsqs78i1yrl";
160 })
161 # Support for Coq 8.13.0
162 (fetchpatch {
163 url = "https://github.com/AbsInt/CompCert/commit/0895388e7ebf9c9f3176d225107e21968919fb97.patch";
164 sha256 = "0qhkzgb2xl5kxys81pldp3mr39gd30lvr2l2wmplij319vp3xavd";
165 })
166 # Support for Coq 8.13.1
167 (fetchpatch {
168 url = "https://github.com/AbsInt/CompCert/commit/6bf310dd678285dc193798e89fc2c441d8430892.patch";
169 sha256 = "026ahhvpj5pksy90f8pnxgmhgwfqk4kwyvcf8x3dsanvz98d4pj5";
170 })
171 # Drop support for Coq < 8.9
172 (fetchpatch {
173 url = "https://github.com/AbsInt/CompCert/commit/7563a5df926a4c6fb1489a7a4c847641c8a35095.patch";
174 sha256 = "05vkslzy399r3dm6dmjs722rrajnyfa30xsyy3djl52isvn4gyfb";
175 })
176 # Support for Coq 8.13.2
177 (fetchpatch {
178 url = "https://github.com/AbsInt/CompCert/commit/48bc183167c4ce01a5c9ea86e49d60530adf7290.patch";
179 sha256 = "0j62lppfk26d1brdp3qwll2wi4gvpx1k70qivpvby5f7dpkrkax1";
180 })
181 ];
182 }
183 {
184 cases = [
185 (range "8.14" "8.15")
186 "3.10"
187 ];
188 out = [
189 # Support for Coq 8.14.1
190 (fetchpatch {
191 url = "https://github.com/AbsInt/CompCert/commit/a79f0f99831aa0b0742bf7cce459cc9353bd7cd0.patch";
192 sha256 = "sha256:0g20x8gfzvplpad9y9vr1p33k6qv6rsp691x6687v9ffvz7zsz94";
193 })
194 # Support for Coq 8.15.0
195 (fetchpatch {
196 url = "https://github.com/AbsInt/CompCert/commit/a882f78c069f7337dd9f4abff117d4df98ef38a6.patch";
197 sha256 = "sha256:16i87s608fj9ni7cvd5wrd7gicqniad7w78wi26pxdy0pacl7bjg";
198 })
199 # Support for Coq 8.15.1
200 (fetchpatch {
201 url = "https://github.com/AbsInt/CompCert/commit/10a976994d7fd30d143354c289ae735d210ccc09.patch";
202 sha256 = "sha256:0bg58gpkgxlmxzp6sg0dvybrfk0pxnm7qd6vxlrbsbm2w6wk03jv";
203 })
204 # Support for Coq 8.15.2
205 (fetchpatch {
206 url = "https://github.com/AbsInt/CompCert/commit/283a5be7296c4c0a94d863b427c77007ab875733.patch";
207 sha256 = "sha256:1s7hvb5ii3p8kkcjlzwldvk8xc3iiibxi9935qjbrh25xi6qs66k";
208 })
209 ];
210 }
211 {
212 cases = [
213 (isEq "8.16")
214 (range "3.11" "3.12")
215 ];
216 out = [
217 # Support for Coq 8.16.0
218 (fetchpatch {
219 url = "https://github.com/AbsInt/CompCert/commit/34be08a23d18d56f2dde24fd24b6dbe3bcb01ec3.patch";
220 sha256 = "sha256-a5YnftGVadVypEqrOYRRxI7YtGOEWyKnO4GqakFhvzI=";
221 })
222 # Support for Coq 8.16.1
223 (fetchpatch {
224 url = "https://github.com/AbsInt/CompCert/commit/35531503b3493cb9b0ec8a8585e84928c85b4af9.patch";
225 hash = "sha256-DvtYi/eiPUe8tA0EFTcCjJA0JjtVKceUsX4ZDM0pWkE=";
226 })
227 ];
228 }
229 {
230 cases = [
231 (range "8.15" "8.16")
232 (isEq "3.13")
233 ];
234 out = [
235 # Support for menhir 20260203
236 menhir_20260203
237 ];
238 }
239 {
240 cases = [
241 (range "8.17" "8.19")
242 (isEq "3.13")
243 ];
244 out = [
245 # Support for Coq 8.17.0 & Coq 8.17.1
246 (fetchpatch {
247 url = "https://github.com/AbsInt/CompCert/commit/2e04d986bdae578186e40330842878559a550402.patch";
248 hash = "sha256-2ZRAjUUSScJI8ogWFTnukCUnJdLWGvyOPyfIVlHL4ig=";
249 })
250 # Support for Coq 8.18.0
251 (fetchpatch {
252 url = "https://github.com/AbsInt/CompCert/commit/28218c5663cba36c6078ca342335d4e55c412bd7.patch";
253 hash = "sha256-aAatUMO26oZwFYGh1BXYWxbTuyOgU8BAKMGDS5796hM=";
254 })
255 # MenhirLib update
256 (fetchpatch {
257 url = "https://github.com/AbsInt/CompCert/commit/9f3d7b6eb99377ad4689cd57563c484c57baa457.patch";
258 hash = "sha256-paofdSBxP/JFoBSiO1OI+mjKRI3UCanXRh/drzYt93E=";
259 })
260 # Support for Coq 8.19.0 & Coq 8.19.1
261 (fetchpatch {
262 url = "https://github.com/AbsInt/CompCert/commit/a2e4ed62fc558d565366845f9d135bd7db5e23c4.patch";
263 hash = "sha256-ufk0bokuayLfkSvK3cK4E9iXU5eZpp9d/ETSa/zCfMg=";
264 })
265 # Support for Coq 8.19.2
266 (fetchpatch {
267 url = "https://github.com/AbsInt/CompCert/commit/8fcfb7d2a6e9ba44003ccab0dfcc894982779af1.patch";
268 hash = "sha256-m/kcnDBBPWFriipuGvKZUqLQU8/W1uqw8j4qfCwnTZk=";
269 })
270 # Support for menhir 20260203
271 menhir_20260203
272 ];
273 }
274 {
275 cases = [
276 (range "8.19" "8.20")
277 (isEq "3.14")
278 ];
279 out = [
280 # Support for Coq 8.19.2
281 (fetchpatch {
282 url = "https://github.com/AbsInt/CompCert/commit/8fcfb7d2a6e9ba44003ccab0dfcc894982779af1.patch";
283 hash = "sha256-m/kcnDBBPWFriipuGvKZUqLQU8/W1uqw8j4qfCwnTZk=";
284 })
285 # Support for Coq 8.20.0
286 (fetchpatch {
287 url = "https://github.com/AbsInt/CompCert/commit/20a5b48758bf8ac18e4c420df67017b371efc237.patch";
288 hash = "sha256-TJ87CvLiAv1absGnPsTXsD/HQwKgS82loUTcosulyso=";
289 })
290 # Support for Coq 8.20.1
291 (fetchpatch {
292 url = "https://github.com/AbsInt/CompCert/commit/e6c9a2d068ae67923bbc7c6b7035b6afde6ece3c.patch";
293 hash = "sha256-PtiEkG/aLRotIiqrmc6SQncQSi7IGSC5QX3e52xkOUQ=";
294 })
295 ];
296 }
297 {
298 cases = [
299 (range "8.19" "8.20")
300 (isEq "3.15")
301 ];
302 out = [
303 # Support for Coq 8.20.1
304 (fetchpatch {
305 url = "https://github.com/AbsInt/CompCert/commit/e524b0a19ae5140f64047b1cba6ebbe1d16d5bbf.patch";
306 hash = "sha256-24kt0hA75ooyXymH+kNS5VlsuXMHbkqTw4m+BzNUwrw=";
307 })
308 # Support for menhir 20260203
309 menhir_20260203
310 ];
311 }
312 {
313 cases = [
314 (isEq "9.0")
315 (isEq "3.16")
316 ];
317 out = [
318 # Support for Coq 9.0.1
319 (fetchpatch {
320 url = "https://github.com/AbsInt/CompCert/commit/a962ef9da0fb4ef2a4314ccedd111eb248e42cf2.patch";
321 hash = "sha256-ipYqcfcgz3cKyI1NGSgfOgiVdV1WUwlv6DVB1S1hJvw=";
322 })
323 ];
324 }
325 {
326 cases = [
327 (isGe "9.0")
328 (isEq "3.17")
329 ];
330 out = [
331 # Support for Coq 9.0.1 & Coq 9.1.1
332 (fetchpatch {
333 url = "https://github.com/AbsInt/CompCert/commit/6e5d40fb028d787249cd897fe4a1b96420addb8b.patch";
334 hash = "sha256-YBDsvhfup1IMc5GcW7BdsHUKGCv3A1eGIeb4Wal4x7A=";
335 })
336 ];
337 }
338 ]
339 [ ];
340 });
341in
342patched_compcert.overrideAttrs (
343 o:
344 lib.optionalAttrs (coq.version != null && coq.version == "dev") {
345 configurePhase = "${o.configurePhase} -ignore-ocaml-version -ignore-coq-version";
346 }
347)