On 2018-07-04 21:56, Alexander Smirnov wrote: > > On 06/29/2018 08:36 PM, Jan Kiszka wrote: >> On 2018-06-28 10:28, Alexander Smirnov wrote: >>> Add initial generation of buildchroot for cross-compilation. >>> >>> Signed-off-by: Alexander Smirnov >>> --- >>>   meta/classes/isar-bootstrap-helper.bbclass         |  5 ++ >>>   meta/conf/isar-bitbake.conf                        |  1 + >>>   .../buildchroot/buildchroot-cross.bb               | 57 >>> ++++++++++++++++++++++ >>>   3 files changed, 63 insertions(+) >>>   create mode 100644 >>> meta/recipes-devtools/buildchroot/buildchroot-cross.bb >>> >>> diff --git a/meta/classes/isar-bootstrap-helper.bbclass >>> b/meta/classes/isar-bootstrap-helper.bbclass >>> index d4f8d9a..a3ef19d 100644 >>> --- a/meta/classes/isar-bootstrap-helper.bbclass >>> +++ b/meta/classes/isar-bootstrap-helper.bbclass >>> @@ -70,6 +70,11 @@ setup_root_file_system() { >>>           -o Dir::Etc::sourcelist="sources.list.d/isar-apt.list" \ >>>           -o Dir::Etc::sourceparts="-" \ >>>           -o APT::Get::List-Cleanup="0" >>> +    # Add multiarch for cross-target >>> +    if [ "${ROOTFS_ARCH}" != "${DISTRO_ARCH}" ]; then >>> +        sudo -E chroot "$ROOTFSDIR" /usr/bin/dpkg --add-architecture >>> ${DISTRO_ARCH} >>> +        sudo -E chroot "$ROOTFSDIR" /usr/bin/apt-get update >>> +    fi >>>       sudo -E chroot "$ROOTFSDIR" \ >>>           /usr/bin/apt-get ${APT_ARGS} --download-only $PACKAGES \ >>>               ${IMAGE_TRANSIENT_PACKAGES} >>> diff --git a/meta/conf/isar-bitbake.conf b/meta/conf/isar-bitbake.conf >>> index ead7798..1412508 100644 >>> --- a/meta/conf/isar-bitbake.conf >>> +++ b/meta/conf/isar-bitbake.conf >>> @@ -22,6 +22,7 @@ WORKDIR = >>> "${TMPDIR}/work/${DISTRO}-${DISTRO_ARCH}/${PF}" >>>   DL_DIR = "${TOPDIR}/downloads" >>>   SSTATE_DIR ?= "${TMPDIR}/sstate-cache" >>>   BUILDCHROOT_DIR = >>> "${TMPDIR}/work/${DISTRO}-${DISTRO_ARCH}/buildchroot/rootfs" >>> +BUILDCHROOT_CROSS_DIR = >>> "${TMPDIR}/work/${DISTRO}-${DISTRO_ARCH}/buildchroot-cross/rootfs" >>>   CACHE = "${TMPDIR}/cache" >>>     OVERRIDES_append = ":${DISTRO}:${DISTRO_ARCH}" >>> diff --git a/meta/recipes-devtools/buildchroot/buildchroot-cross.bb >>> b/meta/recipes-devtools/buildchroot/buildchroot-cross.bb >>> new file mode 100644 >>> index 0000000..bc0bc66 >>> --- /dev/null >>> +++ b/meta/recipes-devtools/buildchroot/buildchroot-cross.bb >>> @@ -0,0 +1,57 @@ >>> +# Root filesystem for packages cross-building >>> +# >>> +# This software is a part of ISAR. >>> +# Copyright (C) 2015-2016 ilbers GmbH >>> + >>> +DESCRIPTION = "Isar development cross-filesystem" >>> + >>> +LICENSE = "gpl-2.0" >>> +LIC_FILES_CHKSUM = >>> "file://${LAYERDIR_isar}/licenses/COPYING.GPLv2;md5=751419260aa954499f7abaabaa882bbe" >>> >>> + >>> +FILESPATH_prepend := "${THISDIR}/files:" >>> +SRC_URI = "file://configscript.sh \ >>> +           file://build.sh" >>> +PV = "1.0" >>> + >>> +inherit isar-bootstrap-helper >>> + >>> +BUILDCHROOT_CROSS_PREINSTALL ?= "make \ >>> +                                 debhelper \ >>> +                                 autotools-dev \ >>> +                                 dpkg \ >>> +                                 locales \ >>> +                                 docbook-to-man \ >>> +                                 apt \ >>> +                                 automake \ >>> +                                 devscripts \ >>> +                                 equivs \ >>> +                                 libc6:${DISTRO_ARCH}" >>> + >>> +# Please note: this works for Stretch distro only. According to the >>> wiki page: >>> +#     https://wiki.debian.org/CrossToolchains >>> +# Jessie doesn't contain toolchain. It should be fetched from the >>> external >>> +# repository: >>> +#     http://emdebian.org/tools/debian/ >>> +BUILDCHROOT_CROSS_PREINSTALL_append_armhf += >>> "binutils-arm-linux-gnueabihf \ >>> +                                              >>> crossbuild-essential-armhf" >>> + >>> +WORKDIR = "${TMPDIR}/work/${DISTRO}-${DISTRO_ARCH}/${PN}" >>> + >>> +do_build[stamp-extra-info] = "${DISTRO}-${DISTRO_ARCH}" >>> +do_build[root_cleandirs] = "${BUILDCHROOT_CROSS_DIR} \ >>> +                            ${BUILDCHROOT_CROSS_DIR}/isar-apt \ >>> +                            ${BUILDCHROOT_CROSS_DIR}/downloads \ >>> +                            ${BUILDCHROOT_CROSS_DIR}/home/builder" >>> +do_build[depends] = "isar-apt:do_cache_config >>> isar-bootstrap-host:do_deploy" >>> + >>> +do_build() { >>> +    setup_root_file_system --host-arch "${BUILDCHROOT_CROSS_DIR}" >>> ${BUILDCHROOT_CROSS_PREINSTALL} >>> + >>> +    # Install package builder script >>> +    sudo chmod -R a+rw "${BUILDCHROOT_CROSS_DIR}/home/builder" >>> +    sudo install -m 755 ${WORKDIR}/build.sh >>> ${BUILDCHROOT_CROSS_DIR}/build.sh >>> + >>> +    # Configure root filesystem >>> +    sudo install -m 755 ${WORKDIR}/configscript.sh >>> ${BUILDCHROOT_CROSS_DIR} >>> +    sudo chroot ${BUILDCHROOT_CROSS_DIR} /configscript.sh >>> +} >>> >> >> This is almost identical to buildchroot:do_build - except for one >> differently named variable, the first line, and missing fix >> 39e0c488d8b2. Please avoid those duplications. >> > > Sorry, didn't get this. It's absolutely different logical units: No, the code is identical. Step back, look at it again. >  - crossbuildchroot has its own lifecycle including stamps, so it could > not be shared with the original buildchroot (only via common include) >  - crossbuildchroot and buildchroot have different default packages to > install and they are incompatible due to possibly different > architectures (cross has always host one, bchroot has target one). > > Could you please clarify what you mean here? I'm not suggesting to have only a single recipe. I'm asking to pull out identical code into a shared function, class, whatever so that we can maintain identical logic in one place (and fix bugs only once). Jan