Crosscompiling Kodi to ARMv7 fails

Hi,

I’m trying to run NixOS with Kodi on an Raspberry Pi 2B as a HTPC. This requires cross-compiling from my desktop PC (x64) to armv7l, as there is no binary cache for armv7l. 24.11 also seems completely broken on 32-bit ARM, so I’m stuck on 24.05 for now.

I am currently stuck on crosscompiling Kodi (after considerable effort spent getting openjdk to crosscompile), with the following rather strange error:

copying path '/nix/store/p4zm691nhs5ldz5c8rfcnks7xfnjv9lb-bison-3.8.2' from 'https://cache.nixos.org'...
  HOSTCC  scripts/kconfig/conf.o
copying path '/nix/store/b1wvkjx96i3s7wblz38ya0zr8i93zbc5-coreutils-9.5' from 'https://cache.nixos.org'...
copying path '/nix/store/w4nql5j8yv9s3a4vrxbjy7rdkqxxnsii-flex-2.6.4' from 'https://cache.nixos.org'...
  HOSTCC  scripts/kconfig/confdata.o
  HOSTCC  scripts/kconfig/expr.o
source root is source
copying path '/nix/store/cxwsmlr3xh1ml4r0kgdjrknw7504b9f8-diffutils-3.10' from 'https://cache.nixos.org'...
unpackPhase completed in 1 minutes 13 seconds
Running phase: patchPhase
substituteStream() in derivation kodi-armv7l-unknown-linux-gnueabihf-21.0: WARNING: '--replace' is deprecated, use --replace-{fail,warn,quiet}. (file 'xbmc/platform/posix/PosixTimezone.cpp')
Running phase: updateAutotoolsGnuConfigScriptsPhase
  LEX     scripts/kconfig/lexer.lex.c
Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.sub
Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.guess
Running phase: updateAutotoolsGnuConfigScriptsPhase
Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.sub
Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.guess
Running phase: configurePhase
make: Entering directory '/build/source/tools/depends/native/JsonSchemaBuilder'
Makefile:1: ../../Makefile.include: No such file or directory
make: *** No rule to make target '../../Makefile.include'.  Stop.
make: Leaving directory '/build/source/tools/depends/native/JsonSchemaBuilder'

That is, a file called Makefile.include cannot be found. If we look at the Kodi git repository, we can see that a file called Makefile.include.in is present at the expected location: xbmc/tools/depends/Makefile.include.in at 72ea90a0c28b0dedbb740972817b75d0e0b7c78a · xbmc/xbmc · GitHub . I have not been able to find any info on what this file is or its relationship to the expected file.

It is completely unclear to me where this error comes from and I have not found anyone else who has encountered it. Any help or ideas are welcome.

Please first of all verify that it’s actually the kodi derivation that fails. I can see a bunch of other stuff building at the same time in the log and it’s not clear from the log posted here that it’s the kodi drv which produced this message.

If it is indeed kodi, please show the full log of only that derivation using nix log ... or nix-store --log $(nix-instantiate ...).

Though as you’ve perhaps noticed already, cross-compilation generally isn’t very well supported yet. Do expect further failures down the line too.
I’d recommend you to attempt to minimise your closure for minimising the likelihood of other broken builds and to minimise the amount of things you need to compile.

Please do send any patches you make upstream though, it greatly helps the next person attempting to do the same as you. Also make sure that this also doesn’t work on unstable because cross things do get fixed from time to time when the next person attempts to put NixOS on their rpi2 (you’re neither the first or last person to attempt precisely that :wink: ).

The problematic package is indeed Kodi:

$ nix log /nix/store/qcj4mj3wx2qrqdkkg1arrj3vv57asg17-kodi-armv7l-unknown-linux-gnueabihf-21.0.drv

@nix { "action": "setPhase", "phase": "unpackPhase" }
Running phase: unpackPhase
unpacking source archive /nix/store/wmb99pjysqibhvyx0arl786dsjrfc6xn-source
source root is source
unpackPhase completed in 1 minutes 12 seconds
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: patchPhase
substituteStream() in derivation kodi-armv7l-unknown-linux-gnueabihf-21.0: WARNING: '--replace' is deprecated, use --replace-{fail,warn,quiet}. (file 'xbmc/platform/posix/PosixTimezone.cpp')
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Running phase: updateAutotoolsGnuConfigScriptsPhase
Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.sub
Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.guess
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Running phase: updateAutotoolsGnuConfigScriptsPhase
Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.sub
Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.guess
@nix { "action": "setPhase", "phase": "configurePhase" }
Running phase: configurePhase
make: Entering directory '/build/source/tools/depends/native/JsonSchemaBuilder'
Makefile:1: ../../Makefile.include: No such file or directory
make: *** No rule to make target '../../Makefile.include'.  Stop.
make: Leaving directory '/build/source/tools/depends/native/JsonSchemaBuilder'

