1{ stdenv, lib, fetchurl, fetchpatch
2, zlib, xz, libintl, python, gettext, ncurses, findXMLCatalogs
3, libiconv
4, pythonSupport ? enableShared && stdenv.buildPlatform == stdenv.hostPlatform
5, icuSupport ? false, icu ? null
6, enableShared ? stdenv.hostPlatform.libc != "msvcrt" && !stdenv.hostPlatform.isStatic
7, enableStatic ? !enableShared
8}:
9
10stdenv.mkDerivation rec {
11 pname = "libxml2";
12 version = "2.9.12";
13
14 src = fetchurl {
15 url = "http://xmlsoft.org/sources/${pname}-${version}.tar.gz";
16 sha256 = "14hxwzmf5xqppx77z7i0ni9lpzg1a84dqpf8j8l1fvy570g6imn8";
17 };
18 patches = [
19 # Upstream bugs:
20 # https://bugzilla.gnome.org/show_bug.cgi?id=789714
21 # https://gitlab.gnome.org/GNOME/libxml2/issues/64
22 # Patch from https://bugzilla.opensuse.org/show_bug.cgi?id=1065270 ,
23 # but only the UTF-8 part.
24 # Can also be mitigated by fixing malformed XML inputs, such as in
25 # https://gitlab.gnome.org/GNOME/gnumeric/merge_requests/3 .
26 # Other discussion:
27 # https://github.com/itstool/itstool/issues/22
28 # https://github.com/NixOS/nixpkgs/pull/63174
29 # https://github.com/NixOS/nixpkgs/pull/72342
30 ./utf8-xmlErrorFuncHandler.patch
31
32 # Work around lxml API misuse.
33 # https://gitlab.gnome.org/GNOME/libxml2/issues/255
34 (fetchpatch {
35 url = "https://gitlab.gnome.org/GNOME/libxml2/commit/85b1792e37b131e7a51af98a37f92472e8de5f3f.patch";
36 sha256 = "epqlNs2S0Zczox3KyCB6R2aJKh87lXydlZ0x6tLHweE=";
37 })
38 ];
39
40 outputs = [ "bin" "dev" "out" "man" "doc" ]
41 ++ lib.optional pythonSupport "py"
42 ++ lib.optional (enableStatic && enableShared) "static";
43
44 strictDeps = true;
45
46 buildInputs = lib.optional pythonSupport python
47 ++ lib.optional (pythonSupport && python?isPy2 && python.isPy2) gettext
48 ++ lib.optional (pythonSupport && python?isPy3 && python.isPy3) ncurses
49 ++ lib.optional (stdenv.isDarwin &&
50 pythonSupport && python?isPy2 && python.isPy2) libintl
51 # Libxml2 has an optional dependency on liblzma. However, on impure
52 # platforms, it may end up using that from /usr/lib, and thus lack a
53 # RUNPATH for that, leading to undefined references for its users.
54 ++ lib.optional stdenv.isFreeBSD xz;
55
56 propagatedBuildInputs = [ zlib findXMLCatalogs ]
57 ++ lib.optional stdenv.isDarwin libiconv
58 ++ lib.optional icuSupport icu;
59
60 configureFlags = [
61 "--exec_prefix=$dev"
62 (lib.enableFeature enableStatic "static")
63 (lib.enableFeature enableShared "shared")
64 (lib.withFeature icuSupport "icu")
65 (lib.withFeatureAs pythonSupport "python" python)
66 ];
67
68 preConfigure = lib.optionalString (lib.versionAtLeast stdenv.hostPlatform.darwinMinVersion "11") ''
69 MACOSX_DEPLOYMENT_TARGET=10.16
70 '';
71
72 enableParallelBuilding = true;
73
74 # disable test that's problematic with newer pythons: see
75 # https://mail.gnome.org/archives/xml/2017-August/msg00014.html
76 preCheck = lib.optionalString (pythonSupport && !(python?pythonOlder && python.pythonOlder "3.5")) ''
77 echo "" > python/tests/tstLastError.py
78 '';
79
80 doCheck = (stdenv.hostPlatform == stdenv.buildPlatform) && !stdenv.isDarwin &&
81 stdenv.hostPlatform.libc != "musl";
82
83 preInstall = lib.optionalString pythonSupport
84 ''substituteInPlace python/libxml2mod.la --replace "${python}" "$py"'';
85 installFlags = lib.optional pythonSupport
86 "pythondir=\"${placeholder "py"}/lib/${python.libPrefix}/site-packages\"";
87
88 postFixup = ''
89 moveToOutput bin/xml2-config "$dev"
90 moveToOutput lib/xml2Conf.sh "$dev"
91 moveToOutput share/man/man1 "$bin"
92 '' + lib.optionalString (enableStatic && enableShared) ''
93 moveToOutput lib/libxml2.a "$static"
94 '';
95
96 passthru = { inherit version; pythonSupport = pythonSupport; };
97
98 meta = {
99 homepage = "http://xmlsoft.org/";
100 description = "An XML parsing library for C";
101 license = lib.licenses.mit;
102 platforms = lib.platforms.all;
103 maintainers = [ lib.maintainers.eelco ];
104 };
105}