pmaports/cross/crossdirect/APKBUILD
Oliver Smith 2c07f28419
cross/crossdirect: use qemu when linking (!318)
Cross linker (e.g. ld from binutils-armhf) does not support any method
of setting additional link paths, and this causes problems when building
various packages. Work around this problem by calling the qemu binary
instead of the cross binary from the native chroot, whenever we are
linking.

I have tested that this allows successfully building hello-world,
coreinfo, libhybris for armhf. So this fixes #227 and fixes #228.

Regarding performance, this is the same way as distcc does it. We would
get a performance gain if we were able to use the cross-linker. But so
far I could not figure out how to patch the binutils source to make it
work like we want to have it. Maybe I'll ask on some binutils mailing
list for advice. In the meantime, this workaround should make
crossdirect work for all use-cases, and it is still faster than the
previous distcc setup, because we can avoid the overhead of setting up
and running a ssh server locally to work around missing authentication
in distcc (see pmbootstrap!1649). Let's test this for some more time,
and then make a pmbootstrap release that rolls out crossdirect for
everyone.
2019-04-14 04:03:21 +02:00

66 lines
2 KiB
Text

# Wrapper for the "crossdirect" compilation method.
# pmbootstrap mounts the native chroot in the foreign arch (e.g. armhf) chroot
# as /native. This package gets installed into the native chroot, and creates
# wrappers like:
#
# /native/usr/lib/crossdirect/armhf/gcc
# -> /native/usr/bin/armv6-alpine-linux-muslgnueabihf-gcc
#
# When building packages in the armhf chroot, PATH will get prepended with
# "/native/usr/lib/crossdirect/armhf". The end game is of course invoking the
# cross compiler from the native chroot, running at native speed, whenever
# calling the compiler from the foreign arch chroot. See crossdirect.c for
# implementation details (llvm, fakeroot, rpath).
pkgname=crossdirect
pkgver=3
pkgrel=0
pkgdesc="Wrappers to launch native cross compilers in foreign chroots"
url="https://postmarketOS.org"
arch="all"
license="MIT"
options=""
source="crossdirect.c"
build() {
cd "$srcdir"
# Architectures and binaries
_archs="x86_64 armhf armv7 aarch64"
for _arch in $_archs; do
[ "$_arch" == "$CARCH" ] && continue
_hostspec="$(arch_to_hostspec $_arch)"
# Build with -Werror, because we maintain this short program. (If
# upstream is elsewhere, having -Werror is usually not desired.)
$CC -o "crossdirect-$_arch" \
-static \
-Werror \
-DHOSTSPEC="\"$_hostspec\"" \
crossdirect.c
done
}
package() {
# Architectures and binaries
_archs="x86_64 armhf armv7 aarch64"
_bins="c++ cc cpp g++ gcc clang clang++"
# Iterate over architectures
for _arch in $_archs; do
[ "$_arch" == "$CARCH" ] && continue
# Put arch-specific crossdirect wrapper in arch-specific bin folder
_bindir="$pkgdir/usr/lib/crossdirect/$_arch"
_hostspec="$(arch_to_hostspec $_arch)"
mkdir -p "$_bindir"
cd "$_bindir"
cp "$srcdir/crossdirect-$_arch" "./"
# Create compiler symlinks
for _bin in $_bins; do
ln -s "crossdirect-$_arch" "$_bin"
ln -s "crossdirect-$_arch" "$_hostspec-$_bin"
done
done
}
sha512sums="f8366add6ba2ac6d9f8af89f389c69914009b12b21e6608121a78d1cd9afe287e24eafb0c21d80d096df9eee9a23cc2e6a5408f6355e27be05203186a0bf9814 crossdirect.c"