Same error on the Kodi package from 24.05, 24.11 and unstable. Any clues to what would cause this error are welcome.

I’d recommend you to attempt to minimise your closure for minimising the likelihood of other broken builds and to minimise the amount of things you need to compile.

I would, but it’s hardly documented how to do that and determining if a package is truly necessary or not would and how to eliminate it would probably take about as much time as just fixing its crosscompile. If you have any sources that detail how I may do this it’d be greatly appreciated, as it might open a path to just natively compile in either QEMU or on my pi. I’m especially interested in but have been unable to figure out how to disable many kernel drivers that my rpi will simply never need.

Please do send any patches you make upstream though, it greatly helps the next person attempting to do the same as you. Also make sure that this also doesn’t work on unstable because cross things do get fixed from time to time when the next person attempts to put NixOS on their rpi2 (you’re neither the first or last person to attempt precisely that :wink: ).

Most of the stuff I’ve done has been fixing openjdk cross, which already seems to be present upstream (in fact, I cribbed a bunch of it from there). Whether I introduced anything novel there is hard to determine as I started from a different base (openjdk seems to have been significantly rewritten between 24.05 and 24.11) and the crosscompile toolchain to armv7l seems to be completely broken on 24.11.

For posterity and future efforts, here is the openjdk overlay I used, though I do not know if all parts of it are necessary or will work. I started from the snippet linked here and added what was needed to make it work: Build failure: `pkgsCross.aarch64-multiplatform.jdk11.override { enableGnome2 = false; }` · Issue #217703 · NixOS/nixpkgs · GitHub

      (final: prev: {
        openjdk11_headless = ((prev.openjdk11_headless.override {
          # libIDL does not compile in cross-compile scenarios.
          enableGnome2 = false;
        }).overrideAttrs (old: with prev; {
          # This might work if `autoconf` is put into `depsBuildBuild`? Didn’t test.
          AUTOCONF = "${autoconf}/bin/autoconf";
          strictDeps = true;
          nativeBuildInputs = old.nativeBuildInputs ++ [ which buildPackages.zip zlib perl ];
          buildInputs = with xorg; [
            cpio file perl zlib cups freetype harfbuzz alsa-lib libjpeg giflib
            libpng zlib lcms2 libX11 libICE libXrender libXext libXtst libXt libXtst
            libXi libXinerama libXcursor libXrandr fontconfig
          ];
          # Required by autoconf even though this isn't actually getting used AFAIK.
          depsBuildBuild = with buildPackages; [ stdenv.cc ];
          configureFlags = let
            jdk-bootstrap = buildPackages.openjdk11-bootstrap.override {
              # when building a headless jdk, also bootstrap it with a headless jdk
              gtkSupport = false;
            };
          in
            old.configureFlags
            ++ [ # Not sure if these are necessary, just makes builds take less time I think
              "--with-jtreg=no"
              "--disable-hotspot-gtest"
            ]
            # The important part, this avoids building a jdk for --build target.
            ++ lib.optional (buildPlatform != hostPlatform) [
              "--with-build-jdk=${buildPackages.openjdk11_headless}"
              "--with-boot-jdk=${jdk-bootstrap.home}"
            ];
        }));
        jdk11_headless = final.openjdk11_headless;
      })

EDIT:

I have also made a post on the Kodi forums asking if anyone there knows anything: Makefile.include issue when crosscompiling to ARMv7

The *.in files are present in C packages that use autotools (in your case, automake). They are generic and turned to your system specific variant without the .in during the ./configure step. I don’t see the typical output of ./configure in your logs so it seems that for some reason, make is being called immediately which fails.

I’m not terribly good with autotools and can’t offer much more advice. But you probably have to find out why the configure-step is not being run.

2 Likes

Thank you, that was the hint I needed to figure it out!

It seems the crosscompile lines added to preConfigure here should (probably) instead be in postConfigure: nixpkgs/pkgs/applications/video/kodi/unwrapped.nix at 58f1b636d3b300090f4c2bbcac59d18d93198705 · NixOS/nixpkgs · GitHub

