From d1062b2e28c10adac5c5bb1f995d1097d71571dd Mon Sep 17 00:00:00 2001 From: Matthias Luescher Date: Fri, 6 Dec 2024 14:39:59 +0100 Subject: [PATCH] Upgraded patch for Mender package builds. --- ...oss-compilation-on-arm64-use-podman.patch} | 101 ++++++--------- .github/patches/mender/Dockerfile.patch | 117 ------------------ .../patches/mender/mender-deb-package.patch | 47 ------- .github/scripts/build-mender-packages | 2 +- 4 files changed, 36 insertions(+), 231 deletions(-) rename .github/patches/mender/{0001-Removed-Raspbian-specific-setup-allow-cross-compilat.patch => 0001-Allow-cross-compilation-on-arm64-use-podman.patch} (64%) delete mode 100644 .github/patches/mender/Dockerfile.patch delete mode 100644 .github/patches/mender/mender-deb-package.patch diff --git a/.github/patches/mender/0001-Removed-Raspbian-specific-setup-allow-cross-compilat.patch b/.github/patches/mender/0001-Allow-cross-compilation-on-arm64-use-podman.patch similarity index 64% rename from .github/patches/mender/0001-Removed-Raspbian-specific-setup-allow-cross-compilat.patch rename to .github/patches/mender/0001-Allow-cross-compilation-on-arm64-use-podman.patch index 2090a4c..436a00e 100644 --- a/.github/patches/mender/0001-Removed-Raspbian-specific-setup-allow-cross-compilat.patch +++ b/.github/patches/mender/0001-Allow-cross-compilation-on-arm64-use-podman.patch @@ -1,16 +1,15 @@ -From 5dd05921a17a02366a0624cd233c2179f63ba4de Mon Sep 17 00:00:00 2001 +From 1813d0dee11b077df0d34de26e47168909b65757 Mon Sep 17 00:00:00 2001 From: Matthias Luescher -Date: Fri, 28 Jun 2024 13:50:26 +0200 -Subject: [PATCH] Removed Raspbian specific setup, allow cross compilation on - arm64. +Date: Fri, 6 Dec 2024 14:36:20 +0100 +Subject: [PATCH] Allow cross compilation on arm64, use podman. --- - docker-build-package | 26 ++++++++-------- - mender-deb-package | 70 +++++++++++++++++++++++++------------------- - 2 files changed, 52 insertions(+), 44 deletions(-) + docker-build-package | 22 +++++++++--------- + mender-deb-package | 53 +++++++++++++++++++++++++++++++------------- + 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/docker-build-package b/docker-build-package -index eafb1a4..01f22fb 100755 +index 600b6db..7b916a2 100755 --- a/docker-build-package +++ b/docker-build-package @@ -16,7 +16,7 @@ @@ -22,7 +21,7 @@ index eafb1a4..01f22fb 100755 declare -A mender_client_props=( [recipe_name]="mender-client" -@@ -138,8 +138,10 @@ if [ $commercial = "true" -a -z "${MENDER_PRIVATE_REPO_ACCESS_TOKEN}" ]; then +@@ -139,8 +139,10 @@ if [ $commercial = "true" -a -z "${MENDER_PRIVATE_REPO_ACCESS_TOKEN}" ]; then exit 1 fi @@ -35,7 +34,7 @@ index eafb1a4..01f22fb 100755 echo "Not building arch independent package $recipe_name on architecture $ARCH" exit 0 fi -@@ -155,31 +157,27 @@ orig_dir="output/orig" +@@ -156,18 +158,18 @@ orig_dir="output/orig" mkdir -p "${output_dir}" "${orig_dir}" @@ -59,13 +58,8 @@ index eafb1a4..01f22fb 100755 echo "Including source packages in the build." BUILD_TYPE="source,${BUILD_TYPE}" fi +@@ -180,7 +182,7 @@ fi - PLATFORM="" - --if [ "$ARCH" = "armhf" -a "$DISTRO" = "debian" ]; then -- PLATFORM="--platform=linux/arm/v6" --fi -- echo -docker run --rm \ @@ -73,33 +67,29 @@ index eafb1a4..01f22fb 100755 --volume $(pwd)/recipes:/recipes \ --volume $(pwd)/${output_dir}:/output \ --volume $(pwd)/${orig_dir}:/orig \ -@@ -188,7 +186,7 @@ docker run --rm \ +@@ -189,7 +191,7 @@ docker run --rm \ --env MENDER_PRIVATE_GPG_KEY_BUILD \ --env OVERRIDE_DEBIAN_SUFFIX \ ${PLATFORM} \ -- ${IMAGE_NAME_PREFIX}-${DISTRO}-${RELEASE}-${ARCH}-${IMAGE_VERSION:-master} \ +- ${IMAGE_NAME_PREFIX}-${BUILD}-${DISTRO}-${RELEASE}-${ARCH}-${IMAGE_VERSION:-master} \ + ${IMAGE_NAME_PREFIX}-${DISTRO}-${RELEASE} \ /script \ ${recipe_name} \ ${BUILD_TYPE} \ diff --git a/mender-deb-package b/mender-deb-package -index 291de2c..d410429 100755 +index 42d5f7d..f8cfb4e 100755 --- a/mender-deb-package +++ b/mender-deb-package -@@ -61,11 +61,8 @@ checkout_repo() { +@@ -61,7 +61,7 @@ checkout_repo() { install_go() { local GOLANG_VERSION=1.21.1 - local GOLANG_ARCH=amd64 + local GOLANG_ARCH=${HOST_ARCHITECTURE} local golang_version_set -- if [ $ARCH = "armhf" -a $OS_DISTRO = "debian" ]; then -- local GOLANG_ARCH=armv6l -- fi - - golang_version_set=$(sed -n '/[^ ]*GOLANG_VERSION:[ "0-9]/{s/.*GOLANG_VERSION:[ ]*\(["0-9\.]*\).*/\1/p;q}' .gitlab-ci.yml) - golang_version_set=${golang_version_set//\"/} -@@ -232,46 +229,57 @@ build_packages() { + if [ $ARCH = "armhf" -a $OS_DISTRO = "raspbian" ]; then + local GOLANG_ARCH=armv6l +@@ -234,11 +234,23 @@ build_packages() { case "$ARCH" in amd64) @@ -108,60 +98,40 @@ index 291de2c..d410429 100755 - ${sign_flags} \ - ${dpkg_build_ignore_flag} \ - --build=$DEB_BUILD_TYPE -- ;; -- -- armhf) -- if [ "$OS_DISTRO" = "debian" ]; then -- # Native build (emulated ARM v6) -- dpkg-buildpackage \ -- ${sign_flags} \ -- ${dpkg_build_ignore_flag} \ -- --build=$DEB_BUILD_TYPE -- else -- # Debian ARM 32bit toolchain -- CROSS_COMPILE="arm-linux-gnueabihf" \ + if [ "$ARCH" != "${HOST_ARCHITECTURE}" ]; then + CROSS_COMPILE="x86_64-linux-gnu" \ - CC="$CROSS_COMPILE-gcc" \ -- PKG_CONFIG_PATH="/usr/lib/arm-linux-gnueabihf/pkgconfig/" \ -- GOARCH=arm \ ++ CC="$CROSS_COMPILE-gcc" \ + PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig/" \ + GOARCH=amd64 \ - dpkg-buildpackage \ -- --target-arch armhf \ ++ dpkg-buildpackage \ + --target-arch amd64 \ - ${sign_flags} \ - ${dpkg_build_ignore_flag} \ - --build=$DEB_BUILD_TYPE ++ ${sign_flags} \ ++ ${dpkg_build_ignore_flag} \ ++ --build=$DEB_BUILD_TYPE + else + # Native build (amd64) + dpkg-buildpackage \ + ${sign_flags} \ + ${dpkg_build_ignore_flag} \ + --build=$DEB_BUILD_TYPE - fi ++ fi + ;; + + armhf) +@@ -263,16 +275,23 @@ build_packages() { ;; -- arm64) + arm64) - # Debian ARM 64bit toolchain - CROSS_COMPILE="aarch64-linux-gnu" \ -+ armhf) -+ # Debian ARM 32bit toolchain -+ CROSS_COMPILE="arm-linux-gnueabihf" \ - CC="$CROSS_COMPILE-gcc" \ +- CC="$CROSS_COMPILE-gcc" \ - PKG_CONFIG_PATH="/usr/lib/aarch64-linux-gnu/pkgconfig/" \ - GOARCH=arm64 \ -+ PKG_CONFIG_PATH="/usr/lib/arm-linux-gnueabihf/pkgconfig/" \ -+ GOARCH=arm \ - dpkg-buildpackage \ +- dpkg-buildpackage \ - --target-arch arm64 \ -+ --target-arch armhf \ - ${sign_flags} \ - ${dpkg_build_ignore_flag} \ - --build=$DEB_BUILD_TYPE - ;; -+ -+ arm64) +- ${sign_flags} \ +- ${dpkg_build_ignore_flag} \ +- --build=$DEB_BUILD_TYPE + if [ "$ARCH" != "${HOST_ARCHITECTURE}" ]; then + # Debian ARM 64bit toolchain + CROSS_COMPILE="aarch64-linux-gnu" \ @@ -179,11 +149,10 @@ index 291de2c..d410429 100755 + ${dpkg_build_ignore_flag} \ + --build=$DEB_BUILD_TYPE + fi -+ ;; + ;; esac } - -@@ -298,6 +306,8 @@ copy_deb_packages() { +@@ -300,6 +319,8 @@ copy_deb_packages() { # Run script # ############## diff --git a/.github/patches/mender/Dockerfile.patch b/.github/patches/mender/Dockerfile.patch deleted file mode 100644 index 9fb8286..0000000 --- a/.github/patches/mender/Dockerfile.patch +++ /dev/null @@ -1,117 +0,0 @@ ---- Dockerfile 2022-12-10 10:42:58.483487231 +0100 -+++ Dockerfile.armhf 2022-12-10 10:46:42.585441703 +0100 -@@ -25,92 +25,21 @@ - RUN dpkg --add-architecture ${ARCH} && \ - apt-get update - --RUN if ! [ "${DISTRO}" = "debian" -a "${ARCH}" = "armhf" ]; then \ -- apt-get install -y \ -- pkg-config \ -- liblzma-dev:${ARCH} \ -- libssl-dev:${ARCH} \ -- libglib2.0-dev:${ARCH} \ -- libmount-dev:${ARCH} \ -- libc-dev:${ARCH} \ -- libc6-dev:${ARCH} \ -- linux-libc-dev:${ARCH} \ -- ; \ -- fi -- --# To provide support for Raspberry Pi Zero W a toolchain tuned for ARMv6 architecture must be used. --# https://tracker.mender.io/browse/MEN-2399 --ENV ARMV6_TOOLCHAIN_ROOT="/armv6-eabihf--glibc--stable-2020.08-1" --RUN if [ "${DISTRO}" = "debian" -a "${ARCH}" = "armhf" ]; then \ -- wget -nc -q https://toolchains.bootlin.com/downloads/releases/toolchains/armv6-eabihf/tarballs/armv6-eabihf--glibc--stable-2020.08-1.tar.bz2 \ -- && tar -xjf armv6-eabihf--glibc--stable-2020.08-1.tar.bz2 \ -- && rm armv6-eabihf--glibc--stable-2020.08-1.tar.bz2; \ -- fi -- --# Get depdendencies from upstream, manually donwloading deb packages, and fake pkg-config. --# NOTE: pkg-config is used from go build to obtain cflags and libs required to build C code; however --# for armhf we will explicitly pass these flags for go to use our custom sysroot instead of the system --# one. Alternatively pkg-config supports setting a prefix, but that would require patching the source code. --RUN if [ "${DISTRO}" = "debian" -a "${ARCH}" = "armhf" ]; then \ -- set -e; \ -- ln -s /bin/true /usr/bin/pkg-config; \ -- curl -f http://raspbian.raspberrypi.org/raspbian/dists/${VERSION}/main/binary-armhf/Packages.gz -o Packages.gz; \ -- gunzip Packages.gz; \ -- get_pkg() { \ -- pkg=$1; \ -- deb_package_url=$(grep Filename Packages | grep /${pkg}_ | grep armhf | tail -n1 | sed 's/Filename: //'); \ -- echo "Downloading ${pkg}..."; \ -- filename=$(basename $deb_package_url); \ -- curl -L http://raspbian.raspberrypi.org/raspbian/${deb_package_url} -o $filename 2>/dev/null; \ -- echo "Extracting ${pkg}..."; \ -- ar -x ${pkg}_*_armhf.deb data.tar.xz; \ -- for dir in ./lib ./usr/include ./usr/lib; do \ -- ( tar -tf data.tar.xz ${dir} >/dev/null 2>/dev/null ) && \ -- ( echo " ${dir}..."; \ -- tar -C ${ARMV6_TOOLCHAIN_ROOT} \ -- -xf data.tar.xz ${dir} ); \ -- done; \ -- echo "Finished ${pkg}"; \ -- }; \ -- for pkg in \ -- liblzma5 \ -- liblzma-dev \ -- libssl1.1 \ -- libssl-dev \ -- libglib2.0-0 \ -- libglib2.0-dev \ -- libpcre3 \ -- libpcre3-dev \ -- zlib1g \ -- zlib1g-dev \ -- libffi-dev \ -- libmount1 \ -- libmount-dev \ -- libselinux1 \ -- libselinux1-dev \ -- libpcre2-8-0 \ -- libpcre2-dev \ -- libblkid1 \ -- libblkid-dev \ -- libuuid1 \ -- uuid-runtime \ -- uuid-dev \ -- ; do \ -- get_pkg $pkg; \ -- done; \ -- if egrep "^Package: libffi7$" Packages; then \ -- get_pkg libffi7; \ -- else \ -- get_pkg libffi6; \ -- fi; \ -- rm -f Packages data.tar.xz *.deb; \ -- fi -+RUN apt-get install -y \ -+ pkg-config \ -+ liblzma-dev:${ARCH} \ -+ libssl-dev:${ARCH} \ -+ libglib2.0-dev:${ARCH} \ -+ libmount-dev:${ARCH} \ -+ libc-dev:${ARCH} \ -+ libc6-dev:${ARCH} \ -+ linux-libc-dev:${ARCH} - - RUN if [ "${ARCH}" = "arm64" ]; then \ - apt-get install -y gcc-aarch64-linux-gnu; \ - fi - --RUN if [ "${ARCH}" = "armhf" -a "${DISTRO}" != "debian" ]; then \ -+RUN if [ "${ARCH}" = "armhf" ]; then \ - apt-get install -y gcc-arm-linux-gnueabihf; \ - fi - -@@ -120,11 +49,6 @@ - echo "$GPG_KEY_BUILD" | gpg --import; \ - fi - --# TODO: Figure out why these packages are required --RUN if [ "${DISTRO}" = "debian" -a "${ARCH}" = "armhf" ]; then \ -- apt-get install -y libmount1:armhf zlib1g:armhf; \ -- fi -- - # Prepare the deb-package script - COPY mender-deb-package /usr/local/bin/ - ENTRYPOINT ["/usr/local/bin/mender-deb-package"] diff --git a/.github/patches/mender/mender-deb-package.patch b/.github/patches/mender/mender-deb-package.patch deleted file mode 100644 index d095194..0000000 --- a/.github/patches/mender/mender-deb-package.patch +++ /dev/null @@ -1,47 +0,0 @@ ---- mender-deb-package 2022-12-10 10:42:58.483487231 +0100 -+++ mender-deb-package.armhf 2022-12-10 10:46:54.013542897 +0100 -@@ -200,36 +200,14 @@ - ;; - - armhf) -- if [ "$OS_DISTRO" = "debian" ]; then -- # Custom toolchain to support ARMv6 -- CROSS_COMPILE="arm-buildroot-linux-gnueabihf" \ -- CC="$CROSS_COMPILE-gcc" \ -- PATH="$PATH:${ARMV6_TOOLCHAIN_ROOT}/bin" \ -- LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${ARMV6_TOOLCHAIN_ROOT}/lib:${ARMV6_TOOLCHAIN_ROOT}/usr/lib" \ -- CGO_CFLAGS="-I${ARMV6_TOOLCHAIN_ROOT}/usr/include \ -- -I${ARMV6_TOOLCHAIN_ROOT}/usr/include/arm-linux-gnueabihf \ -- -pthread \ -- -I${ARMV6_TOOLCHAIN_ROOT}/usr/include/glib-2.0 \ -- -I${ARMV6_TOOLCHAIN_ROOT}/usr/lib/arm-linux-gnueabihf/glib-2.0/include/" \ -- CGO_LDFLAGS="-L${ARMV6_TOOLCHAIN_ROOT}/usr/lib/arm-linux-gnueabihf \ -- -lssl -lcrypto \ -- -lz -lgmodule-2.0 -lffi -lmount -lselinux -lpcre2-8 -lblkid -luuid \ -- -lglib-2.0 -lpcre -lresolv -lgio-2.0 -lgobject-2.0 -lgmodule-2.0" \ -- GOARCH=arm \ -- GOARM=6 \ -- dpkg-buildpackage -aarmhf \ -- ${sign_flags} \ -- --build=$DEB_BUILD_TYPE -- else -- # Debian ARM 32bit toolchain -- CROSS_COMPILE="arm-linux-gnueabihf" \ -- CC="$CROSS_COMPILE-gcc" \ -- PKG_CONFIG_PATH="/usr/lib/arm-linux-gnueabihf/pkgconfig/" \ -- GOARCH=arm \ -- dpkg-buildpackage -aarmhf \ -- ${sign_flags} \ -- --build=$DEB_BUILD_TYPE -- fi -+ # Debian ARM 32bit toolchain -+ CROSS_COMPILE="arm-linux-gnueabihf" \ -+ CC="$CROSS_COMPILE-gcc" \ -+ PKG_CONFIG_PATH="/usr/lib/arm-linux-gnueabihf/pkgconfig/" \ -+ GOARCH=arm \ -+ dpkg-buildpackage -aarmhf \ -+ ${sign_flags} \ -+ --build=$DEB_BUILD_TYPE - ;; - - arm64) diff --git a/.github/scripts/build-mender-packages b/.github/scripts/build-mender-packages index 9c5e9f0..dccec39 100755 --- a/.github/scripts/build-mender-packages +++ b/.github/scripts/build-mender-packages @@ -45,7 +45,7 @@ fi cd "${SCRIPT_DIR}/../../mender-dist-packages" # Make sure we have a pure Debian armhf environment and add flexiblity to build on arm64 host: -git apply "${SCRIPT_DIR}/../patches/mender/0001-Removed-Raspbian-specific-setup-allow-cross-compilat.patch" +git apply "${SCRIPT_DIR}/../patches/mender/0001-Allow-cross-compilation-on-arm64-use-podman.patch" declare -a architectures=("amd64" "armhf" "arm64")