summary refs log tree commit diff
path: root/pkgs/development/tools
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2018-02-26 06:33:00 -0500
committerShea Levy <shea@shealevy.com>2018-02-26 06:38:32 -0500
commit284f75a258e0f766b8b5d047c486f11c4c4e102d (patch)
tree8499ebffaf3c543a75e50d77c604232871493079 /pkgs/development/tools
parent4728ef130e17f194fddedfea386e4fc909e1c4cb (diff)
downloadnixlib-284f75a258e0f766b8b5d047c486f11c4c4e102d.tar
nixlib-284f75a258e0f766b8b5d047c486f11c4c4e102d.tar.gz
nixlib-284f75a258e0f766b8b5d047c486f11c4c4e102d.tar.bz2
nixlib-284f75a258e0f766b8b5d047c486f11c4c4e102d.tar.lz
nixlib-284f75a258e0f766b8b5d047c486f11c4c4e102d.tar.xz
nixlib-284f75a258e0f766b8b5d047c486f11c4c4e102d.tar.zst
nixlib-284f75a258e0f766b8b5d047c486f11c4c4e102d.zip
meson: Support cross-compiling
Diffstat (limited to 'pkgs/development/tools')
-rw-r--r--pkgs/development/tools/build-managers/meson/default.nix26
-rw-r--r--pkgs/development/tools/build-managers/meson/setup-hook.sh8
2 files changed, 30 insertions, 4 deletions
diff --git a/pkgs/development/tools/build-managers/meson/default.nix b/pkgs/development/tools/build-managers/meson/default.nix
index 5db0bce21f79..27aa38cfa7e1 100644
--- a/pkgs/development/tools/build-managers/meson/default.nix
+++ b/pkgs/development/tools/build-managers/meson/default.nix
@@ -1,5 +1,7 @@
-{ lib, python3Packages }:
-python3Packages.buildPythonApplication rec {
+{ lib, python3Packages, stdenv, targetPlatform, writeTextDir, m4 }: let
+  targetPrefix = lib.optionalString stdenv.isCross
+                   (targetPlatform.config + "-");
+in python3Packages.buildPythonApplication rec {
   version = "0.44.0";
   pname = "meson";
   name = "${pname}-${version}";
@@ -33,6 +35,26 @@ python3Packages.buildPythonApplication rec {
 
   setupHook = ./setup-hook.sh;
 
+  crossFile = writeTextDir "cross-file.conf" ''
+    [binaries]
+    c = '${targetPrefix}cc'
+    cpp = '${targetPrefix}c++'
+    ar = '${targetPrefix}ar'
+    strip = '${targetPrefix}strip'
+    pkgconfig = 'pkg-config'
+
+    [properties]
+    needs_exe_wrapper = true
+
+    [host_machine]
+    system = '${targetPlatform.parsed.kernel.name}'
+    cpu_family = '${targetPlatform.parsed.cpu.family}'
+    cpu = '${targetPlatform.parsed.cpu.name}'
+    endian = ${if targetPlatform.isLittleEndian then "'little'" else "'big'"}
+  '';
+
+  inherit (stdenv) cc isCross;
+
   meta = with lib; {
     homepage = http://mesonbuild.com;
     description = "SCons-like build system that use python as a front-end language and Ninja as a building backend";
diff --git a/pkgs/development/tools/build-managers/meson/setup-hook.sh b/pkgs/development/tools/build-managers/meson/setup-hook.sh
index 8f96e6146be0..22e46a62cb9d 100644
--- a/pkgs/development/tools/build-managers/meson/setup-hook.sh
+++ b/pkgs/development/tools/build-managers/meson/setup-hook.sh
@@ -6,11 +6,15 @@ mesonConfigurePhase() {
     fi
 
     # Build release by default.
-    mesonFlags="--buildtype=${mesonBuildType:-release} $mesonFlags"
+    if [ -n "@isCross@" ]; then
+      crossMesonFlags="--cross-file=@crossFile@/cross-file.conf"
+    fi
+
+    mesonFlags="${crossMesonFlags+$crossMesonFlags }--buildtype=${mesonBuildType:-release} $mesonFlags"
 
     echo "meson flags: $mesonFlags ${mesonFlagsArray[@]}"
 
-    meson build $mesonFlags "${mesonFlagsArray[@]}"
+    CC=@cc@/bin/cc CXX=@cc@/bin/c++ meson build $mesonFlags "${mesonFlagsArray[@]}"
     cd build
 
     if ! [[ -v enableParallelBuilding ]]; then