1############################################################################
2# This file mainly provides the `mathcomp` derivation, which is #
3# essentially a meta-package containing all core mathcomp libraries #
4# (ssreflect fingroup algebra solvable field character). They can be #
5# accessed individually through the passthrough attributes of mathcomp #
6# bearing the same names (mathcomp.ssreflect, etc). #
7############################################################################
8# Compiling a custom version of mathcomp using `mathcomp.override`. #
9# This is the replacement for the former `mathcomp_ config` function. #
10# See the documentation at doc/languages-frameworks/coq.section.md. #
11############################################################################
12
13{ lib, ncurses, graphviz, lua, fetchzip,
14 mkCoqDerivation, recurseIntoAttrs, withDoc ? false, single ? false,
15 coqPackages, coq, hierarchy-builder, version ? null }@args:
16with builtins // lib;
17let
18 repo = "math-comp";
19 owner = "math-comp";
20 withDoc = single && (args.withDoc or false);
21 defaultVersion = with versions; lib.switch coq.coq-version [
22 { case = isGe "8.17"; out = "1.18.0"; }
23 { case = range "8.15" "8.18"; out = "1.17.0"; }
24 { case = range "8.16" "8.18"; out = "2.1.0"; }
25 { case = range "8.16" "8.18"; out = "2.0.0"; }
26 { case = range "8.13" "8.18"; out = "1.16.0"; }
27 { case = range "8.14" "8.16"; out = "1.15.0"; }
28 { case = range "8.11" "8.15"; out = "1.14.0"; }
29 { case = range "8.11" "8.15"; out = "1.13.0"; }
30 { case = range "8.10" "8.13"; out = "1.12.0"; }
31 { case = range "8.7" "8.12"; out = "1.11.0"; }
32 { case = range "8.7" "8.11"; out = "1.10.0"; }
33 { case = range "8.7" "8.11"; out = "1.9.0"; }
34 { case = range "8.7" "8.9"; out = "1.8.0"; }
35 { case = range "8.6" "8.9"; out = "1.7.0"; }
36 { case = range "8.5" "8.7"; out = "1.6.4"; }
37 ] null;
38 release = {
39 "2.1.0".sha256 = "sha256-XDLx0BIkVRkSJ4sGCIE51j3rtkSGemNTs/cdVmTvxqo=";
40 "2.0.0".sha256 = "sha256-dpOmrHYUXBBS9kmmz7puzufxlbNpIZofpcTvJFLG5DI=";
41 "1.18.0".sha256 = "sha256-mJJ/zvM2WtmBZU3U4oid/zCMvDXei/93v5hwyyqwiiY=";
42 "1.17.0".sha256 = "sha256-bUfoSTMiW/GzC1jKFay6DRqGzKPuLOSUsO6/wPSFwNg=";
43 "1.16.0".sha256 = "sha256-gXTKhRgSGeRBUnwdDezMsMKbOvxdffT+kViZ9e1gEz0=";
44 "1.15.0".sha256 = "1bp0jxl35ms54s0mdqky15w9af03f3i0n06qk12k4gw1xzvwqv21";
45 "1.14.0".sha256 = "07yamlp1c0g5nahkd2gpfhammcca74ga2s6qr7a3wm6y6j5pivk9";
46 "1.13.0".sha256 = "0j4cz2y1r1aw79snkcf1pmicgzf8swbaf9ippz0vg99a572zqzri";
47 "1.12.0".sha256 = "1ccfny1vwgmdl91kz5xlmhq4wz078xm4z5wpd0jy5rn890dx03wp";
48 "1.11.0".sha256 = "06a71d196wd5k4wg7khwqb7j7ifr7garhwkd54s86i0j7d6nhl3c";
49 "1.10.0".sha256 = "1b9m6pwxxyivw7rgx82gn5kmgv2mfv3h3y0mmjcjfypi8ydkrlbv";
50 "1.9.0".sha256 = "0lid9zaazdi3d38l8042lczb02pw5m9wq0yysiilx891hgq2p81r";
51 "1.8.0".sha256 = "07l40is389ih8bi525gpqs3qp4yb2kl11r9c8ynk1ifpjzpnabwp";
52 "1.7.0".sha256 = "0wnhj9nqpx2bw6n1l4i8jgrw3pjajvckvj3lr4vzjb3my2lbxdd1";
53 "1.6.4".sha256 = "09ww48qbjsvpjmy1g9yhm0rrkq800ffq21p6fjkbwd34qvd82raz";
54 "1.6.1".sha256 = "1ilw6vm4dlsdv9cd7kmf0vfrh2kkzr45wrqr8m37miy0byzr4p9i";
55 };
56 releaseRev = v: "mathcomp-${v}";
57
58 # list of core mathcomp packages sorted by dependency order
59 packages = [ "ssreflect" "fingroup" "algebra" "solvable" "field" "character" "all" ];
60
61 mathcomp_ = package: let
62 mathcomp-deps = lib.optionals (package != "single") (map mathcomp_ (head (splitList (lib.pred.equal package) packages)));
63 pkgpath = if package == "single" then "mathcomp" else "mathcomp/${package}";
64 pname = if package == "single" then "mathcomp" else "mathcomp-${package}";
65 pkgallMake = ''
66 echo "all.v" > Make
67 echo "-I ." >> Make
68 echo "-R . mathcomp.all" >> Make
69 '';
70 derivation = mkCoqDerivation ({
71 inherit version pname defaultVersion release releaseRev repo owner;
72
73 mlPlugin = versions.isLe "8.6" coq.coq-version;
74 nativeBuildInputs = optionals withDoc [ graphviz lua ];
75 buildInputs = [ ncurses ];
76 propagatedBuildInputs = mathcomp-deps;
77
78 buildFlags = optional withDoc "doc";
79
80 preBuild = ''
81 if [[ -f etc/utils/ssrcoqdep ]]
82 then patchShebangs etc/utils/ssrcoqdep
83 fi
84 if [[ -f etc/buildlibgraph ]]
85 then patchShebangs etc/buildlibgraph
86 fi
87 '' + ''
88 cd ${pkgpath}
89 '' + optionalString (package == "all") pkgallMake;
90
91 meta = {
92 homepage = "https://math-comp.github.io/";
93 license = licenses.cecill-b;
94 maintainers = with maintainers; [ vbgl jwiegley cohencyril ];
95 };
96 } // optionalAttrs (package != "single")
97 { passthru = genAttrs packages mathcomp_; }
98 // optionalAttrs withDoc {
99 htmldoc_template =
100 fetchzip {
101 url = "https://github.com/math-comp/math-comp.github.io/archive/doc-1.12.0.zip";
102 sha256 = "0y1352ha2yy6k2dl375sb1r68r1qi9dyyy7dyzj5lp9hxhhq69x8";
103 };
104 postBuild = ''
105 cp -rf _build_doc/* .
106 rm -r _build_doc
107 '';
108 postInstall =
109 let tgt = "$out/share/coq/${coq.coq-version}/"; in
110 optionalString withDoc ''
111 mkdir -p ${tgt}
112 cp -r htmldoc ${tgt}
113 cp -r $htmldoc_template/htmldoc_template/* ${tgt}/htmldoc/
114 '';
115 buildTargets = "doc";
116 extraInstallFlags = [ "-f Makefile.coq" ];
117 });
118 patched-derivation1 = derivation.overrideAttrs (o:
119 optionalAttrs (o.pname != null && o.pname == "mathcomp-all" &&
120 o.version != null && o.version != "dev" && versions.isLt "1.7" o.version)
121 { preBuild = ""; buildPhase = ""; installPhase = "echo doing nothing"; }
122 );
123 patched-derivation2 = patched-derivation1.overrideAttrs (o:
124 optionalAttrs (versions.isLe "8.7" coq.coq-version ||
125 (o.version != "dev" && versions.isLe "1.7" o.version))
126 {
127 installFlags = o.installFlags ++ [ "-f Makefile.coq" ];
128 }
129 );
130 patched-derivation = patched-derivation2.overrideAttrs (o:
131 optionalAttrs (o.version != null
132 && (o.version == "dev" || versions.isGe "2.0.0" o.version))
133 {
134 propagatedBuildInputs = o.propagatedBuildInputs ++ [ hierarchy-builder ];
135 }
136 );
137 in patched-derivation;
138in
139mathcomp_ (if single then "single" else "all")