1{ lib, stdenv, fetchFromGitHub, fetchpatch, makeWrapper
2, coqPackages, ocamlPackages, coq2html
3, tools ? stdenv.cc
4, version ? "3.8"
5}:
6
7let
8 ocaml-pkgs = with ocamlPackages; [ ocaml findlib menhir ];
9 ccomp-platform = if stdenv.isDarwin then "x86_64-macosx" else "x86_64-linux";
10 inherit (coqPackages) coq flocq;
11 inherit (lib) optional optionalString;
12in
13
14let param = {
15 "3.7" = {
16 sha256 = "1h4zhk9rrqki193nxs9vjvya7nl9yxjcf07hfqb6g77riy1vd2jr";
17 patches = [
18 (fetchpatch {
19 url = "https://github.com/AbsInt/CompCert/commit/0a2db0269809539ccc66f8ec73637c37fbd23580.patch";
20 sha256 = "0n8qrba70x8f422jdvq9ddgsx6avf2dkg892g4ldh3jiiidyhspy";
21 })
22 (fetchpatch {
23 url = "https://github.com/AbsInt/CompCert/commit/5e29f8b5ba9582ecf2a1d0baeaef195873640607.patch";
24 sha256 = "184nfdgxrkci880lkaj5pgnify3plka7xfgqrgv16275sqppc5hc";
25 })
26 ];
27 };
28 "3.8" = {
29 sha256 = "1gzlyxvw64ca12qql3wnq3bidcx9ygsklv9grjma3ib4hvg7vnr7";
30 patches = [
31 # Support for Coq 8.12.2
32 (fetchpatch {
33 url = "https://github.com/AbsInt/CompCert/commit/06956421b4307054af221c118c5f59593c0e67b9.patch";
34 sha256 = "1f90q6j3xfvnf3z830bkd4d8526issvmdlrjlc95bfsqs78i1yrl";
35 })
36 # Support for Coq 8.13.0
37 (fetchpatch {
38 url = "https://github.com/AbsInt/CompCert/commit/0895388e7ebf9c9f3176d225107e21968919fb97.patch";
39 sha256 = "0qhkzgb2xl5kxys81pldp3mr39gd30lvr2l2wmplij319vp3xavd";
40 })
41 # Support for Coq 8.13.1
42 (fetchpatch {
43 url = "https://github.com/AbsInt/CompCert/commit/6bf310dd678285dc193798e89fc2c441d8430892.patch";
44 sha256 = "026ahhvpj5pksy90f8pnxgmhgwfqk4kwyvcf8x3dsanvz98d4pj5";
45 })
46 # Drop support for Coq < 8.9
47 (fetchpatch {
48 url = "https://github.com/AbsInt/CompCert/commit/7563a5df926a4c6fb1489a7a4c847641c8a35095.patch";
49 sha256 = "05vkslzy399r3dm6dmjs722rrajnyfa30xsyy3djl52isvn4gyfb";
50 })
51 # Support for Coq 8.13.2
52 (fetchpatch {
53 url = "https://github.com/AbsInt/CompCert/commit/48bc183167c4ce01a5c9ea86e49d60530adf7290.patch";
54 sha256 = "0j62lppfk26d1brdp3qwll2wi4gvpx1k70qivpvby5f7dpkrkax1";
55 })
56 ];
57 useExternalFlocq = true;
58 };
59}."${version}"; in
60
61stdenv.mkDerivation rec {
62 pname = "compcert";
63 inherit version;
64
65 src = fetchFromGitHub {
66 owner = "AbsInt";
67 repo = "CompCert";
68 rev = "v${version}";
69 inherit (param) sha256;
70 };
71
72 patches = param.patches or [];
73
74 nativeBuildInputs = [ makeWrapper ];
75 buildInputs = ocaml-pkgs ++ [ coq coq2html ];
76 propagatedBuildInputs = optional (param.useExternalFlocq or false) flocq;
77 enableParallelBuilding = true;
78
79 postPatch = ''
80 substituteInPlace ./configure \
81 --replace '{toolprefix}gcc' '{toolprefix}cc'
82 '';
83
84 configurePhase = ''
85 ./configure -clightgen \
86 -prefix $out \
87 -coqdevdir $lib/lib/coq/${coq.coq-version}/user-contrib/compcert/ \
88 -toolprefix ${tools}/bin/ \
89 ${optionalString (param.useExternalFlocq or false) "-use-external-Flocq"} \
90 ${ccomp-platform}
91 '';
92
93 installTargets = "documentation install";
94 postInstall = ''
95 # move man into place
96 mkdir -p $man/share
97 mv $out/share/man/ $man/share/
98
99 # move docs into place
100 mkdir -p $doc/share/doc/compcert
101 mv doc/html $doc/share/doc/compcert/
102
103 # wrap ccomp to undefine _FORTIFY_SOURCE; ccomp invokes cc1 which sets
104 # _FORTIFY_SOURCE=2 by default, but undefines __GNUC__ (as it should),
105 # which causes a warning in libc. this suppresses it.
106 for x in ccomp clightgen; do
107 wrapProgram $out/bin/$x --add-flags "-U_FORTIFY_SOURCE"
108 done
109 '';
110
111 outputs = [ "out" "lib" "doc" "man" ];
112
113 meta = with lib; {
114 description = "Formally verified C compiler";
115 homepage = "https://compcert.org";
116 license = licenses.inria-compcert;
117 platforms = [ "x86_64-linux" "x86_64-darwin" ];
118 maintainers = with maintainers; [ thoughtpolice jwiegley vbgl ];
119 };
120}