However, this overlay is not properly applied for some reason:

      (final: prev: {
        kodi-wayland = (prev.kodi-wayland.override {
            x11Support = false;
        }).overrideAttrs (old: {
          preConfigure = ''
            cmakeFlagsArray+=("-DCORE_PLATFORM_NAME=wayland")
          '';
          postConfigure = ''
            CXX=$CXX_FOR_BUILD LD=ld make -C tools/depends/native/JsonSchemaBuilder
            cmakeFlags+=" -DWITH_JSONSCHEMABUILDER=$PWD/tools/depends/native/JsonSchemaBuilder/bin"

            CXX=$CXX_FOR_BUILD LD=ld make EXTRA_CONFIGURE= -C tools/depends/native/TexturePacker
            cmakeFlags+=" -DWITH_TEXTUREPACKER=$PWD/tools/depends/native/TexturePacker/bin"
          '';
        });
      })

Whatever I do (whether I use overrideAttrs or overrideDerivation), Nix keeps trying to build a derivation with the old (broken) preConfigure and no postConfigure, indicating that my overlay was not applied or had no effect. I’m rather confused as to why this does not work. I suspect it may have something to do with the way Kodi is specified in unwrapped.nix which is callPackaged in default.nix which is then callPackaged again in all-packages.nix, but I don’t know how to circumvent this, if it is even the issue.

Ah, I only meant on the basic level; to not enable settings or packages you don’t necessarily need.

QEMU is super slow even on a very fast machine but compiling on the pi can work. You need lots of zram swap, enable a good margin of overcommit, time and storage space though.

You could roll a custom config but I don’t think it’s worth the complexity.

That’s more something you should do if you have extremely tight storage space or memory constraints, not if you’re optimising build time. 10-20mins aren’t that significant when you’re building for hours.

Uhh, huh; you should probably create an issue on that. It’s not something that gets a lot of testing, so it can easily slip through the cracks. Eventhough it’s not a platform that is well supported in any way in most regards, we’d want basic support to work at least.

What also stumps me is that it runs make during the configurePhase, not the buildPhase.

If you want cross to work, you’re almost always better off if you just work on a Nixpkgs checkout directly.

You’ll likely need to touch half a dozen packages and this also makes it easier to contribute upstream.

It might employ the common wrapper pattern where the actual derivation that builds the code is wrapped within another derivation that augments it in some way.

The easiest way to go there would be to overlay the unwrapped package (commonly packagename-unwrapped).

Touching Nixpkgs directly is almost always easier though.

1 Like

This is the preConfigure for Kodi in current nixpkgs:

    preConfigure = ''
      cmakeFlagsArray+=("-DCORE_PLATFORM_NAME=${lib.concatStringsSep " " kodi_platforms}")
    '' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
      # Need these tools on the build system when cross compiling,
      # hacky, but have found no other way.
      CXX=$CXX_FOR_BUILD LD=ld make -C tools/depends/native/JsonSchemaBuilder
      cmakeFlags+=" -DWITH_JSONSCHEMABUILDER=$PWD/tools/depends/native/JsonSchemaBuilder/bin"

      CXX=$CXX_FOR_BUILD LD=ld make EXTRA_CONFIGURE= -C tools/depends/native/TexturePacker
      cmakeFlags+=" -DWITH_TEXTUREPACKER=$PWD/tools/depends/native/TexturePacker/bin"
    '';

Which, as you can see, runs make in preConfigure. I’m hoping that the crosscompile hack they specify here will work in postConfigure… Else I will have to look at autotools in more depth, which I would really rather not. If it doesn’t work, perhaps we need to ./configure, apply this hack, ./configure again and only then make? I have no idea how I would achieve that in NixOS.

There is no exposed kodi-unwrapped package, at least as far as I can tell. I also have no idea how I would do this, my Nix knowledge is still rather limited. The kodi package seems rather suboptimal in several ways (some of its dependencies seem to have to be recompiled every time, which greatly slows down my experimentation here).

I guess using a local nixpkgs checkout is my best shot, though it seems clunky considering how large nixpkgs is and will mean duplication of a lot of packages. Though it seems 2405 is still supported for now, so if it works I could hopefully send the fix upstream.

Now I see what might be going on here. Could you try simply removing that section? It might no longer be relevant and nobody noticed because nobody tried to build it cross in a long time.

You’ll have to read the nix expressions to figure out what’s going on here then.

I’m not quite sure what you mean here. The packages will be the exact same as the ones you get from using upstream Nixpkgs (except for your changes of course). Nothing will be duplicated unless you explicitly change it.

You’re only touching the Nix expressions here.

