build: fix cross-compile without CPU emulation

Fix cross compiling where CPU emulation is not needed, for example
building x86 packages on x86_64 machines.

This is the case with both:
* CrossCompile.UNNECESSARY
* arch != Arch.native()

Fix the logic in CrossCompile().build_chroot that returned the native
chroot in that case instead of Chroot.buildroot(arch).

Fix error:
  /usr/bin/abuild: line 2692: x86_64-alpine-linux-musl-strip: not found

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2577
This commit is contained in:
Oliver Smith 2025-03-20 16:56:55 +01:00
parent ac328581af
commit c0cdd5592d
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB

View file

@ -12,7 +12,10 @@ from pmb.core.chroot import Chroot
class CrossCompile(enum.Enum):
# Cross compilation isn't needed for this package
# Cross compilation isn't needed for this package:
# 1) Either because the arch we will build for is exactly the same as the
# native arch, or
# 2) because CPU emulation is not needed (e.g. x86 on x86_64)
UNNECESSARY = "unnecessary"
# Cross compilation disabled, only use QEMU
QEMU_ONLY = "qemu-only"
@ -49,11 +52,9 @@ class CrossCompile(enum.Enum):
return Chroot.native()
match self:
case CrossCompile.CROSSDIRECT | CrossCompile.QEMU_ONLY:
case CrossCompile.UNNECESSARY | CrossCompile.CROSSDIRECT | CrossCompile.QEMU_ONLY:
return Chroot.buildroot(arch)
# FIXME: are there cases where we're building for a different arch
# but don't need to cross compile?
case CrossCompile.UNNECESSARY | CrossCompile.CROSS_NATIVE | CrossCompile.CROSS_NATIVE2:
case CrossCompile.CROSS_NATIVE | CrossCompile.CROSS_NATIVE2:
return Chroot.native()