From 07bae67bd84fc97b397f8499fa5573291d50c9d8 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Thu, 10 Feb 2022 19:31:20 +0000 Subject: meson: pull cross-file logic out of stdenv MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since Meson isn't part of stdenv, it doesn't really make sense for stdenv to handle mesonFlags. And putting it in stdenv imposes some limitations — we can't depend on e.g. rust.toRustTargetSpec, which we'll need to introduce Rust support in the cross file. --- .../tools/build-managers/meson/default.nix | 28 +++++++++++++++++++++- .../tools/build-managers/meson/setup-hook.sh | 2 +- pkgs/stdenv/generic/make-derivation.nix | 24 ------------------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/pkgs/development/tools/build-managers/meson/default.nix b/pkgs/development/tools/build-managers/meson/default.nix index aeddf457f48..62e16516392 100644 --- a/pkgs/development/tools/build-managers/meson/default.nix +++ b/pkgs/development/tools/build-managers/meson/default.nix @@ -1,4 +1,5 @@ { lib +, stdenv , fetchpatch , installShellFiles , ninja @@ -63,7 +64,32 @@ python3.pkgs.buildPythonApplication rec { ./do-not-update-ldconfig-cache.patch ]; - setupHook = ./setup-hook.sh; + cpuFamily = with stdenv.targetPlatform; + /**/ if isAarch32 then "arm" + else if isAarch64 then "aarch64" + else if isx86_32 then "x86" + else if isx86_64 then "x86_64" + else parsed.cpu.family + builtins.toString parsed.cpu.bits; + + crossFile = if stdenv.hostPlatform == stdenv.targetPlatform then null else + builtins.toFile "cross-file.conf" '' + [properties] + needs_exe_wrapper = true + + [host_machine] + system = '${stdenv.targetPlatform.parsed.kernel.name}' + cpu_family = '${cpuFamily}' + cpu = '${stdenv.targetPlatform.parsed.cpu.name}' + endian = ${if stdenv.targetPlatform.isLittleEndian then "'little'" else "'big'"} + + [binaries] + llvm-config = 'llvm-config-native' + ''; + + setupHook = substituteAll { + src = ./setup-hook.sh; + crossFlags = lib.optionalString (crossFile != null) "--cross-file=${crossFile}"; + }; # Meson included tests since 0.45, however they fail in Nixpkgs because they # require a typical building environment (including C compiler and stuff). diff --git a/pkgs/development/tools/build-managers/meson/setup-hook.sh b/pkgs/development/tools/build-managers/meson/setup-hook.sh index 3d946fcffd5..6a7087174e5 100644 --- a/pkgs/development/tools/build-managers/meson/setup-hook.sh +++ b/pkgs/development/tools/build-managers/meson/setup-hook.sh @@ -6,7 +6,7 @@ mesonConfigurePhase() { fi # See multiple-outputs.sh and meson’s coredata.py - mesonFlags="\ + mesonFlags="@crossFlags@ \ --libdir=${!outputLib}/lib --libexecdir=${!outputLib}/libexec \ --bindir=${!outputBin}/bin --sbindir=${!outputBin}/sbin \ --includedir=${!outputInclude}/include \ diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index 2465449867c..9d9fa58d8e2 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -51,7 +51,6 @@ in # Configure Phase , configureFlags ? [] , cmakeFlags ? [] -, mesonFlags ? [] , # Target is not included by default because most programs don't care. # Including it then would cause needless mass rebuilds. # @@ -287,29 +286,6 @@ else let ++ lib.optional (stdenv.buildPlatform.uname.system != null) "-DCMAKE_HOST_SYSTEM_NAME=${stdenv.buildPlatform.uname.system}" ++ lib.optional (stdenv.buildPlatform.uname.processor != null) "-DCMAKE_HOST_SYSTEM_PROCESSOR=${stdenv.buildPlatform.uname.processor}" ++ lib.optional (stdenv.buildPlatform.uname.release != null) "-DCMAKE_HOST_SYSTEM_VERSION=${stdenv.buildPlatform.uname.release}"; - - mesonFlags = if mesonFlags == null then null else let - # See https://mesonbuild.com/Reference-tables.html#cpu-families - cpuFamily = platform: with platform; - /**/ if isAarch32 then "arm" - else if isAarch64 then "aarch64" - else if isx86_32 then "x86" - else if isx86_64 then "x86_64" - else platform.parsed.cpu.family + builtins.toString platform.parsed.cpu.bits; - crossFile = builtins.toFile "cross-file.conf" '' - [properties] - needs_exe_wrapper = true - - [host_machine] - system = '${stdenv.targetPlatform.parsed.kernel.name}' - cpu_family = '${cpuFamily stdenv.targetPlatform}' - cpu = '${stdenv.targetPlatform.parsed.cpu.name}' - endian = ${if stdenv.targetPlatform.isLittleEndian then "'little'" else "'big'"} - - [binaries] - llvm-config = 'llvm-config-native' - ''; - in [ "--cross-file=${crossFile}" ] ++ mesonFlags; } // lib.optionalAttrs (attrs.enableParallelBuilding or false) { enableParallelChecking = attrs.enableParallelChecking or true; } // lib.optionalAttrs (hardeningDisable != [] || hardeningEnable != [] || stdenv.hostPlatform.isMusl) { -- cgit 1.4.1