aboutsummaryrefslogtreecommitdiff
path: root/package.nix
diff options
context:
space:
mode:
authorQyriad <qyriad@qyriad.me>2024-04-22 15:39:22 -0600
committerQyriad <qyriad@qyriad.me>2024-04-22 21:41:58 -0600
commit05e3b1d39eee5632d143ccd5a382b9d1ffe79fa6 (patch)
treed7736ab52886b6b2740cbb7a32672e87d8b78b03 /package.nix
parent111db8b38fd8350d92d72fa17fd3d9e8ef5a0e09 (diff)
meson: fix cross compilation
This should fix cross compilation in the base case, but this is difficult to test as cross compilation is broken in many different places right now. This should bring Meson back up to cross parity with the Make buildsystem though. Change-Id: If09be8142d1fc975a82b994143ff35be1297dad8
Diffstat (limited to 'package.nix')
-rw-r--r--package.nix52
1 files changed, 47 insertions, 5 deletions
diff --git a/package.nix b/package.nix
index 9a2e08038..6b9fbf6d2 100644
--- a/package.nix
+++ b/package.nix
@@ -100,6 +100,43 @@ let
testConfigureFlags = [ "RAPIDCHECK_HEADERS=${lib.getDev rapidcheck}/extras/gtest/include" ];
+ # Reimplementation of Nixpkgs' Meson cross file, with some additions to make
+ # it actually work.
+ mesonCrossFile =
+ let
+ cpuFamily =
+ platform:
+ with platform;
+ if isAarch32 then
+ "arm"
+ else if isx86_32 then
+ "x86"
+ else
+ platform.uname.processor;
+ in
+ builtins.toFile "lix-cross-file.conf" ''
+ [properties]
+ bindgen_clang_arguments = ['-target', '${stdenv.targetPlatform.config}']
+ # Meson is convinced that if !buildPlatform.canExecute hostPlatform then we cannot
+ # build anything at all, which is not at all correct. If we can't execute the host
+ # platform, we'll just disable tests and doc gen.
+ needs_exe_wrapper = false
+
+ [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'
+ rust = ['rustc', '--target', '${stdenv.targetPlatform.rust.rustcTargetSpec}']
+ # Meson refuses to consider any CMake binary during cross compilation if it's
+ # not explicitly specified here, in the cross file.
+ # https://github.com/mesonbuild/meson/blob/0ed78cf6fa6d87c0738f67ae43525e661b50a8a2/mesonbuild/cmake/executor.py#L72
+ cmake = 'cmake'
+ '';
+
# The internal API docs need these for the build, but if we're not building
# Nix itself, then these don't need to be propagated.
maybePropagatedInputs = [
@@ -184,10 +221,15 @@ stdenv.mkDerivation (finalAttrs: {
]
++ lib.optional stdenv.hostPlatform.isStatic "-Denable-embedded-sandbox-shell=true"
++ lib.optional (finalAttrs.dontBuild) "-Denable-build=false"
- # mesonConfigurePhase automatically passes -Dauto_features=enabled,
- # so we must explicitly enable or disable features that we are not passing
- # dependencies for.
- ++ lib.singleton (lib.mesonEnable "internal-api-docs" internalApiDocs);
+ ++ [
+ # mesonConfigurePhase automatically passes -Dauto_features=enabled,
+ # so we must explicitly enable or disable features that we are not passing
+ # dependencies for.
+ (lib.mesonEnable "internal-api-docs" internalApiDocs)
+ (lib.mesonBool "enable-tests" finalAttrs.doCheck)
+ (lib.mesonBool "enable-docs" canRunInstalled)
+ ]
+ ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) "--cross-file=${mesonCrossFile}";
# We only include CMake so that Meson can locate toml11, which only ships CMake dependency metadata.
dontUseCmakeConfigure = true;
@@ -315,7 +357,7 @@ stdenv.mkDerivation (finalAttrs: {
makeFlags = "profiledir=$(out)/etc/profile.d PRECOMPILE_HEADERS=1";
- doCheck = true;
+ doCheck = canRunInstalled;
mesonCheckFlags = lib.optionals (buildWithMeson || forDevShell) [ "--suite=check" ];