Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / development / libraries / gobject-introspection / wrapper.nix
blob53b1a35f8212501257ba2428ad0f343168c4b638
1 { lib
2 , stdenv
3 , buildPackages
4 , targetPackages
5 , gobject-introspection-unwrapped
6 , ...
7 }@_args:
9 # to build, run
10 # `nix build ".#pkgsCross.aarch64-multiplatform.buildPackages.gobject-introspection"`
12 # a comment for both depsTargetTargetPropagated's
13 # add self to buildInputs to avoid needing to add gobject-introspection to buildInputs in addition to nativeBuildInputs
14 # builds use target-pkg-config to look for gobject-introspection instead of just looking for binaries in $PATH
16 let
17   # ensure that `.override` works
18   args = builtins.removeAttrs _args [ "buildPackages" "targetPackages" "gobject-introspection-unwrapped" ];
19   # passing this stdenv to `targetPackages...` breaks due to splicing not working in `.override``
20   argsForTarget = builtins.removeAttrs args [ "stdenv" ];
22   overriddenUnwrappedGir = gobject-introspection-unwrapped.override args;
23   # if we have targetPackages.gobject-introspection then propagate that
24   overridenTargetUnwrappedGir =
25     if targetPackages ? gobject-introspection-unwrapped
26     then targetPackages.gobject-introspection-unwrapped.override argsForTarget
27     else overriddenUnwrappedGir;
30 # wrap both pkgsCrossX.buildPackages.gobject-introspection and {pkgs,pkgsSomethingExecutableOnBuildSystem).buildPackages.gobject-introspection
31 if (!stdenv.hostPlatform.canExecute stdenv.targetPlatform) && stdenv.targetPlatform.emulatorAvailable buildPackages
32 then
33   overriddenUnwrappedGir.overrideAttrs
34     (previousAttrs:
35       {
37         pname = "gobject-introspection-wrapped";
38         passthru = previousAttrs.passthru // {
39           unwrapped = overriddenUnwrappedGir;
40         };
41         dontStrip = true;
42         depsTargetTargetPropagated = [ overridenTargetUnwrappedGir ];
43         buildCommand = ''
44           eval fixupPhase
45           ${lib.concatMapStrings (output: ''
46             mkdir -p ${"$" + "${output}"}
47             ${lib.getExe buildPackages.xorg.lndir} ${overriddenUnwrappedGir.${output}} ${"$" + "${output}"}
48           '') overriddenUnwrappedGir.outputs}
50           cp $dev/bin/g-ir-compiler $dev/bin/.g-ir-compiler-wrapped
51           cp $dev/bin/g-ir-scanner $dev/bin/.g-ir-scanner-wrapped
53           (
54             rm "$dev/bin/g-ir-compiler"
55             rm "$dev/bin/g-ir-scanner"
56             export bash="${buildPackages.bash}"
57             export emulator=${lib.escapeShellArg (stdenv.targetPlatform.emulator buildPackages)}
58             export emulatorwrapper="$dev/bin/g-ir-scanner-qemuwrapper"
59             export buildlddtree="${buildPackages.pax-utils}/bin/lddtree"
61             export targetgir="${lib.getDev overridenTargetUnwrappedGir}"
63             substituteAll "${./wrappers/g-ir-compiler.sh}" "$dev/bin/g-ir-compiler"
64             substituteAll "${./wrappers/g-ir-scanner.sh}" "$dev/bin/g-ir-scanner"
65             substituteAll "${./wrappers/g-ir-scanner-lddwrapper.sh}" "$dev/bin/g-ir-scanner-lddwrapper"
66             substituteAll "${./wrappers/g-ir-scanner-qemuwrapper.sh}" "$dev/bin/g-ir-scanner-qemuwrapper"
67             chmod +x $dev/bin/g-ir-compiler
68             chmod +x $dev/bin/g-ir-scanner*
69           )
70         ''
71         # when cross-compiling and using the wrapper then when a package looks up the g_ir_X
72         # variable with pkg-config they'll get the host version which can't be run
73         # override the variable to use the absolute path to g_ir_X in PATH which can be run
74         + ''
75           cat >> $dev/nix-support/setup-hook <<-'EOF'
76             override-pkg-config-gir-variables() {
77               PKG_CONFIG_GOBJECT_INTROSPECTION_1_0_G_IR_SCANNER="$(type -p g-ir-scanner)"
78               PKG_CONFIG_GOBJECT_INTROSPECTION_1_0_G_IR_COMPILER="$(type -p g-ir-compiler)"
79               PKG_CONFIG_GOBJECT_INTROSPECTION_1_0_G_IR_GENERATE="$(type -p g-ir-generate)"
80               export PKG_CONFIG_GOBJECT_INTROSPECTION_1_0_G_IR_SCANNER
81               export PKG_CONFIG_GOBJECT_INTROSPECTION_1_0_G_IR_COMPILER
82               export PKG_CONFIG_GOBJECT_INTROSPECTION_1_0_G_IR_GENERATE
83             }
85             preConfigureHooks+=(override-pkg-config-gir-variables)
86           EOF
87         '';
88       })
89 else
90   overriddenUnwrappedGir.overrideAttrs (previousAttrs:
91     {
92       pname = "gobject-introspection-wrapped";
93       passthru = previousAttrs.passthru // {
94         unwrapped = overriddenUnwrappedGir;
95       };
96       dontStrip = true;
97       depsTargetTargetPropagated = [ overridenTargetUnwrappedGir ];
98       buildCommand = ''
99         eval fixupPhase
100         ${lib.concatMapStrings (output: ''
101           mkdir -p ${"$" + "${output}"}
102           ${lib.getExe buildPackages.xorg.lndir} ${overriddenUnwrappedGir.${output}} ${"$" + "${output}"}
103         '') overriddenUnwrappedGir.outputs}
104       '';
105     })