back

by ValdikSS·1mo ago·view on hn ↗
Wow, no cross-compilation as a feature?!

Architecture emulation with qemu-userspace is 5-10x slower than running a native build.

The only 'proper' no-friction cross-compilation system I know is Debian/Ubuntu, because it allows to install foreign architecture libraries into your native system, and has all the wrappers for cross-compilation in dpkg-buildpackage.

This way you don't have to maintain cross-compiler or toolchain/sysroot, you just install whatever dependencies you need with the regular `apt install` of another architecture.

I'd like to have more friendly tooling around that instead of a slow compilation of architecture emulation.

1 comments
Thanks, I was not aware of this - will look into this more.
It is not exactly well documented, dpkg-buildpackage (debhelper) has cross-compilation wrappers for autoconf, cmake, qmake, meson, ninja, ant, perl/python, maven, gradle, bmake, golang, probably others.

Here'a s quick start for a C++ application compilation with libncurses6 and libtinfo6 dependencies as an example. `apt build-dep` will install armhf library dependencies and native other build dependencies.

    # Adding armhf architecture support to existing system
    dpkg --add-architecture armhf
    apt update
    # Installing cross-compiler for armhf
    apt install crossbuild-essential-armhf

    mkdir nload; cd nload
    apt source nload
    cd nload-0.7.4

    # Download build dependencies for nload package, for armhf
    apt build-dep -aarmhf nload
    apt install libstdc++6:armhf # build-dep misses this one

    # Cross-compiling for armhf, get .deb package for armhf
    dpkg-buildpackage -a armhf -Pcross
That's it. You get nload_0.7.4-2_armhf.deb without the need to compile libtinfo6, libncurses6 armhf first.

Here's all manual process which involves tinkering with your running system, but there are 'proper' compilation tools like sbuild which bootstrap the (container) OS, configure it for cross-compiling, and do all the required steps from a clear start, with just a `sbuild --host=armhf` call more or less.

Thanks for the detailed explanation!