Skip to content

Commit ef176ca

Browse files
authored
x-compilation: pick up the dune fixes and use dune install (#716)
* x-compilation: pick up the dune fixes and use `dune install` * new fix * one more prefix lol * new version has ocaml/dune#7450 and ocaml/dune#7428 * ocamlyacc * can't run hooks because other drvs use `${topkg.buildPhase} args` * remove pkg-config hack * wip * sans ocamlpath * even better * more simplification * more fixes * missing dep
1 parent b36a825 commit ef176ca

File tree

4 files changed

+70
-149
lines changed

4 files changed

+70
-149
lines changed

cross/ocaml-compiler.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ in {
3535
3636
OCAML_HOST=${natocaml}
3737
OCAMLRUN="$OCAML_HOST/bin/ocamlrun"
38+
OCAMLLEX="$OCAML_HOST/bin/ocamllex"
3839
OCAMLYACC="$OCAML_HOST/bin/ocamlyacc"
3940
CAMLDEP="$OCAML_HOST/bin/ocamlc"
4041
DYNAMIC_LIBS="-I $OCAML_HOST/lib/ocaml/stublibs"
@@ -53,6 +54,7 @@ in {
5354
make_caml () {
5455
make ''${enableParallelBuilding:+-j $NIX_BUILD_CORES} ''${enableParallelBuilding:+-l $NIX_BUILD_CORES} \
5556
CAMLDEP="$CAMLDEP -depend" \
57+
OCAMLLEX="$OCAMLLEX" \
5658
OCAMLYACC="$OCAMLYACC" CAMLYACC="$OCAMLYACC" \
5759
CAMLRUN="$OCAMLRUN" OCAMLRUN="$OCAMLRUN" \
5860
NEW_OCAMLRUN="$OCAMLRUN" \
@@ -100,6 +102,7 @@ in {
100102
runHook postBuild
101103
'';
102104
installTargets = o.installTargets ++ [ "installoptopt" ];
105+
postInstall = "cp ${natocaml}/bin/ocamlyacc $out/bin/ocamlyacc";
103106
patches = [
104107
(if isOCaml5
105108
then ./cross_5_00.patch

cross/ocaml.nix

Lines changed: 48 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ in
6060
natocaml = natocamlPackages.ocaml;
6161
natfindlib = natocamlPackages.findlib;
6262
natdune = natocamlPackages.dune;
63+
findNativePackage = p:
64+
if p ? pname then
65+
let
66+
pname = p.pname or (throw "`p.pname' not found: ${p.name}");
67+
in
68+
natocamlPackages."${pname}" or
69+
# Some legacy packages are called `ocaml_X`, e.g. extlib and
70+
# sqlite3
71+
natocamlPackages."ocaml_${pname}" or
72+
(
73+
let
74+
prefix1 = "ocaml${osuper.ocaml.version}-";
75+
prefix2 = "ocaml-";
76+
in
77+
if lib.hasPrefix prefix1 p.pname
78+
then natocamlPackages."${(lib.removePrefix prefix1 pname)}"
79+
else if lib.hasPrefix prefix2 p.pname
80+
then natocamlPackages."${(lib.removePrefix prefix2 pname)}"
81+
else throw "Unsupported cross-pkg parsing for `${p.pname}'"
82+
)
83+
else { };
6384

6485
makeFindlibConf = b:
6586
let
@@ -71,9 +92,10 @@ in
7192
b;
7293
natInputs = mergeInputs [
7394
"propagatedBuildInputs"
95+
"buildInputs"
7496
"nativeBuildInputs"
7597
]
76-
b;
98+
(findNativePackage b);
7799

78100
path =
79101
builtins.concatStringsSep ":"
@@ -162,7 +184,7 @@ in
162184
fi
163185
}
164186
exportOcamlDestDir () {
165-
export OCAMLFIND_DESTDIR="''$out/lib/ocaml/${oself.ocaml.version}/site-lib/"
187+
export OCAMLFIND_DESTDIR="''$out/lib/ocaml/${oself.ocaml.version}/${crossName}-sysroot/lib/"
166188
}
167189
createOcamlDestDir () {
168190
if test -n "''${createFindlibDestdir-}"; then
@@ -206,38 +228,22 @@ in
206228
'';
207229

208230
installPhase =
209-
let
210-
natPackage =
211-
natocamlPackages."${args.pname}" or
212-
# Some legacy packages are called `ocaml_X`, e.g. extlib and
213-
# sqlite3
214-
natocamlPackages."ocaml_${args.pname}";
215-
in
216231
''
217232
runHook preInstall
218-
${oself.opaline}/bin/opaline -name ${args.pname} -prefix $out -libdir $OCAMLFIND_DESTDIR
219-
220-
rm -rf $out/lib/ocaml/${osuper.ocaml.version}/site-lib
221-
ln -sfn ${natPackage}/lib/ocaml/${osuper.ocaml.version}/site-lib $out/lib/ocaml/${osuper.ocaml.version}/site-lib
233+
dune install ${args.pname} -x ${crossName} \
234+
--prefix $out --libdir $(dirname $OCAMLFIND_DESTDIR) \
235+
--docdir $out/share/doc --man $out/share/man
222236
runHook postInstall
223237
'';
224238
} // args
225239
)).overrideAttrs (o: {
226240
nativeBuildInputs =
227-
[ natocaml natdune natfindlib buildPackages.stdenv.cc ] ++
228-
# XXX(anmonteiro): apparently important that this comes after
229-
(o.nativeBuildInputs or [ ]);
241+
(o.nativeBuildInputs or [ ]) ++ [ buildPackages.stdenv.cc ];
230242
});
231243

232244
topkg = natocamlPackages.topkg.overrideAttrs (o:
233245
let
234-
run = ''
235-
if [ -z "''${selfBuild:-}" ]; then
236-
unset OCAMLPATH
237-
fi
238-
239-
${natocaml}/bin/ocaml -I ${natfindlib}/lib/ocaml/${osuper.ocaml.version}/site-lib/ pkg/pkg.ml \
240-
'';
246+
run = "${natocaml}/bin/ocaml -I ${natfindlib}/lib/ocaml/${osuper.ocaml.version}/site-lib pkg/pkg.ml";
241247
in
242248
{
243249
selfBuild = true;
@@ -248,13 +254,6 @@ in
248254

249255
buildPhase = "${run} build";
250256

251-
installPhase = ''
252-
if [ -z "''${selfBuild:-}" ]; then
253-
OCAMLFIND_DESTDIR=$(dirname $OCAMLFIND_DESTDIR)/${crossName}-sysroot/lib/
254-
fi
255-
${oself.opaline}/bin/opaline -prefix $out -libdir $OCAMLFIND_DESTDIR
256-
'';
257-
258257
setupHook = writeText "setupHook.sh" ''
259258
addToolchainVariable () {
260259
if [ -z "''${selfBuild:-}" ]; then
@@ -271,47 +270,30 @@ in
271270
let
272271
crossName = lib.head (lib.splitString "-" stdenv.system);
273272
natocamlPackages = getNativeOCamlPackages osuper;
274-
275-
fixTopkgInstall = p: natPackage: p.overrideAttrs (o: {
276-
installPhase = ''
277-
rm -rf $out/lib/ocaml/${osuper.ocaml.version}/site-lib
278-
mkdir -p $out/lib/ocaml/${osuper.ocaml.version}
279-
ln -sfn ${natPackage}/lib/ocaml/${osuper.ocaml.version}/site-lib $out/lib/ocaml/${osuper.ocaml.version}/site-lib
280-
281-
${o.installPhase}
282-
runHook postInstall
283-
'';
284-
});
285273
in
286274
{
287275
camlzip = osuper.camlzip.overrideAttrs (_: {
288276
OCAMLFIND_TOOLCHAIN = "${crossName}";
289277
postInstall = ''
290-
OCAMLFIND_DESTDIR=$(dirname $OCAMLFIND_DESTDIR)/${crossName}-sysroot/lib/
291-
mkdir -p $OCAMLFIND_DESTDIR
292-
mv $out/lib/ocaml/${osuper.ocaml.version}/site-lib/* $OCAMLFIND_DESTDIR
293-
rm -rf $OCAMLFIND_DESTDIR/camlzip
294278
ln -sfn $OCAMLFIND_DESTDIR/{,caml}zip
295279
'';
296280
});
297281

298282
ctypes = osuper.ctypes.overrideAttrs (o: {
299283
postInstall = ''
300-
echo -e '\nversion = "${o.version}"'>> $out/lib/ocaml/${osuper.ocaml.version}/aarch64-sysroot/lib/ctypes/META
284+
echo -e '\nversion = "${o.version}"'>> $out/lib/ocaml/${osuper.ocaml.version}/${crossName}-sysroot/lib/ctypes/META
301285
'';
302286
});
303287

304288
cmdliner = osuper.cmdliner.overrideAttrs (o: {
305-
nativeBuildInputs = o.nativeBuildInputs ++ [ osuper.findlib ];
289+
nativeBuildInputs = o.nativeBuildInputs ++ [ oself.findlib ];
306290

307-
installPhase = ''
308-
rm -rf $out/lib/ocaml/${osuper.ocaml.version}/site-lib
309-
mkdir -p $out/lib/ocaml/${osuper.ocaml.version}
310-
ln -sfn ${natocamlPackages.cmdliner}/lib/ocaml/${osuper.ocaml.version}/site-lib $out/lib/ocaml/${osuper.ocaml.version}/site-lib
311-
312-
OCAMLFIND_DESTDIR=$(dirname $OCAMLFIND_DESTDIR)/${crossName}-sysroot/lib/
313-
mkdir -p $OCAMLFIND_DESTDIR
314-
make install LIBDIR=$OCAMLFIND_DESTDIR/cmdliner
291+
installFlags = [
292+
"LIBDIR=$(OCAMLFIND_DESTDIR)/${o.pname}"
293+
"DOCDIR=$(out)/share/doc/${o.pname}"
294+
];
295+
postInstall = ''
296+
mv $OCAMLFIND_DESTDIR/${o.pname}/{opam,${o.pname}.opam}
315297
'';
316298
});
317299

@@ -325,10 +307,7 @@ in
325307
chmod a+x ./build.sh
326308
'';
327309
installPhase = ''
328-
${oself.opaline}/bin/opaline -prefix $out -libdir $out/lib/ocaml/${osuper.ocaml.version}/site-lib/ ${o.pname}.install
329-
OCAMLFIND_DESTDIR=$(dirname $OCAMLFIND_DESTDIR)/${crossName}-sysroot/lib/
330-
mkdir -p $OCAMLFIND_DESTDIR
331-
mv $out/lib/ocaml/${osuper.ocaml.version}/site-lib/* $OCAMLFIND_DESTDIR
310+
${oself.opaline}/bin/opaline -prefix $out -libdir $OCAMLFIND_DESTDIR ${o.pname}.install
332311
'';
333312
});
334313

@@ -349,62 +328,35 @@ in
349328

350329
num = osuper.num.overrideAttrs (_: {
351330
OCAMLFIND_TOOLCHAIN = "${crossName}";
352-
postInstall = ''
353-
OCAMLFIND_DESTDIR=$(dirname $OCAMLFIND_DESTDIR)/${crossName}-sysroot/lib/
354-
mkdir -p $OCAMLFIND_DESTDIR
355-
mv $out/lib/ocaml/${osuper.ocaml.version}/site-lib/* $OCAMLFIND_DESTDIR
356-
'';
357331
});
358332

359333
ocaml-migrate-parsetree = osuper.ocaml-migrate-parsetree-2;
360334

361-
seq = osuper.seq.overrideAttrs (_: {
335+
seq = osuper.seq.overrideAttrs (o: {
336+
nativeBuildInputs = [ oself.findlib ];
362337
installPhase = ''
363-
install_dest="$out/lib/ocaml/${osuper.ocaml.version}/${crossName}-sysroot/lib/seq/"
338+
install_dest="$OCAMLFIND_DESTDIR/seq/"
364339
mkdir -p $install_dest
365340
mv META $install_dest
366-
367-
mkdir -p $out/lib/ocaml/${osuper.ocaml.version}/site-lib/seq
368-
ln -sfn $install_dest/META $out/lib/ocaml/${osuper.ocaml.version}/site-lib/seq
369341
'';
370342
});
371343

372344
uchar = osuper.uchar.overrideAttrs (_: {
373-
installPhase = osuper.topkg.installPhase;
345+
installPhase = oself.topkg.installPhase;
374346
});
375347

376348
zarith = osuper.zarith.overrideAttrs (o: {
377349
configurePlatforms = [ ];
378350
OCAMLFIND_TOOLCHAIN = "${crossName}";
379-
configureFlags = o.configureFlags ++ [
380-
"-prefixnonocaml ${stdenv.cc.targetPrefix}"
351+
configureFlags = [
381352
];
353+
configurePhase = ''
354+
./configure -prefixnonocaml ${stdenv.cc.targetPrefix} -installdir $OCAMLFIND_DESTDIR
355+
'';
382356
preBuild = ''
383357
buildFlagsArray+=("host=${stdenv.hostPlatform.config}")
384358
'';
385-
postInstall = ''
386-
OCAMLFIND_DESTDIR=$(dirname $OCAMLFIND_DESTDIR)/${crossName}-sysroot/lib/
387-
mkdir -p $OCAMLFIND_DESTDIR
388-
mv $out/lib/ocaml/${osuper.ocaml.version}/site-lib/* $OCAMLFIND_DESTDIR
389-
390-
rm -rf $out/lib/ocaml/${osuper.ocaml.version}/site-lib
391-
mkdir -p $out/lib/ocaml/${osuper.ocaml.version}
392-
ln -sfn ${natocamlPackages.zarith}/lib/ocaml/${osuper.ocaml.version}/site-lib $out/lib/ocaml/${osuper.ocaml.version}/site-lib
393-
'';
359+
preInstall = "mkdir -p $OCAMLFIND_DESTDIR";
394360
});
395-
} // (lib.genAttrs [
396-
"astring"
397-
"jsonm"
398-
"fmt"
399-
"uutf"
400-
"uunf"
401-
"logs"
402-
"fpath"
403-
"bos"
404-
"ptime"
405-
"rresult"
406-
"mtime"
407-
"xmlm"
408-
]
409-
(name: fixTopkgInstall osuper.${name} natocamlPackages.${name})))
361+
})
410362
]

ocaml/default.nix

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,8 @@ with oself;
567567
src = fetchFromGitHub {
568568
owner = "ocaml";
569569
repo = "dune";
570-
rev = "ab74a71dc04380ed592462f982ceb4dd6371203f";
571-
hash = "sha256-EidPQXmB/sd4tEpp7H8flgRw8lhm/s0Pg/IalhSgYdg=";
570+
rev = "8b7133d10480bf585f17ffaba3b0e482eec21ff0";
571+
hash = "sha256-Auo53K6t6oSgr52Mziq4Qlhhn0Dih0Ohq+D2kw1KdUE=";
572572
};
573573
nativeBuildInputs = o.nativeBuildInputs ++ [ makeWrapper ];
574574

@@ -695,14 +695,6 @@ with oself;
695695

696696
flow_parser = callPackage ./flow_parser { };
697697

698-
fmt = osuper.fmt.overrideAttrs (o: {
699-
src = builtins.fetchurl {
700-
url = https://erratique.ch/software/fmt/releases/fmt-0.9.0.tbz;
701-
sha256 = "0q8j2in2473xh7k4hfgnppv9qy77f2ih89yp6yhpbp92ba021yzi";
702-
};
703-
propagatedBuildInputs = [ cmdliner ];
704-
});
705-
706698
functoria-runtime = osuper.functoria-runtime.overrideAttrs (_: {
707699
postPatch = ''
708700
substituteInPlace ./lib_runtime/functoria/dune --replace "bytes" ""
@@ -970,8 +962,6 @@ with oself;
970962
rev = "3d6f0fac";
971963
sha256 = "sha256-QIxKQEoA5EOGqhwCKdIWQ09RhPKYoleTWdbT1GI397o=";
972964
};
973-
974-
propagatedBuildInputs = [ ocplib-endian ];
975965
postPatch = ''
976966
substituteInPlace src/unix/dune --replace "bigarray" ""
977967
'';
@@ -1138,15 +1128,21 @@ with oself;
11381128
postPatch = "echo '(lang dune 2.0)' > dune-project";
11391129
});
11401130

1141-
num = osuper.num.overrideAttrs (o: {
1131+
num = (osuper.num.override { withStatic = true; }).overrideAttrs (o: {
11421132
src = fetchFromGitHub {
11431133
owner = "ocaml";
11441134
repo = "num";
1145-
rev = "703e1f88";
1146-
sha256 = "sha256-Ddo6zmCPF730EV0YliIRnZ80j9YnBOH1yCQTBs7lXDo=";
1135+
rev = "f06af1fda2e722542cc5f2d2d4d1f4441055a92f";
1136+
hash = "sha256-WdH2W5K7UykxCnJu+AwBeRsHR+TWpDyJX3sqF7mk+Cw=";
11471137
};
1148-
1149-
patches = [ ./num/findlib-install.patch ];
1138+
buildFlags = [ "opam-modern" ];
1139+
patches = [ ];
1140+
installPhase = ''
1141+
# Not sure if this is entirely correct, but opaline doesn't like `lib_root`
1142+
substituteInPlace num.install --replace lib_root lib
1143+
cat num.install
1144+
OCAMLRUNPARAM=b ${opaline}/bin/opaline -prefix $out -libdir $OCAMLFIND_DESTDIR num.install
1145+
'';
11501146
});
11511147

11521148
ocaml = (osuper.ocaml.override { flambdaSupport = true; }).overrideAttrs (_: {
@@ -1181,6 +1177,7 @@ with oself;
11811177
ppx_deriving
11821178
sexplib
11831179
ppx_sexp_conv
1180+
cmdliner
11841181
];
11851182
};
11861183

@@ -1469,8 +1466,8 @@ with oself;
14691466

14701467
ppxlib = osuper.ppxlib.overrideAttrs (_: {
14711468
src = builtins.fetchurl {
1472-
url = https://github.com/ocaml-ppx/ppxlib/releases/download/0.29.0/ppxlib-0.29.0.tbz;
1473-
sha256 = "1fjqjq9w157wkzgappswm8g1adhb8r4qvs9kfmw3kvzhvd6i12wf";
1469+
url = https://github.com/ocaml-ppx/ppxlib/releases/download/0.29.1/ppxlib-0.29.1.tbz;
1470+
sha256 = "0yfxwmkcgrn8j0m8dsklm7d979119f0jszrfc6kdnks1f23qrsn8";
14741471
};
14751472

14761473
propagatedBuildInputs = [
@@ -1799,6 +1796,9 @@ with oself;
17991796
substituteInPlace pkg/META --replace "bytes" ""
18001797
'';
18011798
});
1799+
uutf = osuper.uutf.overrideAttrs (_: {
1800+
pname = "uutf";
1801+
});
18021802

18031803
vlq = osuper.vlq.overrideAttrs (_: {
18041804
propagatedBuildInputs = [ camlp-streams ];

ocaml/num/findlib-install.patch

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)