From efe3d21a1e4922c869e78dc9b9ebcb26383ba0e9 Mon Sep 17 00:00:00 2001 From: RICCIARDI-Adrien Date: Wed, 27 Mar 2024 18:00:08 +0100 Subject: [PATCH] Removed the 'build-all-targets.sh' script and replaced the 'build-buildroot.sh' script by a more generic one. Also bumped the Buildroot version to 2024.02. The Buildroot version 2024.02 is the first version providing PPP in version 2.5.0, so a lot of hacks in the Buildroot pppd packages are no more needed. Signed-off-by: RICCIARDI-Adrien --- .github/workflows/generate_images.yaml | 2 +- build-all-targets.sh | 48 ------------- build-buildroot.sh | 98 -------------------------- build-image.sh | 77 ++++++++++++++++++++ 4 files changed, 78 insertions(+), 147 deletions(-) delete mode 100755 build-all-targets.sh delete mode 100755 build-buildroot.sh create mode 100755 build-image.sh diff --git a/.github/workflows/generate_images.yaml b/.github/workflows/generate_images.yaml index 0095d95..3e601f9 100644 --- a/.github/workflows/generate_images.yaml +++ b/.github/workflows/generate_images.yaml @@ -18,7 +18,7 @@ jobs: uses: actions/checkout@v4 - name: Run build script run: | - bash -x ${{ github.workspace }}/build-buildroot.sh ${{ matrix.defconfig_name }} ${{ matrix.libc_name }} /home/runner + bash -x ${{ github.workspace }}/build-image.sh ${{ matrix.defconfig_name }} ${{ matrix.libc_name }} /home/runner - name: Archive image run: | tar -c ${{ env.BUILDROOT_DIRECTORY_NAME }} -f ${{ env.BUILDROOT_DIRECTORY_NAME }}.tar diff --git a/build-all-targets.sh b/build-all-targets.sh deleted file mode 100755 index 7efaf48..0000000 --- a/build-all-targets.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh - -# Exit if any error occurs -set -e - -PrintMessage() -{ - printf "\033[35m-> $1\033[0m\n" -} - -# Building Buildroot in the same path that it will run in a GitHub runner is mandatory for the absolute paths generated by Buildroot during build to work on the GitHub runner -OUTPUT_DIRECTORY=/home/runner - -# Make sure the output directory exists -if [ ! -d "$OUTPUT_DIRECTORY" ] -then - echo "Error : the output directory $OUTPUT_DIRECTORY must be created and must be accessible to this script." - echo "This output directory can't be changed, otherwise Buildroot won't run in a GitHub runner." - exit 1 -fi - -# Make sure the host machine architecture is the same that the GitHub runners one -if [ "$(uname -m)" != "x86_64" ] -then - echo "Error : the host build machine architecture must be x86_64." - exit 1 -fi - -DEFCONFIG_NAMES="qemu_x86_defconfig qemu_x86_64_defconfig raspberrypi4_defconfig raspberrypi4_64_defconfig qemu_ppc64le_pseries_defconfig qemu_mips32r2_malta_defconfig qemu_mips64_malta_defconfig" -LIBC_NAMES="glibc uclibc musl" - -# Build all possible configurations -for Defconfig in $DEFCONFIG_NAMES -do - for Libc in $LIBC_NAMES - do - PrintMessage "Building '$Defconfig' defconfig with '$Libc' libc..." - ./build-buildroot.sh $Defconfig $Libc $OUTPUT_DIRECTORY - - PrintMessage "Compressing Buildroot build..." - Buildroot_Build_Name=buildroot-${Defconfig}-${Libc} - cd $OUTPUT_DIRECTORY - tar -c $Buildroot_Build_Name -f ${Buildroot_Build_Name}.tar - rm -f ${Buildroot_Build_Name}.tar.zstd - zstd -T0 -19 --rm -v ${Buildroot_Build_Name}.tar - cd - - done -done diff --git a/build-buildroot.sh b/build-buildroot.sh deleted file mode 100755 index e3084be..0000000 --- a/build-buildroot.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/sh - -# Exit if any error occurs -set -e - -PrintMessage() -{ - printf "\033[33m--> $1\033[0m\n" -} - -# Check arguments -if [ $# -ne 3 ] -then - echo "Usage : $0 buildroot_defconfig_name libc_name output_directory" - echo " buildroot_defconfig_name : see all available defconfigs here https://git.busybox.net/buildroot/tree/configs?h=2021.02.5" - echo " libc_name : must be \"glibc\", \"uclibc\" or \"musl\"" - echo " output_directory : will contain the build directory and the final compressed artifacts" - exit 1 -fi -DEFCONFIG_NAME="$1" -LIBC_NAME="$2" -OUTPUT_DIRECTORY="$3" - -# Create the build directory name -BUILD_DIRECTORY_NAME="buildroot-${DEFCONFIG_NAME}-${LIBC_NAME}" -BUILD_DIRECTORY_PATH=$(realpath "${OUTPUT_DIRECTORY}")/"${BUILD_DIRECTORY_NAME}" - -PrintMessage "Removing previous build artifacts..." -rm -rf $BUILD_DIRECTORY_PATH - -PrintMessage "Downloading Buildroot sources..." -git clone --depth=1 --branch=2021.02.5 https://github.com/buildroot/buildroot $BUILD_DIRECTORY_PATH - -PrintMessage "Modifying the PPP package to use upstream PPP sources..." -PPP_PACKAGE_PATH="${BUILD_DIRECTORY_PATH}/package/pppd" -echo $PPP_PACKAGE_PATH -# Allow package to build when musl libc is selected -sed -i '/depends on !BR2_TOOLCHAIN_USES_MUSL/d' ${PPP_PACKAGE_PATH}/Config.in -# Upstream version always needs OpenSSL -sed -i '/select BR2_PACKAGE_OPENSSL/c\\select BR2_PACKAGE_OPENSSL' ${PPP_PACKAGE_PATH}/Config.in -# Do not check for package hash, so there is no need to compute it -rm ${PPP_PACKAGE_PATH}/pppd.hash -# Buildroot patch is already applied upstream -rm -f ${PPP_PACKAGE_PATH}/0001-pppd-Fix-bounds-check.patch -# Get package sources from head of master branch -LAST_COMMIT_HASH=$(curl -s -H "Accept: application/vnd.github.VERSION.sha" "https://api.github.com/repos/ppp-project/ppp/commits/master") -sed -i "/PPPD_VERSION =/c\\PPPD_VERSION = ${LAST_COMMIT_HASH}" ${PPP_PACKAGE_PATH}/pppd.mk -sed -i '/PPPD_SITE =/c\\PPPD_SITE = https://github.com/ppp-project/ppp' ${PPP_PACKAGE_PATH}/pppd.mk -sed -i '9iPPPD_SITE_METHOD = git' ${PPP_PACKAGE_PATH}/pppd.mk -# Tell Buildroot to run autoreconf.sh -sed -i '16iPPPD_AUTORECONF = YES' ${PPP_PACKAGE_PATH}/pppd.mk -# Filters feature needs libpcap -sed -i '17iPPPD_DEPENDENCIES = libpcap openssl' ${PPP_PACKAGE_PATH}/pppd.mk -# Enable verbose build commands and force OpenSSL directory, otherwise the host system one might be used instead of Buildroot one -sed -i '18iPPPD_CONF_OPTS = --disable-silent-rules --with-openssl="$(STAGING_DIR)/usr"' ${PPP_PACKAGE_PATH}/pppd.mk -# Do not install build artifacts to staging directory -sed -i 's/PPPD_INSTALL_STAGING = YES/PPPD_INSTALL_STAGING = NO/' ${PPP_PACKAGE_PATH}/pppd.mk -# Delete custom configuration tool, it is now automatically handled by Buildroot -sed -i '/PPPD_CONFIGURE_CMDS/,+4d' ${PPP_PACKAGE_PATH}/pppd.mk -# Delete custom build rule, it is now generated by Autotools -sed -i '/define PPPD_BUILD_CMDS/,+4d' ${PPP_PACKAGE_PATH}/pppd.mk -# Delete custom installation to target rule, it is now generated by Autotools -sed -i '/define PPPD_INSTALL_TARGET_CMDS/,+27d' ${PPP_PACKAGE_PATH}/pppd.mk -# Delete custom staging installation rule as PPP does not need to be installed to staging in this CI -sed -i '/define PPPD_INSTALL_STAGING_CMDS/,+3d' ${PPP_PACKAGE_PATH}/pppd.mk -# Tell Buildroot that this package uses Autotools -sed -i 's/$(eval $(generic-package))/$(eval $(autotools-package))/' ${PPP_PACKAGE_PATH}/pppd.mk - -PrintMessage "Enabling PPP build in Buildroot configuration..." -# Enable all Buildroot PPP options as everything is built by upstream build system -echo "BR2_PACKAGE_PPPD=y" >> ${BUILD_DIRECTORY_PATH}/configs/${DEFCONFIG_NAME} -echo "BR2_PACKAGE_PPPD_FILTER=y" >> ${BUILD_DIRECTORY_PATH}/configs/${DEFCONFIG_NAME} -echo "BR2_PACKAGE_PPPD_RADIUS=y" >> ${BUILD_DIRECTORY_PATH}/configs/${DEFCONFIG_NAME} -echo "BR2_PACKAGE_PPPD_OVERWRITE_RESOLV_CONF=y" >> ${BUILD_DIRECTORY_PATH}/configs/${DEFCONFIG_NAME} - -PrintMessage "Selecting the ${LIBC_NAME} libc..." -case $LIBC_NAME in - "glibc") - echo "BR2_TOOLCHAIN_BUILDROOT_GLIBC=y" >> ${BUILD_DIRECTORY_PATH}/configs/${DEFCONFIG_NAME} - ;; - "uclibc") - echo "BR2_TOOLCHAIN_BUILDROOT_UCLIBC=y" >> ${BUILD_DIRECTORY_PATH}/configs/${DEFCONFIG_NAME} - ;; - "musl") - echo "BR2_TOOLCHAIN_BUILDROOT_MUSL=y" >> ${BUILD_DIRECTORY_PATH}/configs/${DEFCONFIG_NAME} - ;; - *) - echo "Unknown libc, please specify \"glibc\", \"uclibc\" or \"musl\"." - exit 1 - ;; -esac - -PrintMessage "Generating Buildroot configuration..." -cd $BUILD_DIRECTORY_PATH -make $DEFCONFIG_NAME - -PrintMessage "Building..." -make diff --git a/build-image.sh b/build-image.sh new file mode 100755 index 0000000..80a8fb1 --- /dev/null +++ b/build-image.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +# Exit if any error occurs +set -e + +PrintMessage() +{ + printf "\033[33m--> $1\033[0m\n" +} + +BUILDROOT_VERSION=2024.02 + +# Check arguments +if [ $# -ne 3 ] +then + echo "Usage : $0 buildroot_defconfig_name libc_name output_directory" + echo " buildroot_defconfig_name : see all available defconfigs here https://git.busybox.net/buildroot/tree/configs?h=${BUILDROOT_VERSION}" + echo " libc_name : must be \"glibc\", \"uclibc\" or \"musl\"" + echo " output_directory : will contain the build directory and the final compressed artifacts" + exit 1 +fi +DEFCONFIG_NAME="$1" +LIBC_NAME="$2" +OUTPUT_DIRECTORY="$3" + +# Create the build directory name +BUILD_DIRECTORY_NAME="buildroot-${DEFCONFIG_NAME}-${LIBC_NAME}" +BUILD_DIRECTORY_PATH=$(realpath "${OUTPUT_DIRECTORY}")/"${BUILD_DIRECTORY_NAME}" + +PrintMessage "Removing previous build artifacts..." +rm -rf "${BUILD_DIRECTORY_PATH}" + +PrintMessage "Downloading Buildroot sources..." +git clone --depth=1 --branch="${BUILDROOT_VERSION}" https://github.com/buildroot/buildroot "${BUILD_DIRECTORY_PATH}" + +PrintMessage "Modifying the PPP Buildroot package to use upstream PPP sources..." +PPP_PACKAGE_PATH="${BUILD_DIRECTORY_PATH}/package/pppd" +# Upstream version always needs OpenSSL +sed -i '/select BR2_PACKAGE_OPENSSL/c\\select BR2_PACKAGE_OPENSSL' ${PPP_PACKAGE_PATH}/Config.in +# Do not check for package hash, so there is no need to compute it +rm ${PPP_PACKAGE_PATH}/pppd.hash +# Buildroot patches are already applied upstream +rm -f ${PPP_PACKAGE_PATH}/*.patch +# Get package sources from head of master branch +LAST_COMMIT_HASH=$(curl -s -H "Accept: application/vnd.github.VERSION.sha" "https://api.github.com/repos/ppp-project/ppp/commits/master") +sed -i "/PPPD_VERSION =/c\\PPPD_VERSION = ${LAST_COMMIT_HASH}" ${PPP_PACKAGE_PATH}/pppd.mk +sed -i '/PPPD_SITE =/c\\PPPD_SITE = https://github.com/ppp-project/ppp' ${PPP_PACKAGE_PATH}/pppd.mk +sed -i '9iPPPD_SITE_METHOD = git' ${PPP_PACKAGE_PATH}/pppd.mk + +PrintMessage "Enabling PPP build in Buildroot configuration..." +# Enable all Buildroot PPP options as everything is built by upstream build system +echo "BR2_PACKAGE_PPPD=y" >> ${BUILD_DIRECTORY_PATH}/configs/${DEFCONFIG_NAME} +echo "BR2_PACKAGE_PPPD_FILTER=y" >> ${BUILD_DIRECTORY_PATH}/configs/${DEFCONFIG_NAME} + +PrintMessage "Selecting the ${LIBC_NAME} C library..." +case $LIBC_NAME in + "glibc") + echo "BR2_TOOLCHAIN_BUILDROOT_GLIBC=y" >> "${BUILD_DIRECTORY_PATH}/configs/${DEFCONFIG_NAME}" + ;; + "uclibc") + echo "BR2_TOOLCHAIN_BUILDROOT_UCLIBC=y" >> "${BUILD_DIRECTORY_PATH}/configs/${DEFCONFIG_NAME}" + ;; + "musl") + echo "BR2_TOOLCHAIN_BUILDROOT_MUSL=y" >> "${BUILD_DIRECTORY_PATH}/configs/${DEFCONFIG_NAME}" + ;; + *) + echo "Unknown C library, please specify \"glibc\", \"uclibc\" or \"musl\"." + exit 1 + ;; +esac + +PrintMessage "Generating the Buildroot configuration..." +cd "${BUILD_DIRECTORY_PATH}" +make "${DEFCONFIG_NAME}" + +PrintMessage "Building the Buildroot image..." +make