From 8fea9e7dae75e20e026b42345a2347dd424371f8 Mon Sep 17 00:00:00 2001 From: tro Date: Fri, 20 Dec 2024 00:08:21 +0100 Subject: [PATCH] Add static linked deb package for NVIDIA Jetson (Ubuntu 22.04) arm64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As the “NVIDIA JETPACK” is based on Ubuntu 22.04. the approach is to use the packages that are available (without adding some backport package soures list) and just compile the packages from source that are missing statically. Use that static libs to link gg-lite static, but also link against shared libs that are available in the correct version. To do this I did create a container especially for this use case. Also some CMakeLists improvements needs to be done to enable that static linking for just those libs that are not available with Ubuntu 22.04. --- .github/workflows/packaging.yml | 39 +++++++- .../packaging/install-greengrass-lite.sh | 4 +- .../workflows/packaging/readme.template.txt | 4 +- .github/workflows/static-packaging.yml | 91 ++++++++++++++++++ .../static-packaging/readme.template.txt | 60 ++++++++++++ CMakeLists.txt | 14 ++- misc/dictionary.txt | 3 + misc/staticbuildtestcontainer/Containerfile | 94 +++++++++++++++++++ .../getty-override.conf | 3 + 9 files changed, 302 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/static-packaging.yml create mode 100644 .github/workflows/static-packaging/readme.template.txt create mode 100644 misc/staticbuildtestcontainer/Containerfile create mode 100644 misc/staticbuildtestcontainer/getty-override.conf diff --git a/.github/workflows/packaging.yml b/.github/workflows/packaging.yml index ffd96871f..5e156776a 100644 --- a/.github/workflows/packaging.yml +++ b/.github/workflows/packaging.yml @@ -15,16 +15,40 @@ jobs: build_type: [RelWithDebInfo, MinSizeRel] steps: - uses: actions/checkout@v4 + - name: Set up QEMU uses: docker/setup-qemu-action@v3 - - name: Build container for aarch64-linux-gnu + + - name: Cache Podman image + uses: actions/cache@v4 + with: + path: | + ~/podman-aarch64-linux-gnu-image.tar + ~/podman-x86-64-image.tar + key: + ${{ runner.os }}-${{ matrix.architecture }}-podman-${{ + hashFiles('misc/buildtestcontainer/*') }} + + - name: Build and save container for aarch64-linux-gnu if: matrix.architecture == 'aarch64-linux-gnu' run: | - podman build --from=docker.io/arm64v8/ubuntu:24.04 --arch=arm64 misc/buildtestcontainer -t container - - name: Build container for x86-64 + if [ ! -f ~/podman-aarch64-linux-gnu-image.tar ]; then + podman build --from=docker.io/arm64v8/ubuntu:24.04 --arch=arm64 misc/buildtestcontainer -t container + podman save container:latest > ~/podman-aarch64-linux-gnu-image.tar + else + podman load < ~/podman-aarch64-linux-gnu-image.tar + fi + + - name: Build and save container for x86-64 if: matrix.architecture == '' run: | - podman build misc/buildtestcontainer -t container + if [ ! -f ~/podman-x86-64-image.tar ]; then + podman build misc/buildtestcontainer -t container + podman save container:latest > ~/podman-x86-64-image.tar + else + podman load < ~/podman-x86-64-image.tar + fi + - name: Run build in container shell: bash run: | @@ -42,19 +66,24 @@ jobs: make -C build -j$(nproc) && \ cd build && cpack -v -G DEB && cd - \ " + - name: Save package run: | mkdir ${{ github.workspace }}/zipfile/ cp ${{ github.workspace }}/build/*.deb ${{ github.workspace }}/zipfile/ + - name: Generate readme / install file run: | cat ${{ github.workspace }}/.github/workflows/packaging/readme.template.txt >> ${{ github.workspace }}/zipfile/readme.txt cp ${{ github.workspace }}/.github/workflows/packaging/install-greengrass-lite.sh ${{ github.workspace }}/zipfile/ sed -i 's|{{ VERSION_LINK }}|${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|g' ${{ github.workspace }}/zipfile/readme.txt + sed -i 's|{{ UBUNTU_VERSION }}|24.04|g' ${{ github.workspace }}/zipfile/install-greengrass-lite.sh cat ${{ github.workspace }}/LICENSE >> ${{ github.workspace }}/zipfile/readme.txt + - name: md5sums run: | md5sum ${{ github.workspace }}/zipfile/* + - name: Save package uses: actions/upload-artifact@v4 with: @@ -64,6 +93,7 @@ jobs: path: | ${{ github.workspace }}/zipfile/* retention-days: 1 + - name: Save x86-64 package without build type - default package to download if: matrix.build_type == 'MinSizeRel' && matrix.architecture == '' @@ -73,6 +103,7 @@ jobs: path: | ${{ github.workspace }}/zipfile/* retention-days: 1 + - name: Save arm64 package without build type - default package to download if: diff --git a/.github/workflows/packaging/install-greengrass-lite.sh b/.github/workflows/packaging/install-greengrass-lite.sh index 77f622993..cba3e8c77 100755 --- a/.github/workflows/packaging/install-greengrass-lite.sh +++ b/.github/workflows/packaging/install-greengrass-lite.sh @@ -27,11 +27,11 @@ fi check_ubuntu_version() { if [ -f /etc/os-release ]; then . /etc/os-release - if [ "$ID" = "ubuntu" ] && [ "$VERSION_ID" = "24.04" ]; then + if [ "$ID" = "ubuntu" ] && [ "$VERSION_ID" = "{{ UBUNTU_VERSION }}" ]; then return 0 fi fi - echo "Error: This greengrass lite package is only working with Ubuntu 24.04." + echo "Error: This greengrass lite package is only working with Ubuntu {{ UBUNTU_VERSION }}" echo "Current system: $PRETTY_NAME" exit 1 } diff --git a/.github/workflows/packaging/readme.template.txt b/.github/workflows/packaging/readme.template.txt index b14f06841..47959e413 100644 --- a/.github/workflows/packaging/readme.template.txt +++ b/.github/workflows/packaging/readme.template.txt @@ -4,10 +4,10 @@ AWS IoT Greengrass runtime for constrained devices. -The Greengrass Lite nucleus provides a smaller alternative to the Classic +The Greengrass Lite nucleus provides a smaller alternative to the Java nucleus for Greengrass v2 deployments. -Greengrass Lite aims to maintain compatibility with the Classic nucleus, and +Greengrass Lite aims to maintain compatibility with the Java nucleus, and implements a subset of its functionality. There is a arm64 and x86-64 version available of this zip file. For the latest diff --git a/.github/workflows/static-packaging.yml b/.github/workflows/static-packaging.yml new file mode 100644 index 000000000..5a151644d --- /dev/null +++ b/.github/workflows/static-packaging.yml @@ -0,0 +1,91 @@ +name: Build static deb arm64 packages and put them in zip files +on: + push: + branches: + - main + workflow_dispatch: + pull_request: + +jobs: + build: + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + architecture: [aarch64-linux-gnu] + build_type: [RelWithDebInfo, MinSizeRel] + steps: + - uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Cache Podman image + uses: actions/cache@v4 + with: + path: ~/podman-image.tar + key: + ${{ runner.os }}-${{ matrix.architecture }}-podman-${{ + hashFiles('misc/staticbuildtestcontainer/*') }} + + - name: Build and save container for aarch64-linux-gnu + if: matrix.architecture == 'aarch64-linux-gnu' + run: | + if [ ! -f ~/podman-image.tar ]; then + podman build --from=docker.io/arm64v8/ubuntu:22.04 --arch=arm64 misc/staticbuildtestcontainer -t container + podman save container:latest > ~/podman-image.tar + else + podman load < ~/podman-image.tar + fi + + - name: Run build in container + shell: bash + run: | + podman run -v $PWD/.:/aws-greengrass-lite --replace --name ggl container:latest bash -c "\ + cd /aws-greengrass-lite && \ + rm -rf build/ && \ + cmake -B build \ + -DGGL_LOG_LEVEL=DEBUG \ + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ + -DCMAKE_FIND_DEBUG_MODE=ON \ + -DGGL_SYSTEMD_SYSTEM_USER=ggcore \ + -DGGL_SYSTEMD_SYSTEM_GROUP=ggcore \ + -DGGL_SYSTEMD_SYSTEM_DIR=/lib/systemd/system \ + -DCMAKE_INSTALL_PREFIX=/usr && \ + make -C build -j$(nproc) && \ + cd build && cpack -v -G DEB && cd - \ + " + - name: Save package + run: | + mkdir ${{ github.workspace }}/zipfile/ + cp ${{ github.workspace }}/build/*.deb ${{ github.workspace }}/zipfile/ + - name: Generate readme / install file + run: | + cat ${{ github.workspace }}/.github/workflows/static-packaging/readme.template.txt >> ${{ github.workspace }}/zipfile/readme.txt + cp ${{ github.workspace }}/.github/workflows/packaging/install-greengrass-lite.sh ${{ github.workspace }}/zipfile/ + sed -i 's|{{ VERSION_LINK }}|${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|g' ${{ github.workspace }}/zipfile/readme.txt + sed -i 's|{{ UBUNTU_VERSION }}|22.04|g' ${{ github.workspace }}/zipfile/install-greengrass-lite.sh + cat ${{ github.workspace }}/LICENSE >> ${{ github.workspace }}/zipfile/readme.txt + - name: md5sums + run: | + md5sum ${{ github.workspace }}/zipfile/* + - name: Save package + uses: actions/upload-artifact@v4 + with: + name: + aws-greengrass-lite-ubuntu-${{ matrix.architecture || 'x86-64'}}_${{ + matrix.build_type }}-static + path: | + ${{ github.workspace }}/zipfile/* + retention-days: 1 + - name: + Save arm64 package without build type - default package to download + if: + matrix.build_type == 'MinSizeRel' && matrix.architecture == + 'aarch64-linux-gnu' + uses: actions/upload-artifact@v4 + with: + name: aws-greengrass-lite-ubuntu-arm64-static + path: | + ${{ github.workspace }}/zipfile/* + retention-days: 1 diff --git a/.github/workflows/static-packaging/readme.template.txt b/.github/workflows/static-packaging/readme.template.txt new file mode 100644 index 000000000..809caf49f --- /dev/null +++ b/.github/workflows/static-packaging/readme.template.txt @@ -0,0 +1,60 @@ +############################################################################### +# AWS Greengrass Lite +############################################################################### + +AWS IoT Greengrass runtime for constrained devices. + +The Greengrass Lite nucleus provides a smaller alternative to the java nucleus + for Greengrass v2 deployments. + +Greengrass Lite aims to maintain compatibility with the Classic nucleus, and +implements a subset of its functionality. + +There is a arm64 and x86-64 version available of this zip file. For the latest +version, as well as other install options check here: +https://github.com/aws-greengrass/aws-greengrass-lite/releases + +This deb package only works with NVIDIA JetPack SDK 6.0 (based on Ubuntu 22.04.), +because of library version package constraints! + +This package has been built from this source revision: +{{ VERSION_LINK }} + +############################################################################### +# INSTALLATION +############################################################################### + +copy *.deb package and the install-greengrass-lite.sh from this zip onto your +device + +copy ConnectionKit zip onto your device (e.g. scp, usb stick) + +The three files should be in the same folder on the device. + +On the device run installation script, this will automatically detect a *.deb +and *.zip for installation in the same dir: + +sudo ./install-greengrass-lite.sh + +############################################################################### +# UNINSTALLATION +############################################################################### + +Add a parameter "-u" to the script. Be careful this will delete /etc/greengrass +and /var/lib/greengrass! + +sudo ./install-greengrass-lite.sh -u + +############################################################################### +# UPGRADE +############################################################################### + +When a new version of greengrass lite is available and you want to keep your +configuration and components. Install just the deb package from the zip, without +using the (initial-) installation script. + +sudo apt install ./aws-greengrass-lite-x.x.x-Linux.deb + +############################################################################### +# LICENSE +############################################################################### diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b9d66675..b4aefcaa9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,6 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY # Fix for CMake stripping pkg-config includes from compile command unset(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES) - # # Compiler options # @@ -256,7 +255,6 @@ endforeach() # # System deps # - find_package(PkgConfig REQUIRED) pkg_search_module(openssl REQUIRED IMPORTED_TARGET openssl) @@ -425,6 +423,18 @@ endif() # CPACK deb package generation # +file(READ "${CMAKE_SOURCE_DIR}/version" VERSION_STRING) +string(STRIP "${VERSION_STRING}" VERSION_STRING) + +set(CPACK_PACKAGE_VERSION "${VERSION_STRING}") + +string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+$" "\\1" + CPACK_PACKAGE_VERSION_MAJOR "${VERSION_STRING}") +string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9]+$" "\\1" + CPACK_PACKAGE_VERSION_MINOR "${VERSION_STRING}") +string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+)$" "\\1" + CPACK_PACKAGE_VERSION_PATCH "${VERSION_STRING}") + set(CPACK_GENERATOR DEB) set(CPACK_DEBIAN_PACKAGE_RELEASE "${LINUX_DISTRO_STRING}") diff --git a/misc/dictionary.txt b/misc/dictionary.txt index d0221f928..4f6ae16da 100644 --- a/misc/dictionary.txt +++ b/misc/dictionary.txt @@ -13,7 +13,9 @@ corge coverity cpack cpus +DBUILD dbus +dearmor depl DFETCHCONTENT DGGL @@ -24,6 +26,7 @@ elif EOK epoll EPOLLIN +esac evbuffer eventfd evhttp diff --git a/misc/staticbuildtestcontainer/Containerfile b/misc/staticbuildtestcontainer/Containerfile new file mode 100644 index 000000000..36864e264 --- /dev/null +++ b/misc/staticbuildtestcontainer/Containerfile @@ -0,0 +1,94 @@ +FROM ubuntu:22.04 +ARG DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y wget gnupg && \ + wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null && \ + echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | tee /etc/apt/sources.list.d/kitware.list >/dev/null && \ + wget -O kitware-archive-latest.asc https://apt.kitware.com/keys/kitware-archive-latest.asc && \ + gpg --dearmor - < kitware-archive-latest.asc | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null && \ + rm kitware-archive-latest.asc + + +# Update and install necessary packages +RUN apt-get update && apt-get -y install --no-install-recommends \ + bash-completion \ + build-essential \ + ca-certificates \ + cmake \ + dbus \ + file \ + gdb \ + git \ + pkg-config \ + python3 \ + software-properties-common \ + sudo \ + systemd \ + systemd-sysv \ + uuid-dev \ + zlib1g-dev \ + libzip-dev \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +# Create a non-root user for building +RUN useradd -m builder && \ + echo "builder ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers + +# Switch to the non-root user +USER builder +WORKDIR /home/builder + +# Function to download, build and install packages +RUN echo '#!/bin/bash' > /home/builder/build_package.sh && \ + echo 'set -ex' >> /home/builder/build_package.sh && \ + echo 'mkdir -p src && cd src' >> /home/builder/build_package.sh && \ + echo 'wget $1 -O package.tar.gz' >> /home/builder/build_package.sh && \ + echo 'tar xzf package.tar.gz' >> /home/builder/build_package.sh && \ + echo 'cd $(find . -maxdepth 1 -type d | grep -v "^\.$" | head -1)' >> /home/builder/build_package.sh && \ + echo 'eval "$2"' >> /home/builder/build_package.sh && \ + echo 'make -j$(nproc)' >> /home/builder/build_package.sh && \ + echo 'sudo make ${3:-install}' >> /home/builder/build_package.sh && \ + echo 'cd /home/builder && rm -rf src' >> /home/builder/build_package.sh && \ + chmod +x /home/builder/build_package.sh + +# Build and install OpenSSL, using same version as Ubuntu 24.04. (Noble Numbat) +RUN /home/builder/build_package.sh \ + "https://www.openssl.org/source/openssl-3.0.13.tar.gz" \ + 'export ARCH=$(uname -m); \ + case $ARCH in \ + x86_64) TARGET="linux-x86_64";; \ + aarch64) TARGET="linux-aarch64";; \ + armv7l) TARGET="linux-armv4";; \ + *) echo "Unsupported architecture: $ARCH"; exit 1;; \ + esac; \ + ./Configure no-shared no-async $TARGET -static --prefix=/usr/local --openssldir=/usr/local/ssl' \ + 'install_sw' + +# Build and install libcurl, using same version as Ubuntu 24.04. (Noble Numbat) +RUN /home/builder/build_package.sh \ + "https://curl.se/download/curl-8.5.0.tar.gz" \ + './configure --with-openssl=/usr/local --enable-static --disable-shared --prefix=/usr/local' + +USER root + +# Update environment variables and pkg-config files +RUN echo "export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64:\$LD_LIBRARY_PATH" >> /etc/environment && \ + echo "export LIBRARY_PATH=/usr/local/lib:/usr/local/lib64:\$LIBRARY_PATH" >> /etc/environment && \ + echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig:\$PKG_CONFIG_PATH" >> /etc/environment + +# Install additional development libraries +RUN apt-get update && apt-get -y install --no-install-recommends \ + libevent-dev \ + libsqlite3-dev \ + libsystemd-dev \ + liburiparser-dev \ + libyaml-dev \ + sqlite3 \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +COPY ./getty-override.conf \ + /etc/systemd/system/console-getty.service.d/override.conf + +RUN echo "export MAKEFLAGS=-j$(nproc)" >> /root/.profile + +CMD ["/lib/systemd/systemd"] diff --git a/misc/staticbuildtestcontainer/getty-override.conf b/misc/staticbuildtestcontainer/getty-override.conf new file mode 100644 index 000000000..a51c5c175 --- /dev/null +++ b/misc/staticbuildtestcontainer/getty-override.conf @@ -0,0 +1,3 @@ +[Service] +ExecStart= +ExecStart=-/sbin/agetty --autologin root --noclear console $TERM