diff --git a/doc/stdenv/cross-compilation.chapter.md b/doc/stdenv/cross-compilation.chapter.md index 3b6e5c34d54..7b8f2b4ce6c 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/libraries/gobject-introspection/default.nix b/pkgs/development/libraries/gobject-introspection/default.nix index b457331983a..82be84e1f1d 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 }: @@ -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 ]; diff --git a/pkgs/development/libraries/gobject-introspection/wrapper.nix b/pkgs/development/libraries/gobject-introspection/wrapper.nix new file mode 100644 index 00000000000..44d31540e64 --- /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 00000000000..fde3dcfe0c0 --- /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 00000000000..0825f10e166 --- /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/development/tools/build-managers/meson/emulator-hook.sh b/pkgs/development/tools/build-managers/meson/emulator-hook.sh new file mode 100644 index 00000000000..4f08087cf5f --- /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/development/tools/misc/prelink/default.nix b/pkgs/development/tools/misc/prelink/default.nix index 2fbee4ca5f5..384829daadf 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 ]; }; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 5270ed642bf..cb4ce940f38 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -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; };