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