at 23.11-beta 298 lines 10 kB view raw
1{ config 2, lib 3, stdenv 4, fetchurl 5, fetchpatch2 6, gettext 7, meson 8, ninja 9, pkg-config 10, perl 11, python3 12, libiconv, zlib, libffi, pcre2, libelf, gnome, libselinux, bash, gnum4, gtk-doc, docbook_xsl, docbook_xml_dtd_45, libxslt 13# use util-linuxMinimal to avoid circular dependency (util-linux, systemd, glib) 14, util-linuxMinimal ? null 15, buildPackages 16 17# this is just for tests (not in the closure of any regular package) 18, coreutils, dbus, libxml2, tzdata 19, desktop-file-utils, shared-mime-info 20, darwin 21, makeHardcodeGsettingsPatch 22, testers 23}: 24 25assert stdenv.isLinux -> util-linuxMinimal != null; 26 27# TODO: 28# * Make it build without python 29# Problem: an example (test?) program needs it. 30# Possible solution: disable compilation of this example somehow 31# Reminder: add 'sed -e 's@python2\.[0-9]@python@' -i 32# $out/bin/gtester-report' to postInstall if this is solved 33/* 34 * Use --enable-installed-tests for GNOME-related packages, 35 and use them as a separately installed tests run by Hydra 36 (they should test an already installed package) 37 https://wiki.gnome.org/GnomeGoals/InstalledTests 38 * Support org.freedesktop.Application, including D-Bus activation from desktop files 39*/ 40let 41 # Some packages don't get "Cflags" from pkg-config correctly 42 # and then fail to build when directly including like <glib/...>. 43 # This is intended to be run in postInstall of any package 44 # which has $out/include/ containing just some disjunct directories. 45 flattenInclude = '' 46 for dir in "''${!outputInclude}"/include/*; do 47 cp -r "$dir"/* "''${!outputInclude}/include/" 48 rm -r "$dir" 49 ln -s . "$dir" 50 done 51 ln -sr -t "''${!outputInclude}/include/" "''${!outputInclude}"/lib/*/include/* 2>/dev/null || true 52 ''; 53 54 buildDocs = stdenv.hostPlatform == stdenv.buildPlatform && !stdenv.hostPlatform.isStatic; 55in 56 57stdenv.mkDerivation (finalAttrs: { 58 pname = "glib"; 59 version = "2.76.4"; 60 61 src = fetchurl { 62 url = "mirror://gnome/sources/glib/${lib.versions.majorMinor finalAttrs.version}/glib-${finalAttrs.version}.tar.xz"; 63 sha256 = "WloZHJaDbhZqd3H36myisAacYDx9o8uhzTjRaUo5Xdo="; 64 }; 65 66 patches = lib.optionals stdenv.isDarwin [ 67 ./darwin-compilation.patch 68 ] ++ lib.optionals stdenv.hostPlatform.isMusl [ 69 ./quark_init_on_demand.patch 70 ./gobject_init_on_demand.patch 71 ] ++ [ 72 ./glib-appinfo-watch.patch 73 ./schema-override-variable.patch 74 75 # Add support for Pantheon’s terminal emulator. 76 ./elementary-terminal-support.patch 77 78 # GLib contains many binaries used for different purposes; 79 # we will install them to different outputs: 80 # 1. Tools for desktop environment ($bin) 81 # * gapplication (non-darwin) 82 # * gdbus 83 # * gio 84 # * gio-launch-desktop (symlink to $out) 85 # * gsettings 86 # 2. Development/build tools ($dev) 87 # * gdbus-codegen 88 # * gio-querymodules 89 # * glib-compile-resources 90 # * glib-compile-schemas 91 # * glib-genmarshal 92 # * glib-gettextize 93 # * glib-mkenums 94 # * gobject-query 95 # * gresource 96 # * gtester 97 # * gtester-report 98 # 3. Tools for desktop environment that cannot go to $bin due to $out depending on them ($out) 99 # * gio-launch-desktop 100 ./split-dev-programs.patch 101 102 # Disable flaky test. 103 # https://gitlab.gnome.org/GNOME/glib/-/issues/820 104 ./skip-timer-test.patch 105 ]; 106 107 outputs = [ "bin" "out" "dev" "devdoc" ]; 108 109 setupHook = ./setup-hook.sh; 110 111 buildInputs = [ 112 libelf 113 finalAttrs.setupHook 114 pcre2 115 ] ++ lib.optionals (!stdenv.hostPlatform.isWindows) [ 116 bash gnum4 # install glib-gettextize and m4 macros for other apps to use 117 ] ++ lib.optionals stdenv.isLinux [ 118 libselinux 119 util-linuxMinimal # for libmount 120 ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ 121 AppKit Carbon Cocoa CoreFoundation CoreServices Foundation 122 ]) ++ lib.optionals buildDocs [ 123 # Note: this needs to be both in buildInputs and nativeBuildInputs. The 124 # Meson gtkdoc module uses find_program to look it up (-> build dep), but 125 # glib's own Meson configuration uses the host pkg-config to find its 126 # version (-> host dep). We could technically go and fix this in glib, add 127 # pkg-config to depsBuildBuild, but this would be a futile exercise since 128 # Meson's gtkdoc integration does not support cross compilation[1] anyway 129 # and this derivation disables the docs build when cross compiling. 130 # 131 # [1] https://github.com/mesonbuild/meson/issues/2003 132 gtk-doc 133 ]; 134 135 strictDeps = true; 136 137 nativeBuildInputs = [ 138 meson 139 ninja 140 pkg-config 141 perl 142 python3 143 gettext 144 libxslt 145 docbook_xsl 146 ] ++ lib.optionals buildDocs [ 147 gtk-doc 148 docbook_xml_dtd_45 149 libxml2 150 ]; 151 152 propagatedBuildInputs = [ zlib libffi gettext libiconv ]; 153 154 mesonFlags = [ 155 # Avoid the need for gobject introspection binaries in PATH in cross-compiling case. 156 # Instead we just copy them over from the native output. 157 "-Dgtk_doc=${lib.boolToString buildDocs}" 158 "-Dnls=enabled" 159 "-Ddevbindir=${placeholder "dev"}/bin" 160 ] ++ lib.optionals (!stdenv.isDarwin) [ 161 "-Dman=true" # broken on Darwin 162 ] ++ lib.optionals stdenv.isFreeBSD [ 163 "-Db_lundef=false" 164 "-Dxattr=false" 165 ]; 166 167 env.NIX_CFLAGS_COMPILE = toString [ 168 "-Wno-error=nonnull" 169 # Default for release buildtype but passed manually because 170 # we're using plain 171 "-DG_DISABLE_CAST_CHECKS" 172 ]; 173 174 postPatch = '' 175 chmod +x gio/tests/gengiotypefuncs.py 176 patchShebangs gio/tests/gengiotypefuncs.py 177 chmod +x docs/reference/gio/concat-files-helper.py 178 patchShebangs docs/reference/gio/concat-files-helper.py 179 patchShebangs glib/gen-unicode-tables.pl 180 patchShebangs glib/tests/gen-casefold-txt.py 181 patchShebangs glib/tests/gen-casemap-txt.py 182 patchShebangs tools/gen-visibility-macros.py 183 184 # Needs machine-id, comment the test 185 sed -e '/\/gdbus\/codegen-peer-to-peer/ s/^\/*/\/\//' -i gio/tests/gdbus-peer.c 186 sed -e '/g_test_add_func/ s/^\/*/\/\//' -i gio/tests/gdbus-address-get-session.c 187 # All gschemas fail to pass the test, upstream bug? 188 sed -e '/g_test_add_data_func/ s/^\/*/\/\//' -i gio/tests/gschema-compile.c 189 # Cannot reproduce the failing test_associations on hydra 190 sed -e '/\/appinfo\/associations/d' -i gio/tests/appinfo.c 191 # Needed because of libtool wrappers 192 sed -e '/g_subprocess_launcher_set_environ (launcher, envp);/a g_subprocess_launcher_setenv (launcher, "PATH", g_getenv("PATH"), TRUE);' -i gio/tests/gsubprocess.c 193 '' + lib.optionalString stdenv.hostPlatform.isWindows '' 194 substituteInPlace gio/win32/meson.build \ 195 --replace "libintl, " "" 196 ''; 197 198 postConfigure = '' 199 patchShebangs gio/gdbus-2.0/codegen/gdbus-codegen gobject/glib-{genmarshal,mkenums} 200 ''; 201 202 DETERMINISTIC_BUILD = 1; 203 204 postInstall = '' 205 moveToOutput "share/glib-2.0" "$dev" 206 substituteInPlace "$dev/bin/gdbus-codegen" --replace "$out" "$dev" 207 sed -i "$dev/bin/glib-gettextize" -e "s|^gettext_dir=.*|gettext_dir=$dev/share/glib-2.0/gettext|" 208 209 # This file is *included* in gtk3 and would introduce runtime reference via __FILE__. 210 sed '1i#line 1 "glib-${finalAttrs.version}/include/glib-2.0/gobject/gobjectnotifyqueue.c"' \ 211 -i "$dev"/include/glib-2.0/gobject/gobjectnotifyqueue.c 212 for i in $bin/bin/*; do 213 moveToOutput "share/bash-completion/completions/''${i##*/}" "$bin" 214 done 215 for i in $dev/bin/*; do 216 moveToOutput "share/bash-completion/completions/''${i##*/}" "$dev" 217 done 218 '' + lib.optionalString (!buildDocs) '' 219 cp -r ${buildPackages.glib.devdoc} $devdoc 220 ''; 221 222 # Move man pages to the same output as their binaries (needs to be 223 # done after preFixupHooks which moves man pages too - in 224 # _multioutDocs) 225 postFixup = '' 226 for i in $dev/bin/*; do 227 moveToOutput "share/man/man1/''${i##*/}.1.*" "$dev" 228 done 229 ''; 230 231 nativeCheckInputs = [ tzdata desktop-file-utils shared-mime-info ]; 232 233 preCheck = lib.optionalString finalAttrs.doCheck or config.doCheckByDefault or false '' 234 export LD_LIBRARY_PATH="$NIX_BUILD_TOP/glib-${finalAttrs.version}/glib/.libs''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH" 235 export TZDIR="${tzdata}/share/zoneinfo" 236 export XDG_CACHE_HOME="$TMP" 237 export XDG_RUNTIME_HOME="$TMP" 238 export HOME="$TMP" 239 export XDG_DATA_DIRS="${desktop-file-utils}/share:${shared-mime-info}/share" 240 export G_TEST_DBUS_DAEMON="${dbus}/bin/dbus-daemon" 241 export PATH="$PATH:$(pwd)/gobject" 242 echo "PATH=$PATH" 243 ''; 244 245 separateDebugInfo = stdenv.isLinux; 246 247 passthru = rec { 248 gioModuleDir = "lib/gio/modules"; 249 250 makeSchemaDataDirPath = dir: name: "${dir}/share/gsettings-schemas/${name}"; 251 makeSchemaPath = dir: name: "${makeSchemaDataDirPath dir name}/glib-2.0/schemas"; 252 getSchemaPath = pkg: makeSchemaPath pkg pkg.name; 253 getSchemaDataDirPath = pkg: makeSchemaDataDirPath pkg pkg.name; 254 255 tests = { 256 withChecks = finalAttrs.finalPackage.overrideAttrs (_: { doCheck = true; }); 257 pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; 258 }; 259 260 inherit flattenInclude; 261 updateScript = gnome.updateScript { 262 packageName = "glib"; 263 versionPolicy = "odd-unstable"; 264 }; 265 266 mkHardcodeGsettingsPatch = 267 { 268 src, 269 glib-schema-to-var, 270 }: 271 builtins.trace 272 "glib.mkHardcodeGsettingsPatch is deprecated, please use makeHardcodeGsettingsPatch instead" 273 (makeHardcodeGsettingsPatch { 274 inherit src; 275 schemaIdToVariableMapping = glib-schema-to-var; 276 }); 277 }; 278 279 meta = with lib; { 280 description = "C library of programming buildings blocks"; 281 homepage = "https://wiki.gnome.org/Projects/GLib"; 282 license = licenses.lgpl21Plus; 283 maintainers = teams.gnome.members ++ (with maintainers; [ lovek323 raskin ]); 284 pkgConfigModules = [ 285 "gio-2.0" 286 "gobject-2.0" 287 "gthread-2.0" 288 ]; 289 platforms = platforms.unix; 290 291 longDescription = '' 292 GLib provides the core application building blocks for libraries 293 and applications written in C. It provides the core object 294 system used in GNOME, the main loop implementation, and a large 295 set of utility functions for strings and common data structures. 296 ''; 297 }; 298})