The Nixpkgs checkout itself is quite large (~1GiB) but you could use --depth=1 to mitigate this.

Note that 24.05 will go EOL in one month.

No dice, results in this error:

@nix { "action": "setPhase", "phase": "unpackPhase" }
Running phase: unpackPhase
unpacking source archive /nix/store/wmb99pjysqibhvyx0arl786dsjrfc6xn-source
source root is source
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: patchPhase
substituteStream() in derivation kodi-armv7l-unknown-linux-gnueabihf-21.0: WARNING: '--replace' is deprecated, use --replace-{fail,warn,quiet}. (file 'xbmc/platform/posix/PosixTimezone.cpp')
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Running phase: updateAutotoolsGnuConfigScriptsPhase
Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.sub
Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.guess
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Running phase: updateAutotoolsGnuConfigScriptsPhase
Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.sub
Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.guess
@nix { "action": "setPhase", "phase": "configurePhase" }
Running phase: configurePhase
fixing cmake files...
cmake flags: -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DCMAKE_INSTALL_LOCALEDIR=/nix/store/gzlvr5qmrfrb8r2v0n6b43n73qcn7yss-kodi-armv7l-unknown-linux-gnueab>
-- The CXX compiler identification is GNU 13.2.0
-- The C compiler identification is GNU 13.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /nix/store/8vqz5vj4s5ckn4c9a27cmp7z0ldg33q0-armv7l-unknown-linux-gnueabihf-gcc-wrapper-13.2.0/bin/armv7l-unknown-linux-gnueabihf-gcc
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /nix/store/8vqz5vj4s5ckn4c9a27cmp7z0ldg33q0-armv7l-unknown-linux-gnueabihf-gcc-wrapper-13.2.0/bin/armv7l-unknown-linux-gnueabihf-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /nix/store/8vqz5vj4s5ckn4c9a27cmp7z0ldg33q0-armv7l-unknown-linux-gnueabihf-gcc-wrapper-13.2.0/bin/armv7l-unknown-linux-gnueabihf-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Mirror download location: http://mirrors.kodi.tv
-- Source directory: /build/source
-- Build directory: /build/source/build
-- Generator: Single-configuration: Release (Unix Makefiles)
-- CMake Version: 3.29.2
-- System type: Linux
-- Linker: GNU gold
-- Host architecture is little-endian
-- Core system type: linux
-- Platform: wayland;x11
-- CPU: armv7l, ARCH: arm
-- Cross-Compiling: TRUE
-- Execute build artefacts on host:
-- Depends based build:
-- statx is available
-- Could not find hardware support for SSE (missing: _SSE_TRUE _SSE_OK)
-- Could not find hardware support for SSE2 (missing: _SSE2_TRUE _SSE2_OK)
-- Could not find hardware support for SSE3 (missing: _SSE3_TRUE _SSE3_OK)
-- Could not find hardware support for SSSE3 (missing: _SSSE3_TRUE _SSSE3_OK)
-- Could not find hardware support for SSE4.1 (missing: _SSE41_TRUE _SSE41_OK)
-- Could not find hardware support for SSE4.2 (missing: _SSE42_TRUE _SSE42_OK)
-- Could not find hardware support for AVX (missing: _AVX_TRUE _AVX_OK)
-- Could not find hardware support for AVX2 (missing: _AVX2_TRUE _AVX2_OK)
-- NEON optimization enabled
-- Found PkgConfig: /nix/store/w3ysgf5yhbr9k1s9r79cp0cgdryihdgl-armv7l-unknown-linux-gnueabihf-pkg-config-wrapper-0.29.2/bin/armv7l-unknown-linux-gnueabihf-pkg-config (found version "0.29.2")
-- Could NOT find CCache (missing: CCACHE_PROGRAM)
-- Could NOT find ClangFormat (missing: CLANG_FORMAT_EXECUTABLE)
-- Found FlatC Compiler: /nix/store/a746ggds9vp0a2na8yj8jh9ikl7sv4jr-flatbuffers-23.5.26/bin/flatc (found version "23.5.26")
-- Found JsonSchemaBuilder: /build/source/build/build/bin/JsonSchemaBuilder
-- Found Lzo2: /nix/store/d6v84fh06nb61kfkc7067frxgab1n24m-lzo-armv7l-unknown-linux-gnueabihf-2.10/lib/liblzo2.so
-- Found ZLIB: /nix/store/06wgpzn63zl0jmyy96lpz5ngswyf08yd-zlib-armv7l-unknown-linux-gnueabihf-1.3.1/lib/libz.so (found version "1.3.1")
-- Found PNG: /nix/store/69amnjinpbyx36ma2bcrsix1f9d8b7i2-libpng-apng-armv7l-unknown-linux-gnueabihf-1.6.43/lib/libpng.so (found version "1.6.43")
-- Found GIF: /nix/store/m42jhahdb50rr7a1qvvck09nj953k2c6-giflib-armv7l-unknown-linux-gnueabihf-5.2.2/lib/libgif.so (found version "5.2.2")
-- Found JPEG: /nix/store/nkszw330hs4k2lci6f5j6vpbccixamwx-libjpeg-turbo-armv7l-unknown-linux-gnueabihf-3.0.3/lib/libjpeg.so (found version "62")
-- Building internal TexturePacker
-- Shipping internal TexturePacker
-- External TexturePacker will be executed during build:
CMake Error at /nix/store/z9w9jh0pq94vlfzsiyb3g6lrai8ba2px-cmake-3.29.2/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:230 (message):

