Hi,
I’m trying to cross compile a simple rust hello-world to ARM (specifically armv7 for a raspberry-pi 2).
I have a setup here: GitHub - backuitist/wake-on-lan-rust-armv7: Experimenting cross-compiliation with Nix
Trying to build this with
nix build --arg crossSystem ' { config = "armv7l-unknown-linux-gnueabihf"; }'
would result in a ton of dependencies (including git and perl) to be built for ARM.
I looked a bit at my dependencies:
$ nix-instantiate default.nix --arg crossSystem ' { config = "armv7l-unknown-linux-gnueabihf"; }'
/nix/store/w5nb5hymc5jda35fjxpklzhd5mf1jhfn-raspberry-hello-world-armv7l-unknown-linux-gnueabihf.drv
$ nix-store -q --references /nix/store/w5nb5hymc5jda35fjxpklzhd5mf1jhfn-raspberry-hello-world-armv7l-unknown-linux-gnueabihf.drv
/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh
/nix/store/02ws9mxmqizbw50027xq7dqq5cskjms5-bash-4.4-p23.drv
/nix/store/sjd41awxa0h0xh9pbrlnqr9a775zmmgm-stdenv-linux.drv
/nix/store/cg3rvy8xn44m8cgpmkp8mv6vgfsnhh14-nss-cacert-3.38-armv7l-unknown-linux-gnueabihf.drv
/nix/store/nk6b2ckznjic5wj8ddw0wgdrn4mbz3lg-patch-registry-deps
/nix/store/vysvbmbynbmzyfk4s85612a78xi4q673-git-2.18.0-armv7l-unknown-linux-gnueabihf.drv
/nix/store/z5zicpii1i7ncbig7rxa9vv0sacpyq75-rustc-1.27.0-armv7l-unknown-linux-gnueabihf.drv
/nix/store/n09y5ww85b4gfz5n2sdsla1q6yxs1mis-cargo-1.27.0-armv7l-unknown-linux-gnueabihf.drv
/nix/store/q2hizgmxb681zhk4nql04qi8dwk6lk6d-hello-world
/nix/store/812y7jibpb8hbpvbcf45gmhzr8yw4wip-raspberry-hello-world-vendor.drv
As you can see Nix tries to build git for armv7? Would it be possible to use git for the host platform as I don’t think git for ARM would be of any use?
Another thing is that amongst the requisites is perl. It seems that git brings this to the party. I’ve briefly looked into the git derivation and it seems that perl could be removed from git’s dependencies (although I don’t understand how this option could affect the derivation…): nixpkgs/default.nix at master · NixOS/nixpkgs · GitHub
Trying to build this would anyway fail as down the line, nix would try to run the perl-for-arm on the host machine, resulting in an execution failure.
> nix build --arg crossSystem ' { config = "armv7l-unknown-linux-gnueabihf"; }'
builder for '/nix/store/0f9bczppi3ch6h3075gg05fy4qfkgb4c-perl-TermReadKey-2.37-armv7l-unknown-linux-gnueabihf.drv' failed with exit code 2; last 10 log lines:
armv7l-unknown-linux-gnueabihf-gcc -c -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fwrapv -fno-strict-aliasing -DVERSION=\"2.37\" -DXS_VERSION=\"2.37\" -fPIC -Wno-unused-function "-I/nix/store/v11ji6vm0sxdl7rn7sq56ql5kjxdqgk6-perl-5.24.4-armv7l-unknown-linux-gnueabihf/lib/perl5/5.24.4/armv7l-linux/CORE" ReadKey.c
rm -f blib/arch/auto/Term/ReadKey/ReadKey.so
armv7l-unknown-linux-gnueabihf-gcc -shared ReadKey.o -o blib/arch/auto/Term/ReadKey/ReadKey.so \
\
chmod 755 blib/arch/auto/Term/ReadKey/ReadKey.so
"/nix/store/30jw9gz12n7pkzqab1w9pyi1mi4nnlsk-perl-5.24.4-armv7l-unknown-linux-gnueabihf-dev/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- ReadKey.bs blib/arch/auto/Term/ReadKey/ReadKey.bs 644
"/nix/store/v11ji6vm0sxdl7rn7sq56ql5kjxdqgk6-perl-5.24.4-armv7l-unknown-linux-gnueabihf/bin/perl" "-Iblib/arch" "-Iblib/lib" ReadKey_pm.PL ReadKey.pm
/nix/store/56nrxy58wbhvs2sy3rir1jqa68p0kkm5-bash-4.4-p23/bin/bash: /nix/store/v11ji6vm0sxdl7rn7sq56ql5kjxdqgk6-perl-5.24.4-armv7l-unknown-linux-gnueabihf/bin/perl: cannot execute binary file: Exec format error
make: *** [Makefile:532: ReadKey.pm] Error 126
cannot build derivation '/nix/store/vysvbmbynbmzyfk4s85612a78xi4q673-git-2.18.0-armv7l-unknown-linux-gnueabihf.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/w5nb5hymc5jda35fjxpklzhd5mf1jhfn-raspberry-hello-world-armv7l-unknown-linux-gnueabihf.drv': 1 dependencies couldn't be built
[0 built (1 failed)]
Not surprisingly:
file /nix/store/v11ji6vm0sxdl7rn7sq56ql5kjxdqgk6-perl-5.24.4-armv7l-unknown-linux-gnueabihf/bin/perl
/nix/store/v11ji6vm0sxdl7rn7sq56ql5kjxdqgk6-perl-5.24.4-armv7l-unknown-linux-gnueabihf/bin/perl: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /nix/store/h0iynmqx9mq8dvghi28xp29p06659y69-glibc-2.27-armv7l-unknown-linux-gnueabihf/lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, not stripped
Any suggestion?
Thanks,
Bruno