[v3,12/16] Add compat architecture support via multiarch

Message ID 970e3659843f28908d0cd08d6604ebbfac6c9cf0.1600788534.git.jan.kiszka@siemens.com
State Accepted, archived
Headers show
Series Complete backlog: SDK, compat arch, assorting fixed and cleanups | expand

Commit Message

Jan Kiszka Sept. 22, 2020, 7:28 a.m. UTC
From: Jan Kiszka <jan.kiszka@siemens.com>

Allow building and installing 32-bit packages an 64-bit architectures
that support this. Namely, these are amd64 and arm64 for us so far,
minus stretch-amd64 which lacks crossbuild-essential-i386 in that
version.

Control the target architecture of a package is added via the
PACKAGE_ARCH variable that defaults to DISTRO_ARCH. When set to
COMPAT_DISTRO_ARCH, the package is built for i386 on amd64 and armhf on
arm64.

If the build environment and the target image should contain the compat
arch is controlled via setting ISAR_ENABLE_COMPAT_ARCH to 1.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 meta-isar/conf/local.conf.sample                   |  5 +++++
 meta/classes/dpkg.bbclass                          |  8 +++++---
 meta/conf/bitbake.conf                             |  3 ++-
 meta/conf/distro/debian-common.conf                |  3 +++
 .../recipes-core/isar-bootstrap/isar-bootstrap.inc | 14 +++++++++++++-
 meta/recipes-devtools/buildchroot/buildchroot.inc  |  5 +++++
 meta/recipes-devtools/sdkchroot/sdkchroot.bb       |  1 +
 7 files changed, 34 insertions(+), 5 deletions(-)

Comments

Baurzhan Ismagulov Sept. 24, 2020, 12:19 p.m. UTC | #1
On Tue, Sep 22, 2020 at 05:28:50PM +0200, Jan Kiszka wrote:
> Allow building and installing 32-bit packages an 64-bit architectures
> that support this. Namely, these are amd64 and arm64 for us so far,
> minus stretch-amd64 which lacks crossbuild-essential-i386 in that
> version.
> 
> Control the target architecture of a package is added via the
> PACKAGE_ARCH variable that defaults to DISTRO_ARCH. When set to
> COMPAT_DISTRO_ARCH, the package is built for i386 on amd64 and armhf on
> arm64.
> 
> If the build environment and the target image should contain the compat
> arch is controlled via setting ISAR_ENABLE_COMPAT_ARCH to 1.

Looks like a clean implementation, thanks. Applied 12-15/16 to have this in
earlier than later.

With kind regards,
Baurzhan.

Patch

diff --git a/meta-isar/conf/local.conf.sample b/meta-isar/conf/local.conf.sample
index e842c129..2f82020d 100644
--- a/meta-isar/conf/local.conf.sample
+++ b/meta-isar/conf/local.conf.sample
@@ -175,6 +175,11 @@  IMAGE_INSTALL = "hello-isar example-raw example-module-${KERNEL_NAME} enable-fsc
 # Enable cross-compilation support
 ISAR_CROSS_COMPILE ?= "0"
 
+#
+# Uncomment to enable 32-bit compat architecture support
+# NOTE: this works for amd64 and arm64 targets so far
+#ISAR_ENABLE_COMPAT_ARCH ?= "1"
+
 #
 # Uncomment this to enable use of cached base repository
 #ISAR_USE_CACHED_BASE_REPO ?= "1"
diff --git a/meta/classes/dpkg.bbclass b/meta/classes/dpkg.bbclass
index acccc1f2..a24386df 100644
--- a/meta/classes/dpkg.bbclass
+++ b/meta/classes/dpkg.bbclass
@@ -3,16 +3,18 @@ 
 
 inherit dpkg-base
 
+PACKAGE_ARCH ?= "${DISTRO_ARCH}"
+
 # Install build dependencies for package
 do_install_builddeps() {
     dpkg_do_mounts
     E="${@ isar_export_proxies(d)}"
     deb_dl_dir_import "${BUILDCHROOT_DIR}"
     sudo -E chroot ${BUILDCHROOT_DIR} /isar/deps.sh \
-        ${PP}/${PPS} ${DISTRO_ARCH} --download-only
+        ${PP}/${PPS} ${PACKAGE_ARCH} --download-only
     deb_dl_dir_export "${BUILDCHROOT_DIR}"
     sudo -E chroot ${BUILDCHROOT_DIR} /isar/deps.sh \
-        ${PP}/${PPS} ${DISTRO_ARCH}
+        ${PP}/${PPS} ${PACKAGE_ARCH}
     dpkg_undo_mounts
 }
 
@@ -27,5 +29,5 @@  dpkg_runbuild() {
     E="${@ isar_export_proxies(d)}"
     export PARALLEL_MAKE="${PARALLEL_MAKE}"
     sudo -E chroot --userspec=$( id -u ):$( id -g ) ${BUILDCHROOT_DIR} \
-         /isar/build.sh ${PP}/${PPS} ${DISTRO_ARCH}
+         /isar/build.sh ${PP}/${PPS} ${PACKAGE_ARCH}
 }
diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 44ded532..a3e2af2c 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -62,8 +62,9 @@  KERNEL_FILE ?= "vmlinuz"
 KERNEL_FILE_mipsel ?= "vmlinux"
 KERNEL_FILE_riscv64 ?= "vmlinux"
 
