1{
2 stdenv,
3 lib,
4 fetchFromGitLab,
5 pkg-config,
6 autoreconfHook,
7 libintl,
8 python,
9 gettext,
10 ncurses,
11 findXMLCatalogs,
12 libiconv,
13 # Python limits cross-compilation to an allowlist of host OSes.
14 # https://github.com/python/cpython/blob/dfad678d7024ab86d265d84ed45999e031a03691/configure.ac#L534-L562
15 pythonSupport ?
16 enableShared
17 && (
18 stdenv.hostPlatform == stdenv.buildPlatform
19 || stdenv.hostPlatform.isCygwin
20 || stdenv.hostPlatform.isLinux
21 || stdenv.hostPlatform.isWasi
22 ),
23 icuSupport ? false,
24 icu,
25 zlibSupport ? false,
26 zlib,
27 enableShared ? !stdenv.hostPlatform.isMinGW && !stdenv.hostPlatform.isStatic,
28 enableStatic ? !enableShared,
29 gnome,
30 testers,
31 enableHttp ? false,
32}:
33
34stdenv.mkDerivation (finalAttrs: {
35 pname = "libxml2";
36 version = "2.14.4-unstable-2025-06-20";
37
38 outputs = [
39 "bin"
40 "dev"
41 "out"
42 "devdoc"
43 ]
44 ++ lib.optional pythonSupport "py"
45 ++ lib.optional (enableStatic && enableShared) "static";
46 outputMan = "bin";
47
48 src = fetchFromGitLab {
49 domain = "gitlab.gnome.org";
50 owner = "GNOME";
51 repo = "libxml2";
52 rev = "356542324fa439de544b5e419b91ae68d42c306c"; # some bugfixes right behind 2.14.4
53 hash = "sha256-0jo08ECX+oP7Ekjgw3ZgOh+fSiNjlbjoZc4p3PqomJA=";
54 };
55
56 patches = [
57 # Unmerged ABI-breaking patch required to fix the following security issues:
58 # - https://gitlab.gnome.org/GNOME/libxslt/-/issues/139
59 # - https://gitlab.gnome.org/GNOME/libxslt/-/issues/140
60 # See also https://gitlab.gnome.org/GNOME/libxml2/-/issues/906
61 # Source: https://github.com/chromium/chromium/blob/4fb4ae8ce3daa399c3d8ca67f2dfb9deffcc7007/third_party/libxml/chromium/xml-attr-extra.patch
62 ./xml-attr-extra.patch
63 ];
64
65 strictDeps = true;
66
67 nativeBuildInputs = [
68 pkg-config
69 autoreconfHook
70 ];
71
72 buildInputs =
73 lib.optionals pythonSupport [
74 python
75 ]
76 ++ lib.optionals (pythonSupport && python ? isPy2 && python.isPy2) [
77 gettext
78 ]
79 ++ lib.optionals (pythonSupport && python ? isPy3 && python.isPy3) [
80 ncurses
81 ]
82 ++ lib.optionals (stdenv.hostPlatform.isDarwin && pythonSupport && python ? isPy2 && python.isPy2) [
83 libintl
84 ]
85 ++ lib.optionals zlibSupport [
86 zlib
87 ];
88
89 propagatedBuildInputs = [
90 findXMLCatalogs
91 ]
92 ++ lib.optionals (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isMinGW) [
93 libiconv
94 ]
95 ++ lib.optionals icuSupport [
96 icu
97 ];
98
99 configureFlags = [
100 "--exec-prefix=${placeholder "dev"}"
101 (lib.enableFeature enableStatic "static")
102 (lib.enableFeature enableShared "shared")
103 (lib.withFeature icuSupport "icu")
104 (lib.withFeature pythonSupport "python")
105 (lib.optionalString pythonSupport "PYTHON=${python.pythonOnBuildForHost.interpreter}")
106 ]
107 # avoid rebuilds, can be merged into list in version bumps
108 ++ lib.optional enableHttp "--with-http"
109 ++ lib.optional zlibSupport "--with-zlib";
110
111 installFlags = lib.optionals pythonSupport [
112 "pythondir=\"${placeholder "py"}/${python.sitePackages}\""
113 "pyexecdir=\"${placeholder "py"}/${python.sitePackages}\""
114 ];
115
116 enableParallelBuilding = true;
117
118 doCheck = (stdenv.hostPlatform == stdenv.buildPlatform) && stdenv.hostPlatform.libc != "musl";
119 preCheck = lib.optional stdenv.hostPlatform.isDarwin ''
120 export DYLD_LIBRARY_PATH="$PWD/.libs:$DYLD_LIBRARY_PATH"
121 '';
122
123 preConfigure = lib.optionalString (lib.versionAtLeast stdenv.hostPlatform.darwinMinVersion "11") ''
124 MACOSX_DEPLOYMENT_TARGET=10.16
125 '';
126
127 preInstall = lib.optionalString pythonSupport ''
128 substituteInPlace python/libxml2mod.la --replace-fail "$dev/${python.sitePackages}" "$py/${python.sitePackages}"
129 '';
130
131 postFixup = ''
132 moveToOutput bin/xml2-config "$dev"
133 moveToOutput lib/xml2Conf.sh "$dev"
134 ''
135 + lib.optionalString (enableStatic && enableShared) ''
136 moveToOutput lib/libxml2.a "$static"
137 '';
138
139 passthru = {
140 inherit pythonSupport;
141
142 updateScript = gnome.updateScript {
143 packageName = "libxml2";
144 versionPolicy = "none";
145 };
146 tests = {
147 pkg-config = testers.hasPkgConfigModules {
148 package = finalAttrs.finalPackage;
149 };
150 cmake-config = testers.hasCmakeConfigModules {
151 moduleNames = [ "LibXml2" ];
152 package = finalAttrs.finalPackage;
153 };
154 };
155 };
156
157 meta = with lib; {
158 homepage = "https://gitlab.gnome.org/GNOME/libxml2";
159 description = "XML parsing library for C";
160 license = licenses.mit;
161 platforms = platforms.all;
162 maintainers = with maintainers; [ jtojnar ];
163 pkgConfigModules = [ "libxml-2.0" ];
164 };
165})