i.e., the thing this preConfigure hack is missing does indeed need to be built.

As I understand it (and I may understand wrong), the issue is that Kodi has a bunch of vendored build-time dependencies which Nixpkgs un-vendors, except for TexturePacker and JsonSchemaBuilder because those are just Kodi-specific. The makefiles seem to have some logic to use vendored versions of those, but not for crosscompile, so we need to build them. Something like that, anyway.

What I have right now is:

    preConfigure = ''
      cmakeFlagsArray+=("-DCORE_PLATFORM_NAME=${lib.concatStringsSep " " kodi_platforms}")
      # Need these tools on the build system when cross compiling,
      # hacky, but have found no other way.
      pushd tools/depends

      ls .

      autoconf -f
      ./configure --host=x86_64-linux-gnu --with-rendersystem=gles --with-toolchain=${buildPackages.stdenv.cc} --prefix=/opt/xbmc-deps

      CXX=$CXX_FOR_BUILD LD=ld make -C native/JsonSchemaBuilder
      cmakeFlags+=" -DWITH_JSONSCHEMABUILDER=$PWD/native/JsonSchemaBuilder/bin"

      CXX=$CXX_FOR_BUILD LD=ld make EXTRA_CONFIGURE= -C native/TexturePacker
      cmakeFlags+=" -DWITH_TEXTUREPACKER=$PWD/native/TexturePacker/bin"

      popd
    '';

i.e., we ./configure the vendored dependencies first, then make the two we need, then ./configure and build Kodi. However, it’s currently getting stuck on a lack of curl so I will have to add that dependency (I do not think it is actually used, hopefully)

You’re right, I got confused.

Well, we’ll see. I guess if it’s EOL it doesn’t really matter if I pull from nixpkgs directly or from my own fork with a patch applied. I could PR it to 24.11 or master, but as I said earlier I wouldn’t be able to test it. Perhaps I’ll try to make a bug report at least when/if I figure it out.

Just a hunch but you could try to add cmake and/or stdenv.cc from buildPackages or pkgsBuildBuild (not 100% sure which would make sense right now) to depsBuildBuild. It might be able to compile those vendored deps. If it’s trying to download them, perhaps see whether they’d normally be vendored as git submodules and fetch the submodules in the src.

Otherwise, you could also package those deps separately and provide them to the build system just like the other deps.

Is that the entire error message?

That doesn’t make sense if you can’t actually test. You could help out testing a potential fix for armv7l cross though if there is one and then post your patches.

Ideally do so in either case for posterity and for getting second opinions on things.

Also for armv7l cross being broken, that ought to be fixed.

1 Like

i think the unwrapped variant is just pkgs.kodi :thinking: you don’t get a wrapped kodi unless you use the withPackages that is provided by kodi.passthru

my understanding is that this is an unfortunate side effect of nix and the way kodi builds things… kodi vendors many of its own dependencies with source forks and some of them i don’t think you can even tell it to use the system package, it only accepts source

that being said… yes, there is definitely room to clean up the kodi expression, maybe i’ll find some time this cycle to do so

kinda… the cmake files for kodi often try to download things from the internet, which of course doesn’t work for nix - fortunately the cmake files make it easy to provide your own source, so that is what you’re seeing here… we fetch the source with fetch* in nix and then provide the source to cmake


finally… i am sorry i don’t know anything about cross compiling, i really wish i could help you out here

2 Likes

stendv.cc is already in depsBuildBuild, it’s not really clear to me why it works for native but doesn’t work for crosscompile.

Whoops, I was in a rush:

