Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions doc/stdenv/cross-compilation.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 13 additions & 3 deletions pkgs/development/libraries/gobject-introspection/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
, cairo
, gnome
, substituteAll
, buildPackages
, gobject-introspection-unwrapped
, nixStoreDir ? builtins.storeDir
, x11Support ? true
}:
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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 ];

Expand Down
29 changes: 29 additions & 0 deletions pkgs/development/libraries/gobject-introspection/wrapper.nix
Original file line number Diff line number Diff line change
@@ -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"
)
'';
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! @bash@
# shellcheck shell=bash

exec @emulator@ @targetgir@/bin/g-ir-compiler "$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! @bash@
# shellcheck shell=bash

exec @dev@/bin/.g-ir-scanner-wrapped \
--use-binary-wrapper=@emulator@ \
--use-ldd-wrapper=@buildprelink@ \
"$@"
5 changes: 5 additions & 0 deletions pkgs/development/tools/build-managers/meson/emulator-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_meson_exe_wrapper_cross_flag() {
mesonFlagsArray+=(--cross-file=@crossFile@)
}

preConfigureHooks+=(add_meson_exe_wrapper_cross_flag)
54 changes: 43 additions & 11 deletions pkgs/development/tools/misc/prelink/default.nix
Original file line number Diff line number Diff line change
@@ -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";

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
];

buildInputs = [
libelf stdenv.cc.libc (lib.getOutput "static" stdenv.cc.libc)
stdenv.cc.libc
libelf
libiberty
];

src = fetchurl {
url = "https://people.redhat.com/jakub/prelink/prelink-${version}.tar.bz2";
sha256 = "1w20f6ilqrz8ca51qhrn1n13h7q1r34k09g33d6l2vwvbrhcffb3";
};
# 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 = {
homepage = "https://people.redhat.com/jakub/prelink/";
license = "GPL";
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 ];
};
}
23 changes: 22 additions & 1 deletion pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { };
Expand Down Expand Up @@ -17567,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;
};
Expand Down