Merge pull request #176464 from Artturin/gobjecfix

This commit is contained in:
Artturi 2022-06-12 17:32:49 +03:00 committed by GitHub
commit ce62ff7bdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 142 additions and 16 deletions

View file

@ -153,6 +153,24 @@ Add the following to your `mkDerivation` invocation.
doCheck = stdenv.hostPlatform == stdenv.buildPlatform;
```
#### Package using Meson needs to run binaries for the host platform during build. {#cross-meson-runs-host-code}
Add `mesonEmulatorHook` cross conditionally to `nativeBuildInputs`.
e.g.
```
nativeBuildInputs = [
meson
] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
mesonEmulatorHook
];
```
Example of an error which this fixes.
`[Errno 8] Exec format error: './gdk3-scan'`
## Cross-building packages {#sec-cross-usage}
Nixpkgs can be instantiated with `localSystem` alone, in which case there is no cross-compiling and everything is built by and for that system, or also with `crossSystem`, in which case packages run on the latter, but all building happens on the former. Both parameters take the same schema as the 3 (build, host, and target) platforms defined in the previous section. As mentioned above, `lib.systems.examples` has some platforms which are used as arguments for these parameters in practice. You can use them programmatically, or on the command line:

View file

@ -17,6 +17,8 @@
, cairo
, gnome
, substituteAll
, buildPackages
, gobject-introspection-unwrapped
, nixStoreDir ? builtins.storeDir
, x11Support ? true
}:
@ -67,7 +69,7 @@ stdenv.mkDerivation rec {
docbook_xml_dtd_45
python3
setupHook # move .gir files
];
] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ gobject-introspection-unwrapped ];
buildInputs = [
python3
@ -86,7 +88,11 @@ stdenv.mkDerivation rec {
"--datadir=${placeholder "dev"}/share"
"-Ddoctool=disabled"
"-Dcairo=disabled"
"-Dgtk_doc=true"
"-Dgtk_doc=${lib.boolToString (stdenv.hostPlatform == stdenv.buildPlatform)}"
] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"-Dgi_cross_ldd_wrapper=${buildPackages.prelink}/bin/prelink-rtld"
"-Dgi_cross_use_prebuilt_gi=true"
"-Dgi_cross_binary_wrapper=${stdenv.hostPlatform.emulator buildPackages}"
];
doCheck = !stdenv.isAarch64;
@ -97,6 +103,10 @@ stdenv.mkDerivation rec {
patchShebangs tools/*
'';
postInstall = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
cp -r ${buildPackages.gobject-introspection-unwrapped.devdoc} $devdoc
'';
preCheck = ''
# Our gobject-introspection patches make the shared library paths absolute
# in the GIR files. When running tests, the library is not yet installed,
@ -122,7 +132,7 @@ stdenv.mkDerivation rec {
meta = with lib; {
description = "A middleware layer between C libraries and language bindings";
homepage = "https://gi.readthedocs.io/";
maintainers = teams.gnome.members ++ (with maintainers; [ lovek323 ]);
maintainers = teams.gnome.members ++ (with maintainers; [ lovek323 artturin ]);
platforms = platforms.unix;
license = with licenses; [ gpl2 lgpl2 ];

View file

@ -0,0 +1,29 @@
{ lib
, stdenv
, buildPackages
, gobject-introspection-unwrapped
, targetPackages
}:
# to build, run
# `nix build ".#pkgsCross.aarch64-multiplatform.buildPackages.gobject-introspection"`
gobject-introspection-unwrapped.overrideAttrs (_previousAttrs: {
pname = "gobject-introspection-wrapped";
postFixup = ''
mv $dev/bin/g-ir-compiler $dev/bin/.g-ir-compiler-wrapped
mv $dev/bin/g-ir-scanner $dev/bin/.g-ir-scanner-wrapped
(
export bash="${buildPackages.bash}/bin/bash"
export emulator=${lib.escapeShellArg (stdenv.targetPlatform.emulator buildPackages)}
export buildprelink="${buildPackages.prelink}/bin/prelink-rtld"
export targetgir="${lib.getDev targetPackages.gobject-introspection-unwrapped}"
substituteAll "${./wrappers/g-ir-compiler.sh}" "$dev/bin/g-ir-compiler"
substituteAll "${./wrappers/g-ir-scanner.sh}" "$dev/bin/g-ir-scanner"
chmod +x "$dev/bin/g-ir-compiler"
chmod +x "$dev/bin/g-ir-scanner"
)
'';
})

View file

@ -0,0 +1,4 @@
#! @bash@
# shellcheck shell=bash
exec @emulator@ @targetgir@/bin/g-ir-compiler "$@"

View file

@ -0,0 +1,7 @@
#! @bash@
# shellcheck shell=bash
exec @dev@/bin/.g-ir-scanner-wrapped \
--use-binary-wrapper=@emulator@ \
--use-ldd-wrapper=@buildprelink@ \
"$@"

View file

@ -0,0 +1,5 @@
add_meson_exe_wrapper_cross_flag() {
mesonFlagsArray+=(--cross-file=@crossFile@)
}
preConfigureHooks+=(add_meson_exe_wrapper_cross_flag)

View file

@ -1,22 +1,54 @@
{ lib, stdenv, fetchurl, libelf }:
{ stdenv
, lib
, fetchgit
, autoreconfHook
, libelf
, libiberty
}:
stdenv.mkDerivation rec {
pname = "prelink";
version = "20130503";
version = "unstable-2019-06-24";
buildInputs = [
libelf stdenv.cc.libc (lib.getOutput "static" stdenv.cc.libc)
src = fetchgit {
url = "https://git.yoctoproject.org/git/prelink-cross";
branchName = "cross_prelink";
rev = "f9975537dbfd9ade0fc813bd5cf5fcbe41753a37";
sha256 = "sha256-O9/oZooLRyUBBZX3SFcB6LFMmi2vQqkUlqtZnrq5oZc=";
};
strictDeps = true;
configurePlatforms = [ "build" "host" ];
nativeBuildInputs = [
autoreconfHook
];
src = fetchurl {
url = "https://people.redhat.com/jakub/prelink/prelink-${version}.tar.bz2";
sha256 = "1w20f6ilqrz8ca51qhrn1n13h7q1r34k09g33d6l2vwvbrhcffb3";
};
buildInputs = [
stdenv.cc.libc
libelf
libiberty
];
meta = {
homepage = "https://people.redhat.com/jakub/prelink/";
license = "GPL";
# Disable some tests because they're failing
preCheck = ''
for f in reloc2 layout1 unprel1 tls3 cxx2 cxx3 quick1 quick2 deps1 deps2; do
echo '#' > testsuite/''${f}.sh
done
patchShebangs --build testsuite
'';
# most tests fail
doCheck = !stdenv.isAarch64;
enableParallelBuilding = true;
meta = with lib;{
description = "ELF prelinking utility to speed up dynamic linking";
platforms = lib.platforms.linux;
homepage = "https://wiki.yoctoproject.org/wiki/Cross-Prelink";
license = licenses.gpl2Plus;
platforms = platforms.linux;
maintainers = with maintainers; [ artturin ];
};
}

View file

@ -3965,6 +3965,24 @@ with pkgs;
meson = callPackage ../development/tools/build-managers/meson { };
# while building documentation meson may want to run binaries for host
# which needs an emulator
# example of an error which this fixes
# [Errno 8] Exec format error: './gdk3-scan'
mesonEmulatorHook =
if (stdenv.buildPlatform != stdenv.targetPlatform) then
makeSetupHook
{
name = "mesonEmulatorHook";
substitutions = {
crossFile = writeText "cross-file.conf" ''
[binaries]
exe_wrapper = ${lib.escapeShellArg (stdenv.targetPlatform.emulator buildPackages)}
'';
};
} ../development/tools/build-managers/meson/emulator-hook.sh
else throw "mesonEmulatorHook has to be in a cross conditional i.e. (stdenv.buildPlatform != stdenv.hostPlatform)";
meson-tools = callPackage ../misc/meson-tools { };
metabase = callPackage ../servers/metabase { };
@ -17630,7 +17648,10 @@ with pkgs;
gns3-gui = gns3Packages.guiStable;
gns3-server = gns3Packages.serverStable;
gobject-introspection = callPackage ../development/libraries/gobject-introspection {
gobject-introspection = if (stdenv.hostPlatform != stdenv.targetPlatform)
then callPackage ../development/libraries/gobject-introspection/wrapper.nix { } else gobject-introspection-unwrapped;
gobject-introspection-unwrapped = callPackage ../development/libraries/gobject-introspection {
nixStoreDir = config.nix.storeDir or builtins.storeDir;
inherit (darwin) cctools;
};