From 284f75a258e0f766b8b5d047c486f11c4c4e102d Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 26 Feb 2018 06:33:00 -0500 Subject: [PATCH] meson: Support cross-compiling --- .../tools/build-managers/meson/default.nix | 26 +++++++++++++++++-- .../tools/build-managers/meson/setup-hook.sh | 8 ++++-- 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