CMake Error at /nix/store/z9w9jh0pq94vlfzsiyb3g6lrai8ba2px-cmake-3.29.2/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find TexturePacker (missing: TEXTUREPACKER_EXECUTABLE)

Fair enough, but then I don’t really understand why my overrides weren’t doing anything.

Yeah, that makes sense. In a certain sense it’s impressive to begin with that something as complex as Kodi is included in nixpkgs and (mostly) working, really!

Yeah, though I don’t think it’s quite the case here, it seems like for TexturePacker and the other one it only really wants an executable.

I will try to hack on it a bit more and see if I can get it compiling. I feel like I’m relatively close, but there’s a bunch of parameters that expect me to pass toolchains in here, compounded with the fact that I need to make sure the correct Nix executables are used, and I am really not familiar with autotools.

neither do i :thinking:

observe my nix-repl session:

nix-repl> kodi-wayland.preConfigure
"cmakeFlagsArray+=(\"-DCORE_PLATFORM_NAME=wayland x11\")\n"

nix-repl> :b kodi-wayland.overrideAttrs (_: { preConfigure = "echo 'fail'; exit 1;"; })
error: builder for '/nix/store/gd1hznk9zp9sgnqskvwvdjpildzb6v1x-kodi-21.1.drv' failed with exit code 1;
       last 11 log lines:
       > Running phase: unpackPhase
       > unpacking source archive /nix/store/xz1655bqyv7k0v29h3qjxp8mb4c9r010-source
       > source root is source
       > Running phase: patchPhase
       > applying patch /nix/store/kwyhjysqilf15z1h5k5j36pq1mrqdckd-no-python-lib.patch
       > patching file cmake/scripts/linux/Install.cmake
       > Running phase: updateAutotoolsGnuConfigScriptsPhase
       > Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.sub
       > Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.guess
       > Running phase: configurePhase
       > fail
       For full logs, run 'nix log /nix/store/gd1hznk9zp9sgnqskvwvdjpildzb6v1x-kodi-21.1.drv'.
[0 built (1 failed), 85 copied (846.2 MiB), 470.1 MiB DL]

what you had definitely should be working

keeping in mind i know nothing about cross compiling are you able to give me a few commands so i can retry what you’re doing? i’m not saying i will solve all your problems… but i am willing to take a look if it could help move us forward to a better kodi experience in nixpkgs :smile:

1 Like

I’ll try to make a minimal example that can reproduce it, admittedly I do have a few complicating factors here (I was just running it through colmena through my flake config), so it might take a bit.

But it’s only part of the puzzle, and I’ve made some progress at actually getting the crosscompile to work with this (probably not very idiomatic) preConfigure:

    preConfigure = ''
      cmakeFlagsArray+=("-DCORE_PLATFORM_NAME=${lib.concatStringsSep " " kodi_platforms}")
      pushd tools/depends

      autoconf -f
      ./configure --host=x86_64-linux-gnu --with-rendersystem=gles --with-toolchain=${buildPackages.stdenv.cc} --prefix=$PWD/bin

      echo "subconfigure done"

      echo "building jsonschemabuilder"

      CXX=$CXX_FOR_BUILD LD=ld make CMAKE_FOR_BUILD="${buildPackages.cmake}/bin/cmake -DCMAKE_INSTALL_PREFIX=/build/source/tools/depends/JsonSchemaBuilder" -C native/JsonSchemaBuilder
      cmakeFlags+=" -DWITH_JSONSCHEMABUILDER=$PWD/JsonSchemaBuilder/bin/JsonSchemaBuilder"

      echo "building texturepacker"

      CXX=$CXX_FOR_BUILD LD=ld make CMAKE_FOR_BUILD="${buildPackages.cmake}/bin/cmake -DCMAKE_INSTALL_PREFIX=/build/source/tools/depends/TexturePacker" -C native/TexturePacker
      cmakeFlags+=" -DWITH_TEXTUREPACKER=$PWD/TexturePacker/bin/TexturePacker"

      popd
    '';

JsonSchemaBuilder builds without issue now! Which tells me I’m on the right path. However, this results in this error indicating that it cannot find the Lzo2 library:

