12 # Python limits cross-compilation to an allowlist of host OSes.
13 # https://github.com/python/cpython/blob/dfad678d7024ab86d265d84ed45999e031a03691/configure.ac#L534-L562
14 , pythonSupport ? enableShared &&
15 (stdenv.hostPlatform == stdenv.buildPlatform || stdenv.hostPlatform.isCygwin || stdenv.hostPlatform.isLinux || stdenv.hostPlatform.isWasi)
18 , enableShared ? !stdenv.hostPlatform.isMinGW && !stdenv.hostPlatform.isStatic
19 , enableStatic ? !enableShared
25 stdenv.mkDerivation (finalAttrs: {
29 outputs = [ "bin" "dev" "out" "devdoc" ]
30 ++ lib.optional pythonSupport "py"
31 ++ lib.optional (enableStatic && enableShared) "static";
35 url = "mirror://gnome/sources/libxml2/${lib.versions.majorMinor finalAttrs.version}/libxml2-${finalAttrs.version}.tar.xz";
36 hash = "sha256-ZdBC4cgBAkPmF++wKv2iC4XCFgrNv7y1smuAzsZRVlA=";
46 buildInputs = lib.optionals pythonSupport [
48 ] ++ lib.optionals (pythonSupport && python?isPy2 && python.isPy2) [
50 ] ++ lib.optionals (pythonSupport && python?isPy3 && python.isPy3) [
52 ] ++ lib.optionals (stdenv.hostPlatform.isDarwin && pythonSupport && python?isPy2 && python.isPy2) [
56 propagatedBuildInputs = [
58 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
60 ] ++ lib.optionals icuSupport [
65 "--exec-prefix=${placeholder "dev"}"
66 (lib.enableFeature enableStatic "static")
67 (lib.enableFeature enableShared "shared")
68 (lib.withFeature icuSupport "icu")
69 (lib.withFeature pythonSupport "python")
70 (lib.optionalString pythonSupport "PYTHON=${python.pythonOnBuildForHost.interpreter}")
71 ] ++ lib.optional enableHttp "--with-http";
73 installFlags = lib.optionals pythonSupport [
74 "pythondir=\"${placeholder "py"}/${python.sitePackages}\""
75 "pyexecdir=\"${placeholder "py"}/${python.sitePackages}\""
78 enableParallelBuilding = true;
81 (stdenv.hostPlatform == stdenv.buildPlatform) &&
82 stdenv.hostPlatform.libc != "musl";
83 preCheck = lib.optional stdenv.hostPlatform.isDarwin ''
84 export DYLD_LIBRARY_PATH="$PWD/.libs:$DYLD_LIBRARY_PATH"
87 preConfigure = lib.optionalString (lib.versionAtLeast stdenv.hostPlatform.darwinMinVersion "11") ''
88 MACOSX_DEPLOYMENT_TARGET=10.16
91 preInstall = lib.optionalString pythonSupport ''
92 substituteInPlace python/libxml2mod.la --replace-fail "$dev/${python.sitePackages}" "$py/${python.sitePackages}"
96 moveToOutput bin/xml2-config "$dev"
97 moveToOutput lib/xml2Conf.sh "$dev"
98 '' + lib.optionalString (enableStatic && enableShared) ''
99 moveToOutput lib/libxml2.a "$static"
103 inherit pythonSupport;
105 updateScript = gnome.updateScript {
106 packageName = "libxml2";
107 versionPolicy = "none";
110 pkg-config = testers.hasPkgConfigModules {
111 package = finalAttrs.finalPackage;
117 homepage = "https://gitlab.gnome.org/GNOME/libxml2";
118 description = "XML parsing library for C";
119 license = licenses.mit;
120 platforms = platforms.all;
121 maintainers = with maintainers; [ jtojnar ];
122 pkgConfigModules = [ "libxml-2.0" ];