From 6e6292279e89ff6240c77159fec15970b0d5db7a Mon Sep 17 00:00:00 2001 From: Artturin Date: Tue, 7 Jun 2022 21:47:38 +0300 Subject: [PATCH 1/5] meson: add mesonEmulatorHook fixes building documentation while cross-compiling and other issues Exec format error: './gdk3-scan' added some simple documentation --- doc/stdenv/cross-compilation.chapter.md | 18 ++++++++++++++++++ .../build-managers/meson/emulator-hook.sh | 5 +++++ pkgs/top-level/all-packages.nix | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 pkgs/development/tools/build-managers/meson/emulator-hook.sh diff --git a/doc/stdenv/cross-compilation.chapter.md b/doc/stdenv/cross-compilation.chapter.md index 3b6e5c34d54d..7b8f2b4ce6cd 100644 --- a/doc/stdenv/cross-compilation.chapter.md +++ b/doc/stdenv/cross-compilation.chapter.md @@ -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: diff --git a/pkgs/development/tools/build-managers/meson/emulator-hook.sh b/pkgs/development/tools/build-managers/meson/emulator-hook.sh new file mode 100644 index 000000000000..4f08087cf5f5 --- /dev/null +++ b/pkgs/development/tools/build-managers/meson/emulator-hook.sh @@ -0,0 +1,5 @@ +add_meson_exe_wrapper_cross_flag() { + mesonFlagsArray+=(--cross-file=@crossFile@) +} + +preConfigureHooks+=(add_meson_exe_wrapper_cross_flag) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 2ce6d217dd35..b8216c367786 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -3942,6 +3942,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 { }; From 163ffce31d78d54fb95366bdebe3143f636f491c Mon Sep 17 00:00:00 2001 From: Artturin Date: Tue, 7 Jun 2022 21:48:40 +0300 Subject: [PATCH 2/5] prelink: 20130503 -> unstable-2019-06-24 cross_prelink branch has prelink-rltd and the normal prelink tools --- .../tools/misc/prelink/default.nix | 56 +++++++++++++++---- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/pkgs/development/tools/misc/prelink/default.nix b/pkgs/development/tools/misc/prelink/default.nix index 2fbee4ca5f52..384829daadf0 100644 --- a/pkgs/development/tools/misc/prelink/default.nix +++ b/pkgs/development/tools/misc/prelink/default.nix @@ -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 ]; }; } From 79d349b0877cf22b693882c9a28f9052ae66cf2d Mon Sep 17 00:00:00 2001 From: Artturin Date: Tue, 7 Jun 2022 21:51:59 +0300 Subject: [PATCH 3/5] gobject-introspection: support cross-compilation used the following as references https://github.com/void-linux/void-packages/blob/master/srcpkgs/gobject-introspection and https://git.busybox.net/buildroot/tree/package/gobject-introspection thanks void and buildroot --- .../gobject-introspection/default.nix | 17 +++++++++-- ...-error-return-codes-from-ldd-wrapper.patch | 30 +++++++++++++++++++ .../gobject-introspection/wrapper.nix | 29 ++++++++++++++++++ .../wrappers/g-ir-compiler.sh | 4 +++ .../wrappers/g-ir-scanner.sh | 7 +++++ pkgs/top-level/all-packages.nix | 5 +++- 6 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 pkgs/development/libraries/gobject-introspection/giscanner-ignore-error-return-codes-from-ldd-wrapper.patch create mode 100644 pkgs/development/libraries/gobject-introspection/wrapper.nix create mode 100644 pkgs/development/libraries/gobject-introspection/wrappers/g-ir-compiler.sh create mode 100644 pkgs/development/libraries/gobject-introspection/wrappers/g-ir-scanner.sh diff --git a/pkgs/development/libraries/gobject-introspection/default.nix b/pkgs/development/libraries/gobject-introspection/default.nix index b457331983aa..a0f4f22472d3 100644 --- a/pkgs/development/libraries/gobject-introspection/default.nix +++ b/pkgs/development/libraries/gobject-introspection/default.nix @@ -17,6 +17,8 @@ , cairo , gnome , substituteAll +, buildPackages +, gobject-introspection-unwrapped , nixStoreDir ? builtins.storeDir , x11Support ? true }: @@ -40,6 +42,9 @@ stdenv.mkDerivation rec { }; patches = [ + # prelink-rtld, which we use for cross returns 127 when it can't find a library. + # https://git.busybox.net/buildroot/tree/package/gobject-introspection/0003-giscanner-ignore-error-return-codes-from-ldd-wrapper.patch + ./giscanner-ignore-error-return-codes-from-ldd-wrapper.patch # Make g-ir-scanner put absolute path to GIR files it generates # so that programs can just dlopen them without having to muck # with LD_LIBRARY_PATH environment variable. @@ -67,7 +72,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 +91,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 +106,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, diff --git a/pkgs/development/libraries/gobject-introspection/giscanner-ignore-error-return-codes-from-ldd-wrapper.patch b/pkgs/development/libraries/gobject-introspection/giscanner-ignore-error-return-codes-from-ldd-wrapper.patch new file mode 100644 index 000000000000..fdcec4bc88c9 --- /dev/null +++ b/pkgs/development/libraries/gobject-introspection/giscanner-ignore-error-return-codes-from-ldd-wrapper.patch @@ -0,0 +1,30 @@ +From e0fc4a2a5161a36483ddc518be9bb14390f11b19 Mon Sep 17 00:00:00 2001 +From: Alexander Kanavin +Date: Wed, 5 Sep 2018 16:46:52 +0200 +Subject: [PATCH] giscanner: ignore error return codes from ldd-wrapper + +prelink-rtld, which we use instead of ldd returns 127 when it can't find a library. +It is not an error per se, but it breaks subprocess.check_output(). + +Upstream-Status: Inappropriate [oe-core specific] +Signed-off-by: Alexander Kanavin +Signed-off-by: Adam Duskett +--- + giscanner/shlibs.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/giscanner/shlibs.py b/giscanner/shlibs.py +index 9f8ab5df..7a1a72fe 100644 +--- a/giscanner/shlibs.py ++++ b/giscanner/shlibs.py +@@ -103,7 +103,7 @@ def _resolve_non_libtool(options, binary, libraries): + args.extend(['otool', '-L', binary.args[0]]) + else: + args.extend(['ldd', binary.args[0]]) +- output = subprocess.check_output(args) ++ output = subprocess.run(args, check=False, stdout=subprocess.PIPE).stdout + if isinstance(output, bytes): + output = output.decode("utf-8", "replace") + +-- +2.25.1 diff --git a/pkgs/development/libraries/gobject-introspection/wrapper.nix b/pkgs/development/libraries/gobject-introspection/wrapper.nix new file mode 100644 index 000000000000..44d31540e645 --- /dev/null +++ b/pkgs/development/libraries/gobject-introspection/wrapper.nix @@ -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" + ) + ''; +}) diff --git a/pkgs/development/libraries/gobject-introspection/wrappers/g-ir-compiler.sh b/pkgs/development/libraries/gobject-introspection/wrappers/g-ir-compiler.sh new file mode 100644 index 000000000000..fde3dcfe0c00 --- /dev/null +++ b/pkgs/development/libraries/gobject-introspection/wrappers/g-ir-compiler.sh @@ -0,0 +1,4 @@ +#! @bash@ +# shellcheck shell=bash + +exec @emulator@ @targetgir@/bin/g-ir-compiler "$@" diff --git a/pkgs/development/libraries/gobject-introspection/wrappers/g-ir-scanner.sh b/pkgs/development/libraries/gobject-introspection/wrappers/g-ir-scanner.sh new file mode 100644 index 000000000000..0825f10e166e --- /dev/null +++ b/pkgs/development/libraries/gobject-introspection/wrappers/g-ir-scanner.sh @@ -0,0 +1,7 @@ +#! @bash@ +# shellcheck shell=bash + +exec @dev@/bin/.g-ir-scanner-wrapped \ + --use-binary-wrapper=@emulator@ \ + --use-ldd-wrapper=@buildprelink@ \ + "$@" diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index b8216c367786..44bfd07525c2 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17585,7 +17585,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; }; From 41f8722078be674d185db03d0947e0df84a7ae2c Mon Sep 17 00:00:00 2001 From: Artturin Date: Wed, 8 Jun 2022 03:49:04 +0300 Subject: [PATCH 4/5] gobject-introspection: add artturin as maintainer --- pkgs/development/libraries/gobject-introspection/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/libraries/gobject-introspection/default.nix b/pkgs/development/libraries/gobject-introspection/default.nix index a0f4f22472d3..b8cbdc0cfa30 100644 --- a/pkgs/development/libraries/gobject-introspection/default.nix +++ b/pkgs/development/libraries/gobject-introspection/default.nix @@ -135,7 +135,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 ]; From 944781be23e853575128a319846c8962af78bb92 Mon Sep 17 00:00:00 2001 From: Artturin Date: Thu, 9 Jun 2022 21:14:58 +0300 Subject: [PATCH 5/5] gobject-introspection: revert patch to ignore return codes from ldd we may not need this so reverting for now --- .../gobject-introspection/default.nix | 3 -- ...-error-return-codes-from-ldd-wrapper.patch | 30 ------------------- 2 files changed, 33 deletions(-) delete mode 100644 pkgs/development/libraries/gobject-introspection/giscanner-ignore-error-return-codes-from-ldd-wrapper.patch diff --git a/pkgs/development/libraries/gobject-introspection/default.nix b/pkgs/development/libraries/gobject-introspection/default.nix index b8cbdc0cfa30..82be84e1f1df 100644 --- a/pkgs/development/libraries/gobject-introspection/default.nix +++ b/pkgs/development/libraries/gobject-introspection/default.nix @@ -42,9 +42,6 @@ stdenv.mkDerivation rec { }; patches = [ - # prelink-rtld, which we use for cross returns 127 when it can't find a library. - # https://git.busybox.net/buildroot/tree/package/gobject-introspection/0003-giscanner-ignore-error-return-codes-from-ldd-wrapper.patch - ./giscanner-ignore-error-return-codes-from-ldd-wrapper.patch # Make g-ir-scanner put absolute path to GIR files it generates # so that programs can just dlopen them without having to muck # with LD_LIBRARY_PATH environment variable. diff --git a/pkgs/development/libraries/gobject-introspection/giscanner-ignore-error-return-codes-from-ldd-wrapper.patch b/pkgs/development/libraries/gobject-introspection/giscanner-ignore-error-return-codes-from-ldd-wrapper.patch deleted file mode 100644 index fdcec4bc88c9..000000000000 --- a/pkgs/development/libraries/gobject-introspection/giscanner-ignore-error-return-codes-from-ldd-wrapper.patch +++ /dev/null @@ -1,30 +0,0 @@ -From e0fc4a2a5161a36483ddc518be9bb14390f11b19 Mon Sep 17 00:00:00 2001 -From: Alexander Kanavin -Date: Wed, 5 Sep 2018 16:46:52 +0200 -Subject: [PATCH] giscanner: ignore error return codes from ldd-wrapper - -prelink-rtld, which we use instead of ldd returns 127 when it can't find a library. -It is not an error per se, but it breaks subprocess.check_output(). - -Upstream-Status: Inappropriate [oe-core specific] -Signed-off-by: Alexander Kanavin -Signed-off-by: Adam Duskett ---- - giscanner/shlibs.py | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/giscanner/shlibs.py b/giscanner/shlibs.py -index 9f8ab5df..7a1a72fe 100644 ---- a/giscanner/shlibs.py -+++ b/giscanner/shlibs.py -@@ -103,7 +103,7 @@ def _resolve_non_libtool(options, binary, libraries): - args.extend(['otool', '-L', binary.args[0]]) - else: - args.extend(['ldd', binary.args[0]]) -- output = subprocess.check_output(args) -+ output = subprocess.run(args, check=False, stdout=subprocess.PIPE).stdout - if isinstance(output, bytes): - output = output.decode("utf-8", "replace") - --- -2.25.1