@nix { "action": "setPhase", "phase": "unpackPhase" }
Running phase: unpackPhase
unpacking source archive /nix/store/wmb99pjysqibhvyx0arl786dsjrfc6xn-source
source root is source
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: patchPhase
substituteStream() in derivation kodi-armv7l-unknown-linux-gnueabihf-21.0: WARNING: '--replace' is deprecated, use --replace-{fail,warn,quiet}. (file 'xbmc/platform/posix/PosixTimezone.cpp')
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Running phase: updateAutotoolsGnuConfigScriptsPhase
Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.sub
Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.guess
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Running phase: updateAutotoolsGnuConfigScriptsPhase
Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.sub
Updating Autotools / GNU config script to a newer upstream version: ./tools/depends/build-aux/config.guess
@nix { "action": "setPhase", "phase": "configurePhase" }
Running phase: configurePhase
/build/source/tools/depends /build/source
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for ccache... no
checking for curl... /nix/store/jqkcjz37vhwab2pzy4cc20pw6bzik671-curl-8.7.1-bin/bin/curl
checking for tar... /nix/store/gnnfd78winj1lc3xb0z7j6wzm35wybwc-gnutar-1.35/bin/tar
checking for sha512sum... /nix/store/hazsx60lrysd393fw7z7vpy4g6gn4acd-coreutils-9.5/bin/sha512sum
checking for sha256sum... /nix/store/hazsx60lrysd393fw7z7vpy4g6gn4acd-coreutils-9.5/bin/sha256sum
checking for ranlib... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/ranlib
checking for ld... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/ld
checking for ar... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/ar
checking for readelf... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/readelf
checking for strip... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/strip
checking for as... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/as
checking for nm... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/nm
checking for objdump... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/objdump
checking for clang... gcc
checking for clang++... g++
checking for x86_64-linux-gnu-ranlib... no
checking for ranlib... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/ranlib
configure: WARNING: using cross tools not prefixed with host triplet
checking for x86_64-linux-gnu-ld... no
checking for ld... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/ld
checking for x86_64-linux-gnu-ar... no
checking for ar... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/ar
checking for x86_64-linux-gnu-readelf... no
checking for readelf... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/readelf
checking for x86_64-linux-gnu-strip... no
checking for strip... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/strip
checking for x86_64-linux-gnu-as... no
checking for as... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/as
checking for x86_64-linux-gnu-nm... no
checking for nm... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/nm
checking for x86_64-linux-gnu-objdump... no
checking for objdump... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/objdump
checking for x86_64-linux-gnu-gcc... no
checking for gcc... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/gcc
checking for x86_64-linux-gnu-g++... no
checking for g++... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/g++
checking for x86_64-linux-gnu-gcc... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/gcc accepts -g... yes
checking for /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/gcc option to enable C11 features... none needed
checking how to run the C preprocessor... /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/gcc -E
checking for library containing iconv_open... none required
checking whether the compiler supports GNU C++... yes
checking whether /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/g++ accepts -g... yes
checking for /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/g++ option to enable C++11 features... none needed
checking whether /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/g++ supports C++17 features with -std=c++17... yes
...skipping...
target_platform:         x11 wayland gbm
platform_includes:
ffmpeg options:  --enable-vaapi --enable-vdpau --cpu=x86_64
prefix:          /build/source/tools/depends/bin
depends:                 /build/source/tools/depends/bin/x86_64-linux-gnu-debug
subconfigure done
building jsonschemabuilder
make: Entering directory '/build/source/tools/depends/native/JsonSchemaBuilder'
rm -rf x86_64-linux-native/*; mkdir -p x86_64-linux-native/build
cd x86_64-linux-native; cp -a ../src/* .
cd x86_64-linux-native/build; /nix/store/z9w9jh0pq94vlfzsiyb3g6lrai8ba2px-cmake-3.29.2/bin/cmake -DCMAKE_INSTALL_PREFIX=/build/source/tools/depends/JsonSchemaBuilder ..
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (1.8s)
-- Generating done (0.0s)
-- Build files have been written to: /build/source/tools/depends/native/JsonSchemaBuilder/x86_64-linux-native/build
make -C x86_64-linux-native/build
make[1]: Entering directory '/build/source/tools/depends/native/JsonSchemaBuilder/x86_64-linux-native/build'
[ 50%] Building CXX object CMakeFiles/JsonSchemaBuilder.dir/JsonSchemaBuilder.cpp.o
[100%] Linking CXX executable JsonSchemaBuilder
[100%] Built target JsonSchemaBuilder
make[1]: Leaving directory '/build/source/tools/depends/native/JsonSchemaBuilder/x86_64-linux-native/build'
make -C x86_64-linux-native/build install
make[1]: Entering directory '/build/source/tools/depends/native/JsonSchemaBuilder/x86_64-linux-native/build'
[100%] Built target JsonSchemaBuilder
Install the project...
-- Install configuration: ""
-- Installing: /build/source/tools/depends/JsonSchemaBuilder/bin/JsonSchemaBuilder
make[1]: Leaving directory '/build/source/tools/depends/native/JsonSchemaBuilder/x86_64-linux-native/build'
touch .installed-x86_64-linux-native
make: Leaving directory '/build/source/tools/depends/native/JsonSchemaBuilder'
total 552K
-rwxr-xr-x 1 nixbld nixbld 552K Dec  5 22:24 JsonSchemaBuilder
building texturepacker
make: Entering directory '/build/source/tools/depends/native/TexturePacker'
rm -rf x86_64-linux-native/*; mkdir -p x86_64-linux-native/build
cd x86_64-linux-native; cp -a ../src/* .
cd x86_64-linux-native/build; /nix/store/z9w9jh0pq94vlfzsiyb3g6lrai8ba2px-cmake-3.29.2/bin/cmake -DCMAKE_INSTALL_PREFIX=/build/source/tools/depends/TexturePacker -DNATIVEPREFIX=/build/source/tools/depends/bin/x86_64-linux-gnu-native -DKODI_SOURCE_DIR=/build/source -DENABLE_STATIC=1 >
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /nix/store/i53w7x986ifmgzvb8da6zkfms4xzmdrk-gcc-wrapper-13.2.0/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /nix/store/z9w9jh0pq94vlfzsiyb3g6lrai8ba2px-cmake-3.29.2/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Lzo2 (missing: LZO2_LIBRARY)
Call Stack (most recent call first):
  /nix/store/z9w9jh0pq94vlfzsiyb3g6lrai8ba2px-cmake-3.29.2/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
  /build/source/cmake/modules/FindLzo2.cmake:22 (find_package_handle_standard_args)
  CMakeLists.txt:16 (find_package)


-- Configuring incomplete, errors occurred!
make: *** [Makefile:20: x86_64-linux-native] Error 1
make: Leaving directory '/build/source/tools/depends/native/TexturePacker'

lzo is present in nativeBuildInputs so I’m not sure what causes this. Adding Lzo2_DIR=${buildPackages.lzo} to the envvars of the second make invocation doesn’t seem to help. I don’t really know what to do about it, so any advice would be appreciated.

if you have your config on github or whatever you can just point me there too

basically i just want your expression and maybe how you income invoke it (if that is relevant… i really know nothing about cross compile :sweat:)

How is lzo used here? For the build or for use at runtire?

If it’s the latter, it needs to go in buildInputs and will not work in native if strictDeps=true

It’s enough if you just build it via pkgsCross.

I did some testing myself and I think it’s simply a colmena issue, sorry for the false alarm. See Using nixosSystem? Flake future? · Issue #60 · zhaofengli/colmena · GitHub , using nixosConfigurations and colmena together in a certain way means that overlays are duplicated somehow, so probably that was screwing something up combined with me using several interdependent overlays. In my current code I can’t even seem to reproduce it anymore. If you’d still like to look at my config, I put it at GitHub - gcoremans/nixfiles . I have a bunch of commented-out overlays, and a minimal example at minimal. The cross-compile host is gog.

Thanks a ton for the help, though!

It’s present in both buildInputs and nativeBuildInputs, so it might be used in both. But for the failure concretely, I need it for an internal vendored build dependency that I believe is only built and executed at build time. So, it’s definitely present (buildPackages.lzo works fine), but CMake cannot find it.

After some closer inspection, it looks like only the host system packages were in CMAKE_PREFIX_PATH, and not the build system dependencies I needed for TexturePacker. However, even trying to add it to CMAKE_PREFIX_PATH using CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH:${buildPackages.lzo} make [...] doesn’t seem to work and it’s still not found.

I’m not sure the deps are passed to the cmake invocation for the subproject because it happens at configure time.

I’d explore the route of also building the remaining subprojects in Nix.

You’re probably right, and I’ve started trying to do this. However, I still can’t get it to work.

I’ve split it out into another derivation made by stdenv.mkDerivation called vendortools, and then I specify that derivation in nativeBuildInputs.

However, it still seems to be trying to build that derivation for ARMv7, and so the libraries I specify in buildInputs in vendortools are ARM libraries and it cannot find the correct library. I think this is probably the problem but I have no idea why this is.

I would think that if I specify a dependency in nativeBuildInputs, Nix would try to build that dependency for the build platform, and thus also pass buildInputs as being of that platform, but this isn’t happening for some reason and I do not understand why. Adding it as a dependency to depsBuildBuild doesn’t work either.