nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ stdenv
2, lib
3, fetchurl
4, glib
5, flex
6, bison
7, meson
8, ninja
9, gtk-doc
10, docbook-xsl-nons
11, docbook_xml_dtd_43
12, docbook_xml_dtd_45
13, pkg-config
14, libffi
15, python3
16, cctools
17, cairo
18, gnome
19, substituteAll
20, buildPackages
21, gobject-introspection-unwrapped
22, nixStoreDir ? builtins.storeDir
23, x11Support ? true
24, testers
25}:
26
27# now that gobject-introspection creates large .gir files (eg gtk3 case)
28# it may be worth thinking about using multiple derivation outputs
29# In that case its about 6MB which could be separated
30
31let
32 pythonModules = pp: [
33 pp.mako
34 pp.markdown
35 ];
36in
37stdenv.mkDerivation (finalAttrs: {
38 pname = "gobject-introspection";
39 version = "1.76.1";
40
41 # outputs TODO: share/gobject-introspection-1.0/tests is needed during build
42 # by pygobject3 (and maybe others), but it's only searched in $out
43 outputs = [ "out" "dev" "devdoc" "man" ];
44 outputBin = "dev";
45
46 src = fetchurl {
47 url = "mirror://gnome/sources/gobject-introspection/${lib.versions.majorMinor finalAttrs.version}/gobject-introspection-${finalAttrs.version}.tar.xz";
48 sha256 = "GWF4v2Q0VQHc3E2EabNqpv6ASJNU7+cct8uKuCo3OL8=";
49 };
50
51 patches = [
52 # Make g-ir-scanner put absolute path to GIR files it generates
53 # so that programs can just dlopen them without having to muck
54 # with LD_LIBRARY_PATH environment variable.
55 (substituteAll {
56 src = ./absolute_shlib_path.patch;
57 inherit nixStoreDir;
58 })
59 ] ++ lib.optionals x11Support [
60 # Hardcode the cairo shared library path in the Cairo gir shipped with this package.
61 # https://github.com/NixOS/nixpkgs/issues/34080
62 (substituteAll {
63 src = ./absolute_gir_path.patch;
64 cairoLib = "${lib.getLib cairo}/lib";
65 })
66 ];
67
68 strictDeps = true;
69
70 nativeBuildInputs = [
71 meson
72 ninja
73 pkg-config
74 flex
75 bison
76 gtk-doc
77 docbook-xsl-nons
78 docbook_xml_dtd_45
79 # Build definition checks for the Python modules needed at runtime by importing them.
80 (buildPackages.python3.withPackages pythonModules)
81 finalAttrs.setupHook # move .gir files
82 # can't use canExecute, we need prebuilt when cross
83 ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ gobject-introspection-unwrapped ];
84
85 buildInputs = [
86 (python3.withPackages pythonModules)
87 ];
88
89 nativeCheckInputs = lib.optionals stdenv.isDarwin [
90 cctools # for otool
91 ];
92
93 propagatedBuildInputs = [
94 libffi
95 glib
96 ];
97
98 mesonFlags = [
99 "--datadir=${placeholder "dev"}/share"
100 "-Dcairo=disabled"
101 "-Dgtk_doc=${lib.boolToString (stdenv.hostPlatform == stdenv.buildPlatform)}"
102 ] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
103 "-Dgi_cross_ldd_wrapper=${substituteAll {
104 name = "g-ir-scanner-lddwrapper";
105 isExecutable = true;
106 src = ./wrappers/g-ir-scanner-lddwrapper.sh;
107 inherit (buildPackages) bash;
108 buildlddtree = "${buildPackages.pax-utils}/bin/lddtree";
109 }}"
110 "-Dgi_cross_binary_wrapper=${stdenv.hostPlatform.emulator buildPackages}"
111 # can't use canExecute, we need prebuilt when cross
112 ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
113 "-Dgi_cross_use_prebuilt_gi=true"
114 ];
115
116 doCheck = !stdenv.isAarch64;
117
118 # During configurePhase, two python scripts are generated and need this. See
119 # https://github.com/NixOS/nixpkgs/pull/98316#issuecomment-695785692
120 postConfigure = ''
121 patchShebangs tools/*
122 '';
123
124 postInstall = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
125 cp -r ${buildPackages.gobject-introspection-unwrapped.devdoc} $devdoc
126 # these are uncompiled c and header files which aren't installed when cross-compiling because
127 # code that installs them is in tests/meson.build which is only run when not cross-compiling
128 # pygobject3 needs them
129 cp -r ${buildPackages.gobject-introspection-unwrapped.dev}/share/gobject-introspection-1.0/tests $dev/share/gobject-introspection-1.0/tests
130 '';
131
132 preCheck = ''
133 # Our gobject-introspection patches make the shared library paths absolute
134 # in the GIR files. When running tests, the library is not yet installed,
135 # though, so we need to replace the absolute path with a local one during build.
136 # We are using a symlink that we will delete before installation.
137 mkdir -p $out/lib
138 ln -s $PWD/tests/scanner/libregress-1.0${stdenv.targetPlatform.extensions.sharedLibrary} $out/lib/libregress-1.0${stdenv.targetPlatform.extensions.sharedLibrary}
139 '';
140
141 postCheck = ''
142 rm $out/lib/libregress-1.0${stdenv.targetPlatform.extensions.sharedLibrary}
143 '';
144
145 setupHook = ./setup-hook.sh;
146
147 passthru = {
148 updateScript = gnome.updateScript {
149 packageName = "gobject-introspection";
150 versionPolicy = "odd-unstable";
151 };
152 tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
153 };
154
155 meta = with lib; {
156 description = "A middleware layer between C libraries and language bindings";
157 homepage = "https://gi.readthedocs.io/";
158 maintainers = teams.gnome.members ++ (with maintainers; [ lovek323 artturin ]);
159 pkgConfigModules = [ "gobject-introspection-1.0" ];
160 platforms = platforms.unix;
161 license = with licenses; [ gpl2 lgpl2 ];
162
163 longDescription = ''
164 GObject introspection is a middleware layer between C libraries (using
165 GObject) and language bindings. The C library can be scanned at compile
166 time and generate a metadata file, in addition to the actual native C
167 library. Then at runtime, language bindings can read this metadata and
168 automatically provide bindings to call into the C library.
169 '';
170 };
171})