Skip to content
Snippets Groups Projects
Unverified Commit 661b467e authored by Oliver Smith's avatar Oliver Smith
Browse files

cross/crossdirect: support rust

Install two new wrappers to speed up cross compiling rust packages, by
using the native cross compiler.

Related: pmbootstrap#1861
parent b9f0add3
No related branches found
No related tags found
No related merge requests found
Pipeline #194342 passed
......@@ -5,21 +5,24 @@
#
# /native/usr/lib/crossdirect/armhf/gcc
# -> /native/usr/bin/armv6-alpine-linux-muslgnueabihf-gcc
# /native/usr/lib/crossdirect/armhf/rustc
# -> /native/usr/bin/rustc --target=armv6-alpine-linux-musleabihf ...
#
# 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).
# implementation details of the C version (llvm, fakeroot, rpath). The rust
# version is implemented as simple shell wrappers below.
pkgname=crossdirect
pkgver=3
pkgrel=1
pkgver=4
pkgrel=0
pkgdesc="Wrappers to launch native cross compilers in foreign chroots"
url="https://postmarketOS.org"
arch="all"
license="MIT"
options=""
options="!check"
source="crossdirect.c"
build() {
......@@ -40,27 +43,71 @@ build() {
done
}
rust_triplet() {
# Find the triplets in Alpine's rust APKBUILD or with:
# pmbootstrap chroot -barmhf --add=rust -- ls /usr/lib/rustlib
case "$1" in
x86_64)
echo "x86_64-alpine-linux-musl"
;;
armhf)
echo "arm-unknown-linux-musleabihf"
;;
armv7)
echo "armv7-unknown-linux-musleabihf"
;;
aarch64)
echo "aarch64-unknown-linux-musl"
;;
*)
echo "ERROR: don't know the rust triple for $1!" >&2
exit 1
;;
esac
}
package() {
# Architectures and binaries
_archs="x86_64 armhf armv7 aarch64"
_bins="c++ cc cpp g++ gcc clang clang++"
# Rust: crossdirect-clinker
# Invoked from native rustc, resets LD_LIBRARY_PATH and runs foreign
# arch GCC for linking
_clinker="$pkgdir/usr/lib/crossdirect/clinker"
mkdir -p "$pkgdir/usr/lib/crossdirect"
( echo "#!/bin/sh"
echo "LD_LIBRARY_PATH=/lib:/usr/lib \\"
echo ' gcc "$@"' ) > "$_clinker"
chmod +x "$_clinker"
# Iterate over architectures
for _arch in $_archs; do
[ "$_arch" == "$CARCH" ] && continue
# Put arch-specific crossdirect wrapper in arch-specific bin folder
# GCC: 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
# GCC: create compiler symlinks
for _bin in $_bins; do
ln -s "crossdirect-$_arch" "$_bin"
ln -s "crossdirect-$_arch" "$_hostspec-$_bin"
done
# Rust: arch-specific rustc wrapper
( echo "#!/bin/sh"
echo "LD_LIBRARY_PATH=/native/lib:/native/usr/lib \\"
echo " /native/usr/bin/rustc \\"
echo " -Clinker=/native/usr/lib/crossdirect/clinker \\"
echo " --target=$(rust_triplet "$_arch") \\"
echo " --sysroot=/usr \\"
echo ' "$@"' ) > "$_bindir/rustc"
chmod +x "$_bindir/rustc"
done
}
sha512sums="20b963322820de038257304c1eefa85767b78e242eda7459f06d70a1cfae5540a445aa7d5587024bf4d88a4bee28120ef9f5c2d24a648e71b542b9618318deb2 crossdirect.c"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment