Merge pull request #73820 from serokell/static-fixes

Fix static building for ocaml-ng
This commit is contained in:
Matthew Bauer 2019-12-02 13:34:41 -05:00 committed by GitHub
commit 18848aa605
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 169 additions and 56 deletions

View File

@ -27,7 +27,8 @@ stdenv.mkDerivation rec {
++ stdenv.lib.optional stdenv.isDarwin gettext
++ stdenv.lib.optional enableCapabilities libcap;
configureFlags = [ "--with-libgpg-error-prefix=${libgpgerror.dev}" ];
configureFlags = [ "--with-libgpg-error-prefix=${libgpgerror.dev}" ]
++ stdenv.lib.optional stdenv.hostPlatform.isMusl "--disable-asm";
# Make sure libraries are correct for .pc and .la files
# Also make sure includes are fixed for callers who don't use libgpgcrypt-config

View File

@ -28,13 +28,8 @@ stdenv.mkDerivation (rec {
NIX_LDFLAGS = stdenv.lib.optionalString stdenv.isLinux "-lgcc_s";
configureFlags =
# We use `isLinux` here only to avoid mass rebuilds for Darwin, where
# disabling udev happens automatically. Remove `isLinux` at next big change!
stdenv.lib.optional (stdenv.isLinux && !enableSystemd) "--disable-udev";
preFixup = stdenv.lib.optionalString enableSystemd ''
sed 's,-ludev,-L${systemd.lib}/lib -ludev,' -i $out/lib/libusb-1.0.la
preFixup = stdenv.lib.optionalString stdenv.isLinux ''
sed 's,-ludev,-L${stdenv.lib.getLib systemd}/lib -ludev,' -i $out/lib/libusb-1.0.la
'';
meta = with stdenv.lib; {

View File

@ -6,14 +6,15 @@ let param =
if stdenv.lib.versionAtLeast ocaml.version "4.02" then {
version = "0.8.5";
sha256 = "1mhckvdcxkikbzgvy24kjz4265l15b86a6swz7m3ynbgvqdcfzqn";
buildInputs = [ dune ];
nativeBuildInputs = [ dune ];
propagatedBuildInputs = [ uuidm ];
buildPhase = "dune build -p alcotest";
inherit (dune) installPhase;
} else {
version = "0.7.2";
sha256 = "1qgsz2zz5ky6s5pf3j3shc4fjc36rqnjflk8x0wl1fcpvvkr52md";
buildInputs = [ ocamlbuild topkg ];
buildInputs = [ topkg ];
nativeBuildInputs = [ ocamlbuild ];
inherit (topkg) buildPhase installPhase;
};
in
@ -27,7 +28,8 @@ stdenv.mkDerivation rec {
inherit (param) sha256;
};
buildInputs = [ ocaml findlib ] ++ param.buildInputs;
nativeBuildInputs = [ ocaml findlib ] ++ (param.nativeBuildInputs or []);
buildInputs = [ findlib ] ++ (param.buildInputs or []);
propagatedBuildInputs = [ cmdliner astring fmt result ]
++ (param.propagatedBuildInputs or []);

View File

@ -25,7 +25,8 @@ stdenv.mkDerivation rec {
inherit (param) sha256;
};
buildInputs = [ ocaml findlib ocamlbuild ounit topkg ];
buildInputs = [ findlib ounit topkg ];
nativeBuildInputs = [ ocaml findlib ocamlbuild ];
propagatedBuildInputs = [ result cstruct zarith ] ++ param.propagatedBuildInputs;
buildPhase = "${topkg.run} build --tests true";

View File

@ -10,7 +10,8 @@ stdenv.mkDerivation rec {
sha256 = "1s10iqx8rgnxr5n93lf4blwirjf8nlm272yg5sipr7lsr35v49wc";
};
buildInputs = [ ocaml findlib ocamlbuild topkg ];
nativeBuildInputs = [ ocaml findlib ocamlbuild ];
buildInputs = [ findlib topkg ];
propagatedBuildInputs = [ astring fmt fpath logs rresult ];
inherit (topkg) buildPhase installPhase;

View File

@ -25,8 +25,8 @@ stdenv.mkDerivation rec {
inherit (param) sha256;
};
nativeBuildInputs = [ ocamlbuild topkg ];
buildInputs = [ ocaml findlib ];
nativeBuildInputs = [ ocaml ocamlbuild findlib ];
buildInputs = [ topkg ];
propagatedBuildInputs = [ result ];
inherit (topkg) buildPhase installPhase;

View File

@ -8,7 +8,8 @@ stdenv.mkDerivation {
sha256 = "1zj9azcxcn6skmb69ykgmi9z8c50yskwg03wqgh87lypgjdcz060";
};
buildInputs = [ ocaml findlib ocamlbuild topkg cmdliner ];
nativeBuildInputs = [ ocaml findlib ocamlbuild ];
buildInputs = [ findlib topkg cmdliner ];
propagatedBuildInputs = [ result uchar ];
inherit (topkg) buildPhase installPhase;

View File

@ -10,7 +10,8 @@ stdenv.mkDerivation {
sha256 = "1176dcmxb11fnw49b7yysvkjh0kpzx4s48lmdn5psq9vshp5c29w";
};
buildInputs = [ ocaml findlib ocamlbuild topkg ];
buildInputs = [ findlib topkg ];
nativeBuildInputs = [ ocaml findlib ocamlbuild ];
propagatedBuildInputs = [ uutf ];
inherit (topkg) buildPhase installPhase;

View File

@ -18,7 +18,8 @@ stdenv.mkDerivation rec {
sha256 = "1lkhr7i44xw4kpfbhgj3rbqy3dv5bfm4kyrbl8a9rfafddcxlwss";
};
buildInputs = [ ocaml findlib ocamlbuild topkg fmt cmdliner lwt ];
nativeBuildInputs = [ ocaml findlib ocamlbuild ];
buildInputs = [ findlib topkg fmt cmdliner lwt ];
propagatedBuildInputs = [ result ];
buildPhase = "${topkg.run} build --with-js_of_ocaml false";

View File

@ -11,7 +11,9 @@ stdenv.mkDerivation {
sha256 = "058d83hmxd5mjccxdm3ydchmhk2lca5jdg82jg0klsigmf4ida6v";
};
buildInputs = [ ocaml findlib ocamlbuild ];
nativeBuildInputs = [ ocaml findlib ocamlbuild ];
buildInputs = [ findlib ];
configurePlatforms = [];
createFindlibDestdir = true;

View File

@ -23,7 +23,8 @@ stdenv.mkDerivation {
inherit (param) sha256;
};
buildInputs = [ ocaml findlib ocamlbuild topkg ]
nativeBuildInputs = [ ocaml findlib ocamlbuild ];
buildInputs = [ findlib topkg ]
++ stdenv.lib.optional jsooSupport js_of_ocaml;
buildPhase = "${topkg.buildPhase} --with-js_of_ocaml ${boolToString jsooSupport}";

View File

@ -1,11 +1,19 @@
{ stdenv, fetchurl, fetchpatch, ocaml, findlib, ocamlbuild, topkg
, cpuid, ocb-stubblr, sexplib
, cstruct, zarith, ppx_sexp_conv, ppx_deriving
, cstruct, zarith, ppx_sexp_conv, ppx_deriving, writeScriptBin
, cstruct-lwt ? null
}:
with stdenv.lib;
let withLwt = cstruct-lwt != null; in
let
withLwt = cstruct-lwt != null;
# the build system will call 'cc' with no way to override
# this is wrong when we're cross-compiling, so insert a wrapper
cc-wrapper = writeScriptBin "cc" ''
set -e
$CC "$@"
'';
in
stdenv.mkDerivation rec {
name = "ocaml${ocaml.version}-nocrypto-${version}";
@ -43,8 +51,9 @@ stdenv.mkDerivation rec {
})
];
buildInputs = [ ocaml findlib ocamlbuild topkg cpuid ocb-stubblr ];
propagatedBuildInputs = [ cstruct ppx_deriving ppx_sexp_conv sexplib zarith ] ++ optional withLwt cstruct-lwt;
nativeBuildInputs = [ ocaml findlib ocamlbuild cc-wrapper ];
buildInputs = [ ocamlbuild findlib topkg cpuid ocb-stubblr ppx_deriving ];
propagatedBuildInputs = [ cstruct ppx_sexp_conv sexplib zarith ] ++ optional withLwt cstruct-lwt;
buildPhase = "${topkg.buildPhase} --with-lwt ${boolToString withLwt}";
inherit (topkg) installPhase;

View File

@ -1,4 +1,4 @@
{ stdenv, fetchFromGitHub, fetchpatch, ocaml, findlib }:
{ stdenv, lib, fetchFromGitHub, fetchpatch, ocaml, findlib, withStatic ? false }:
stdenv.mkDerivation rec {
version = "1.1";
@ -14,12 +14,14 @@ stdenv.mkDerivation rec {
url = "https://github.com/ocaml/num/commit/6d4c6d476c061298e6385e8a0864f083194b9307.patch";
sha256 = "18zlvb5n327q8y3c52js5dvyy29ssld1l53jqng8m9w1k24ypi0b";
})
];
] ++ lib.optional withStatic ./enable-static.patch;
buildInputs = [ ocaml findlib ];
nativeBuildInputs = [ ocaml findlib ];
buildInputs = [ ocaml findlib ];
createFindlibDestdir = true;
meta = {
description = "Legacy Num library for arbitrary-precision integer and rational arithmetic";
license = stdenv.lib.licenses.lgpl21;

View File

@ -0,0 +1,12 @@
diff -u a/src/Makefile b/src/Makefile
--- a/src/Makefile
+++ b/src/Makefile
@@ -45,7 +45,7 @@
endif
libnums.$(A): $(COBJS)
- $(OCAMLMKLIB) -oc nums $(COBJS)
+ $(OCAMLMKLIB) -custom -oc nums $(COBJS)
nums.cma: $(CMOS)
$(OCAMLMKLIB) -o nums -oc nums -linkall $(CMOS)

View File

@ -1,4 +1,4 @@
{stdenv, fetchurl, ocaml, findlib, lablgtk}:
{stdenv, fetchurl, ocaml, findlib, lablgtk ? null}:
stdenv.mkDerivation rec {
pname = "ocamlgraph";
@ -16,7 +16,8 @@ stdenv.mkDerivation rec {
postPatch = ''
sed -i 's@$(DESTDIR)$(OCAMLLIB)/ocamlgraph@$(DESTDIR)/lib/ocaml/${ocaml.version}/site-lib/ocamlgraph@' Makefile.in
sed -i 's@OCAMLFINDDEST := -destdir $(DESTDIR)@@' Makefile.in
sed -i 's@+lablgtk2@${lablgtk}/lib/ocaml/${ocaml.version}/site-lib/lablgtk2 -I ${lablgtk}/lib/ocaml/${ocaml.version}/site-lib/stublibs@' configure Makefile.in editor/Makefile
${stdenv.lib.optionalString (lablgtk != null)
"sed -i 's@+lablgtk2@${lablgtk}/lib/ocaml/${ocaml.version}/site-lib/lablgtk2 -I ${lablgtk}/lib/ocaml/${ocaml.version}/site-lib/stublibs@' configure Makefile.in editor/Makefile"}
'';
createFindlibDestdir = true;

View File

@ -15,6 +15,8 @@ stdenv.mkDerivation rec {
installFlags = [ "LIBDIR=$(OCAMLFIND_DESTDIR)" ];
patches = [ ./optional-static.patch ];
meta = {
description = "Parser and printer for the opam file syntax";
license = stdenv.lib.licenses.lgpl21;

View File

@ -0,0 +1,13 @@
diff -u a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -1,1 +1,5 @@
-TARGETS = opam-file-format.cma opam-file-format.cmxa opam-file-format.cmxs
+TARGETS = opam-file-format.cma opam-file-format.cmxa
+
+ifeq "$(NATDYNLINK)" "true"
+TARGETS = $(TARGETS) opam-file-format.cmxs
+endif
all: $(TARGETS)

View File

@ -14,7 +14,9 @@ stdenv.mkDerivation {
sha256 = "0hbd2sqdz75lv5ax82yhsfdk1dlcvq12xpys6n85ysmrl0c3d3lk";
});
buildInputs = [ ocaml findlib ocamlbuild ];
nativeBuildInputs = [ ocaml findlib ocamlbuild ];
buildInputs = [ findlib ];
configurePlatforms = [];
dontAddPrefix = true;

View File

@ -37,6 +37,7 @@ in
inherit (param) sha256;
};
nativeBuildInputs = [ ocaml findlib ];
buildInputs = [ ocaml findlib ];
createFindlibDestdir = true;

View File

@ -9,7 +9,8 @@ stdenv.mkDerivation rec {
sha256 = "1fxq57xy1ajzfdnvv5zfm7ap2nf49znw5f9gbi4kb9vds942ij27";
};
buildInputs = [ ocaml findlib ocamlbuild topkg js_of_ocaml ];
nativeBuildInputs = [ ocaml findlib ocamlbuild ];
buildInputs = [ findlib topkg js_of_ocaml ];
propagatedBuildInputs = [ result ];

View File

@ -21,7 +21,8 @@ stdenv.mkDerivation rec {
sha256 = "02wv4lia583imn3sfci4nqv6ac5nzig5j3yfdnlqa0q8bp9rfc6g";
};
buildInputs = [ ocaml ocamlbuild findlib topkg ppx_sexp_conv ppx_cstruct ]
nativeBuildInputs = [ ocaml ocamlbuild findlib ];
buildInputs = [ findlib topkg ppx_sexp_conv ppx_cstruct ]
++ optionals doCheck [ ounit cstruct-unix ];
propagatedBuildInputs = [ cstruct-sexp nocrypto result x509 ] ++
optional withLwt lwt;

View File

@ -29,7 +29,7 @@ stdenv.mkDerivation rec {
sha256 = "1df61vw6v5bg2mys045682ggv058yqkqb67w7r2gz85crs04d5fw";
};
buildInputs = [ ocaml findlib ocamlbuild ];
nativeBuildInputs = [ ocaml findlib ocamlbuild ];
propagatedBuildInputs = [ result ];
buildPhase = "${run} build";

View File

@ -1,4 +1,4 @@
{ stdenv, fetchurl, ocaml, findlib, ocamlbuild, opaline }:
{ stdenv, fetchurl, ocaml, findlib, ocamlbuild, opaline, withShared ? true }:
stdenv.mkDerivation {
name = "ocaml${ocaml.version}-uchar-0.0.2";
@ -8,9 +8,11 @@ stdenv.mkDerivation {
sha256 = "1w2saw7zanf9m9ffvz2lvcxvlm118pws2x1wym526xmydhqpyfa7";
};
buildInputs = [ ocaml ocamlbuild findlib opaline ];
buildPhase = "ocaml pkg/build.ml native=true native-dynlink=true";
nativeBuildInputs = [ ocaml ocamlbuild findlib opaline ];
buildInputs = [ findlib ocaml ocamlbuild opaline ];
buildPhase = "ocaml pkg/build.ml native=true native-dynlink=${if withShared then "true" else "false"}";
installPhase = "opaline -libdir $OCAMLFIND_DESTDIR";
configurePlatforms = [];
meta = {
description = "Compatibility library for OCamls Uchar module";

View File

@ -8,7 +8,9 @@ stdenv.mkDerivation rec {
sha256 = "1ivxb3hxn9bk62rmixx6px4fvn52s4yr1bpla7rgkcn8981v45r8";
};
buildInputs = [ ocaml findlib ocamlbuild topkg cmdliner ];
nativeBuildInputs = [ ocaml findlib ocamlbuild ];
configurePlatforms = [];
buildInputs = [ topkg cmdliner ];
inherit (topkg) buildPhase installPhase;

View File

@ -13,7 +13,8 @@ stdenv.mkDerivation rec {
sha256 = "1nx1rly3qj23jzn9yk3x6fwqimcxjd84kv5859vvhdg56psq26p6";
};
buildInputs = [ ocaml findlib ocamlbuild topkg cmdliner ];
nativeBuildInputs = [ ocaml ocamlbuild findlib ];
buildInputs = [ findlib topkg cmdliner ];
propagatedBuildInputs = [ uchar ];
inherit (topkg) buildPhase installPhase;

View File

@ -6,7 +6,7 @@ let
version = "1.7.0";
url = "https://github.com/ocaml-community/yojson/releases/download/${version}/yojson-${version}.tbz";
sha256 = "08llz96if8bcgnaishf18si76cv11zbkni0aldb54k3cn7ipiqvd";
buildInputs = [ dune ];
nativeBuildInputs = [ dune ];
extra = { inherit (dune) installPhase; };
} else rec {
version = "1.2.3";
@ -29,9 +29,10 @@ stdenv.mkDerivation ({
inherit (param) url sha256;
};
buildInputs = [ ocaml findlib ] ++ (param.buildInputs or []);
propagatedBuildInputs = [ cppo easy-format biniou ];
nativeBuildInputs = [ ocaml findlib ] ++ (param.nativeBuildInputs or []);
propagatedNativeBuildInputs = [ cppo ];
propagatedBuildInputs = [ easy-format biniou ];
configurePlatforms = [];
meta = with stdenv.lib; {
description = "An optimized parsing and printing library for the JSON format";

View File

@ -6,9 +6,9 @@
let source =
if stdenv.lib.versionAtLeast ocaml.version "4.02"
then {
version = "1.9.1";
url = https://github.com/ocaml/Zarith/archive/release-1.9.1.tar.gz;
sha256 = "0pfa271476dic5pvn6kxz3dfswxs6kqm2cxmhdx5xq2ayca05gj9";
version = "1.9";
url = https://github.com/ocaml/Zarith/archive/release-1.9.tar.gz;
sha256 = "1xrqcaj5gp52xp4ybpnblw8ciwlgrr0zi7rg7hnk8x83isjkpmwx";
} else {
version = "1.3";
url = http://forge.ocamlcore.org/frs/download.php/1471/zarith-1.3.tgz;
@ -26,9 +26,8 @@ stdenv.mkDerivation rec {
propagatedBuildInputs = [ gmp ];
patchPhase = "patchShebangs ./z_pp.pl";
configurePhase = ''
./configure -installdir $out/lib/ocaml/${ocaml.version}/site-lib
'';
dontAddPrefix = true;
configureFlags = [ "-installdir ${placeholder "out"}/lib/ocaml/${ocaml.version}/site-lib" ];
preInstall = "mkdir -p $out/lib/ocaml/${ocaml.version}/site-lib/stublibs";

View File

@ -3,11 +3,12 @@
}:
stdenv.mkDerivation {
pname = "js_of_ocaml";
pname = "js_of_ocaml";
inherit (js_of_ocaml-compiler) version src installPhase meta;
inherit (js_of_ocaml-compiler) version src installPhase meta;
buildInputs = [ ocaml findlib dune ocaml-migrate-parsetree ppx_tools_versioned ];
buildInputs = [ findlib ocaml-migrate-parsetree ppx_tools_versioned ];
nativeBuildInputs = [ ocaml findlib dune ];
postPatch = "patchShebangs lib/generate_stubs.sh";

View File

@ -1,5 +1,5 @@
{ lib, fetchFromGitHub, buildDunePackage
, cmdliner, cppo, yojson
, ocaml, findlib, cmdliner, dune, cppo, yojson
}:
buildDunePackage rec {
@ -13,8 +13,10 @@ buildDunePackage rec {
sha256 = "0c537say0f3197zn8d83nrihabrxyn28xc6d7c9c3l0vvrv6qvfj";
};
buildInputs = [ cmdliner cppo ];
nativeBuildInputs = [ ocaml findlib dune cppo ];
buildInputs = [ cmdliner ];
configurePlatforms = [];
propagatedBuildInputs = [ yojson ];
meta = {

View File

@ -1,5 +1,6 @@
{ stdenv, lib, fetchurl, autoreconfHook, pkgconfig
, libxslt, xz, elf-header }:
, libxslt, xz, elf-header
, withStatic ? false }:
let
systems = [ "/run/current-system/kernel-modules" "/run/booted-system/kernel-modules" "" ];
@ -21,10 +22,11 @@ in stdenv.mkDerivation rec {
"--sysconfdir=/etc"
"--with-xz"
"--with-modulesdirs=${modulesDirs}"
];
] ++ lib.optional withStatic "--enable-static";
patches = [ ./module-dir.patch ]
++ lib.optional stdenv.isDarwin ./darwin.patch;
++ lib.optional stdenv.isDarwin ./darwin.patch
++ lib.optional withStatic ./enable-static.patch;
postInstall = ''
for prog in rmmod insmod lsmod modinfo modprobe depmod; do

View File

@ -0,0 +1,12 @@
diff --git a/configure.ac b/configure.ac
index ee72283..b42c42a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -19,7 +19,6 @@ AM_SILENT_RULES([yes])
LT_INIT([disable-static pic-only])
DOLT
-AS_IF([test "x$enable_static" = "xyes"], [AC_MSG_ERROR([--enable-static is not supported by kmod])])
AS_IF([test "x$enable_largefile" = "xno"], [AC_MSG_ERROR([--disable-largefile is not supported by kmod])])
#####################################################################

View File

@ -52,6 +52,39 @@ self: super: let
});
};
removeUnknownConfigureFlags = f: with self.lib;
remove "--disable-shared"
(remove "--enable-static" f);
ocamlFixPackage = b:
b.overrideAttrs (o: {
configurePlatforms = [ ];
configureFlags = removeUnknownConfigureFlags (o.configureFlags or [ ]);
buildInputs = o.buildInputs ++ o.nativeBuildInputs or [ ];
propagatedNativeBuildInputs = o.propagatedBuildInputs or [ ];
});
ocamlStaticAdapter = _: super:
self.lib.mapAttrs
(_: p: if p ? overrideAttrs then ocamlFixPackage p else p)
super
// {
lablgtk = null; # Currently xlibs cause infinite recursion
ocaml = ((super.ocaml.override { useX11 = false; }).overrideAttrs (o: {
configurePlatforms = [ ];
dontUpdateAutotoolsGnuConfigScripts = true;
})).overrideDerivation (o: {
preConfigure = ''
configureFlagsArray+=("-cc" "$CC" "-as" "$AS" "-partialld" "$LD -r")
'';
configureFlags = (removeUnknownConfigureFlags o.configureFlags) ++ [
"--no-shared-libs"
"-host ${o.stdenv.hostPlatform.config}"
"-target ${o.stdenv.targetPlatform.config}"
];
});
};
in {
stdenv = foldl (flip id) super.stdenv staticAdapters;
gcc49Stdenv = foldl (flip id) super.gcc49Stdenv staticAdapters;
@ -172,6 +205,10 @@ in {
};
};
kmod = super.kmod.override {
withStatic = true;
};
curl = super.curl.override {
# a very sad story: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=439039
gssSupport = false;
@ -196,5 +233,9 @@ in {
};
};
ocaml-ng = self.lib.mapAttrs (_: set:
if set ? overrideScope' then set.overrideScope' ocamlStaticAdapter else set
) super.ocaml-ng;
python27 = super.python27.override { static = true; };
}