-OVERRIDES = "${DISTRO_ARCH}:${MACHINE}:${DISTRO}:forcevariable"
+OVERRIDES = "${DISTRO_ARCH}:${COMPAT_OVERRIDE}:${MACHINE}:${DISTRO}:forcevariable"
 FILESOVERRIDES = "${DISTRO_ARCH}:${MACHINE}"
+COMPAT_OVERRIDE = "${@'compat-arch' if d.getVar('ISAR_ENABLE_COMPAT_ARCH') == '1' else ''}"
 
 # Setting default QEMU_ARCH variables for different DISTRO_ARCH:
 QEMU_ARCH_amd64 = "x86_64"
diff --git a/meta/conf/distro/debian-common.conf b/meta/conf/distro/debian-common.conf
index 7d681c49..582678f6 100644
--- a/meta/conf/distro/debian-common.conf
+++ b/meta/conf/distro/debian-common.conf
@@ -22,3 +22,6 @@  GRUB_BOOTLOADER_INSTALL_armhf = "grub-efi-arm-bin"
 GRUB_BOOTLOADER_INSTALL_arm64 = "grub-efi-arm64-bin"
 
 SYSLINUX_BOOTLOADER_INSTALL = "syslinux syslinux-common"
+
+COMPAT_DISTRO_ARCH_amd64 = "i386"
+COMPAT_DISTRO_ARCH_arm64 = "armhf"
diff --git a/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc b/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
index da0d436b..fbfe669d 100644
--- a/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
+++ b/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
@@ -222,7 +222,7 @@  def get_host_release():
     rel = platform.release()
     return rel
 
-do_bootstrap[vardeps] += "DISTRO_APT_PREMIRRORS"
+do_bootstrap[vardeps] += "DISTRO_APT_PREMIRRORS ISAR_ENABLE_COMPAT_ARCH"
 do_bootstrap[dirs] = "${DEPLOY_DIR_BOOTSTRAP}"
 do_bootstrap[depends] = "base-apt:do_cache"
 
@@ -236,6 +236,14 @@  isar_bootstrap() {
         esac
         shift
     done
+    if [ "${ISAR_ENABLE_COMPAT_ARCH}" = "1" ]; then
+        if [ -z "${COMPAT_DISTRO_ARCH}" ]; then
+            bbfatal "${DISTRO_ARCH} does not have a compat arch"
+        fi
+        if [ "${@get_distro_suite(d, True)}-${COMPAT_DISTRO_ARCH}" = "stretch-i386" ]; then
+            bbfatal "compat arch build for stretch-i386 not supported"
+        fi
+    fi
     debootstrap_args="--verbose --variant=minbase --include=${DISTRO_BOOTSTRAP_BASE_PACKAGES}"
     if [ -f "${DISTRO_BOOTSTRAP_KEYRING}" ]; then
         debootstrap_args="$debootstrap_args --keyring=${DISTRO_BOOTSTRAP_KEYRING}"
@@ -330,6 +338,10 @@  isar_bootstrap() {
                 chroot "${ROOTFSDIR}" /usr/bin/dpkg --add-architecture ${DISTRO_ARCH}
             fi
 
+            if [ "${ISAR_ENABLE_COMPAT_ARCH}" = "1" ]; then
+                chroot "${ROOTFSDIR}" /usr/bin/dpkg --add-architecture ${COMPAT_DISTRO_ARCH}
+            fi
+
             chroot "${ROOTFSDIR}" /usr/bin/apt-get update -y
             chroot "${ROOTFSDIR}" /usr/bin/apt-get install -y -f
             chroot "${ROOTFSDIR}" /usr/bin/apt-get dist-upgrade -y \
diff --git a/meta/recipes-devtools/buildchroot/buildchroot.inc b/meta/recipes-devtools/buildchroot/buildchroot.inc
index b4d7b764..835968de 100644
--- a/meta/recipes-devtools/buildchroot/buildchroot.inc
+++ b/meta/recipes-devtools/buildchroot/buildchroot.inc
@@ -22,7 +22,12 @@  ROOTFS_CLEAN_FILES = ""
 ROOTFS_MANIFEST_DEPLOY_DIR = "${DEPLOY_DIR_BUILDCHROOT}"
 ROOTFS_FEATURES += "generate-manifest"
 
+BUILDCHROOT_COMPAT_PREINSTALL_compat-arch = " \
+    libc6:${COMPAT_DISTRO_ARCH} \
+    crossbuild-essential-${COMPAT_DISTRO_ARCH}"
+
 BUILDCHROOT_PREINSTALL_COMMON = " \
+    ${BUILDCHROOT_COMPAT_PREINSTALL} \
     make \
     debhelper \
     autotools-dev \
diff --git a/meta/recipes-devtools/sdkchroot/sdkchroot.bb b/meta/recipes-devtools/sdkchroot/sdkchroot.bb
index 82b430b3..c96cc772 100644
--- a/meta/recipes-devtools/sdkchroot/sdkchroot.bb
+++ b/meta/recipes-devtools/sdkchroot/sdkchroot.bb
@@ -22,6 +22,7 @@  DEPENDS += "${SDK_INSTALL}"
 TOOLCHAIN = "crossbuild-essential-${DISTRO_ARCH}"
 TOOLCHAIN_${HOST_ARCH} = "build-essential"
 TOOLCHAIN_i386 = "build-essential"
+TOOLCHAIN_append_compat-arch = " crossbuild-essential-${COMPAT_DISTRO_ARCH}"
 
 inherit rootfs
 ROOTFS_ARCH = "${HOST_ARCH}"