Describe the bug
Cross-compilation of mesa fails with the following error at configure stage
$ nix build -L -f '<nixpkgs>' pkgsCross.aarch64-multiplatform.mesa
...
mesa> Run-time dependency valgrind found: YES 3.15.0
mesa> Program bison found: YES (/nix/store/ra42sij0cb917p3m90qdnv0vc3kxv1hm-bison-3.5.4/bin/bison)
mesa> Program flex found: YES (/nix/store/q99r9k0py7m2mrdfsif9wfvllvvxfiqi-flex-2.6.4/bin/flex)
mesa> Run-time dependency libunwind found: NO (tried pkgconfig and cmake)
mesa> Found pkg-config: /nix/store/nc3ivxhlqyj2alck8p47srvwzzgkbh2i-pkg-config-0.29.2/bin/pkg-config (0.29.2)
mesa> Did not find CMake 'cmake'
mesa> Found CMake: NO
mesa> Build-time dependency wayland-scanner found: NO (tried pkgconfig)
mesa> meson.build:1553:2: ERROR: Dependency "wayland-scanner" not found, tried pkgconfig
mesa> A full log can be found at /build/mesa-20.0.2/build/meson-logs/meson-log.txt
Though there appear to be other non-fatal, but otherwise concerning issues (especially surrounding LLVM) in the configuration process.
To Reproduce
Steps to reproduce the behavior:
nix build -L -f '<nixpkgs>' pkgsCross.aarch64-multiplatform.mesaExpected behavior
Build should succeed
Notify maintainers
@vcunat
Metadata
"x86_64-linux"Linux 5.6.13, NixOS, 20.09pre225898.7319061eef4 (Nightingale)yesyesnix-env (Nix) 2.3.4"nixos-20.09pre225898.7319061eef4"""/nix/var/nix/profiles/per-user/root/channels/nixosMaintainer information:
# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:
Looks like meson is expecting PKG_CONFIG_PATH_FOR_BUILD to be set when looking for wayland-scanner, but the variable is not set.
Doing something like this makes it build, but is likely the wrong way to approach the problem?
diff --git a/pkgs/development/libraries/mesa/default.nix b/pkgs/development/libraries/mesa/default.nix
index 7eb18dd31c1..d4556fc2637 100644
--- a/pkgs/development/libraries/mesa/default.nix
+++ b/pkgs/development/libraries/mesa/default.nix
@@ -1,4 +1,5 @@
{ stdenv, lib, fetchurl, fetchpatch
+, pkgsBuildTarget
, pkgconfig, intltool, ninja, meson
, file, flex, bison, expat, libdrm, xorg, wayland, wayland-protocols, openssl
, llvmPackages, libffi, libomxil-bellagio, libva-minimal
@@ -116,8 +117,13 @@ stdenv.mkDerivation {
pkgconfig meson ninja
intltool bison flex file
python3Packages.python python3Packages.Mako
+ wayland
];
+ preUnpack = ''
+ export PKG_CONFIG_PATH_FOR_BUILD="${pkgsBuildTarget.wayland}/lib/pkgconfig"
+ '';
+
propagatedBuildInputs = with xorg; [
libXdamage libXxf86vm
] ++ optional stdenv.isLinux libdrm
I think https://github.com/NixOS/nixpkgs/pull/87705 will fix this partly. We will still need wayland in nativeBuildInputs.
Yeah, looks like the solution in #87705 is indeed partial, because mesa doesn鈥檛 build even on origin/master from 2 hours ago (with the nativeBuildInputs change applied).
What really is going on there is way over my head, so I鈥檒l leave this to somebody who understands it better.
@matthewbauer but wayland-scanner is a possibly-build-specific dev tool (#51176), so I think it shouldn't be using PKG_CONFIG_PATH_FOR_BUILD for this in the first place. Even if the native wayland-scanner really does work, I'd like to do the g-i thing as planned for #88222 where we combine the tools and the rest of the package in a wrapper with a patched pc file.
CC @dcbaker, do you test cross builds upstream?
Fixing cross-builds for complex packages like mesa might turn out to be hard, especially in our default feature-ful config. My motivation for aarch64 there isn't high, as we have natively compiled version from Hydra and even https://github.com/nix-community/aarch64-build-box
My motivation for aarch64 there isn't high, as we have natively compiled version from Hydra
I鈥檓 not sure if its the fact that I'm cross-compiling (and so hashes change for whatever reason) or the fact that I accidentally changed some dependency of mesa, but I鈥檓 not able to get it and other dependencies to be pulled from hydra at all (including mesa). Arguably I can still obtain a aarch64 server to do a native build, but that sounds both a subpar experience (to building locally) and a compromise.
Cross-compiled builds always get different hashes than native builds. EDIT: the thing is that getting the server (or using a local VM) might be way cheaper than fixing such complex builds and keeping them fixed (human work).
Well assuming any wayland-scanner will do, and there are no other issues, this won't be hard to fix.
wayland-scanner is cross-compiled by meson (https://github.com/wayland-project/wayland/blob/6d4497371014cacbf0dc4ed9983fd6617ec25c9a/src/meson.build#L38-L45, so I don't think we can treat it like xxx-config (even if that is more correct). wayland itself, even, needs the native wayland-scanner to cross compile (https://github.com/NixOS/nixpkgs/blob/7e571eb9943d770c2a68ed11f8beb14e6062180a/pkgs/development/libraries/wayland/default.nix#L38-L39). meson makes it pretty hard to not pull native build inputs from PKG_CONFIG_PATH_FOR_BUILD.
@Ericson2314, yes we do an x86 -> arm build. Here's the CI results for current master:
https://gitlab.freedesktop.org/mesa/mesa/pipelines/152118
@dcbaker Thanks!!
@dcbaker so it looks like the cross CI extends the native build to get access to native wayland-scanner? We did something similar in https://github.com/NixOS/nixpkgs/pull/89036 --- just making sure it isn't intended that one might build wayland-scanner as a separate package from the rest of wayland.
Oh don't get me started on wayland scanner, lol. I tried to fix that mess but upstream thinks fixing it makes their build too complicated and wont take patches. So yes, I think you need to build and package wayland scanner separate if you need to cross compile wayland.
Ugh, the classic struggle with cross. Well, I'd be happy to go comment on any issue / PR / mailing list thread you made if it might tip the scales.
Most helpful comment
Oh don't get me started on wayland scanner, lol. I tried to fix that mess but upstream thinks fixing it makes their build too complicated and wont take patches. So yes, I think you need to build and package wayland scanner separate if you need to cross compile wayland.