From f95eb6b4bfc686875588ade5e7db5d02e413a89e Mon Sep 17 00:00:00 2001 From: Reimar Stier Date: Wed, 22 May 2024 06:29:15 +0200 Subject: [PATCH] Compile sctp --- Dockerfile | 31 +++++++++++++--------------- README.md | 8 ++++---- build.py | 53 +++++++++++++++++++++++++++++++----------------- build_libsctp.sh | 50 +++++++++++++++++++++++++++++++++++++++++++++ copylib.sh | 12 ----------- show_version.sh | 13 ++++++++++++ 6 files changed, 115 insertions(+), 52 deletions(-) create mode 100755 build_libsctp.sh delete mode 100755 copylib.sh create mode 100755 show_version.sh diff --git a/Dockerfile b/Dockerfile index 31e4573..b0012a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,14 +6,15 @@ ARG VERSION=1.1.0 ARG HASH=0dcb9277b21f916f5646574b9b2229d3b8e97d5e99b935a4d0b7509a5f0ccdcd ARG DOCKCROSS_IMAGE=linux-arm64 ARG DOCKCROSS_VERSION=latest -ARG DEBIAN_ARCHITECTURE=arm64 - -RUN dpkg --add-architecture $DEBIAN_ARCHITECTURE -RUN apt update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - ca-certificates wget build-essential cmake \ - libsctp-dev:$DEBIAN_ARCHITECTURE lksctp-tools:$DEBIAN_ARCHITECTURE RUN mkdir /tmp/cannelloni + +ENV LIBSCTP_VERSION=1.0.19 +WORKDIR /tmp/libsctp +# copy installed libraries to expected target location for cmake toolchain +COPY build_libsctp.sh /build_libsctp.sh +RUN /build_libsctp.sh + WORKDIR /tmp/cannelloni RUN wget https://github.com/mguentner/cannelloni/archive/refs/tags/v$VERSION.tar.gz -O cannelloni-$VERSION.tar.gz RUN echo "$HASH cannelloni-$VERSION.tar.gz" | sha256sum --check --status @@ -22,11 +23,7 @@ RUN tar --strip-components=1 -xvf cannelloni-$VERSION.tar.gz # Document build metadata RUN echo "Built with dockcross/$DOCKCROSS_IMAGE:$DOCKCROSS_VERSION\n" | tee -a /tmp/cannelloni/build-metadata.txt -# copy installed libraries to expected target location for cmake toolchain -COPY copylib.sh /copylib.sh -RUN /copylib.sh - -RUN cmake -DCMAKE_BUILD_TYPE=Release 2>&1 | tee -a /tmp/cannelloni/build-metadata.txt +RUN cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DSCTP_INCLUDE_DIR=/tmp/libsctp/src/include/netinet/ -DSCTP_LIBRARY=/tmp/libsctp/src/lib/.libs/ -DSCTP_SUPPORT=ON 2>&1 | tee -a /tmp/cannelloni/build-metadata.txt RUN make 2>&1 | tee -a /tmp/cannelloni/build-metadata.txt COPY checklib.sh /checklib.sh @@ -34,11 +31,10 @@ RUN /checklib.sh 2>&1 | tee -a /tmp/cannelloni/build-metadata.txt WORKDIR /tmp/ -# copy libcannelloni to target directory +# rename libcannelloni in target directory RUN cp --remove-destination /tmp/cannelloni/libcannelloni-common.so.0.0.1 /tmp/cannelloni/libcannelloni-common.so.0 - -# copy libsctp library to target directory -RUN cp --no-dereference --preserve=links /usr/lib/*/libsctp* /tmp/cannelloni +RUN mv cannelloni/gpl-2.0.txt cannelloni/cannelloni-license-gpl-2.0.txt +# copy libsctp license to target directory RUN curl https://raw.githubusercontent.com/sctp/lksctp-tools/master/COPYING.lib --output /tmp/cannelloni/libsctp-license.txt # add note about source RUN echo "You can find a copy of the cannelloni source code at: https://github.com/mguentner/cannelloni/archive/refs/tags/v$VERSION.tar.gz" > /tmp/cannelloni/SOURCES.md @@ -46,9 +42,10 @@ RUN echo "You can find a copy of the libsctp source and license here: https://gi # create tar file as output RUN tar cf /tmp/cannelloni.tar.gz \ - cannelloni/cannelloni cannelloni/libcannelloni-common.so.0 cannelloni/gpl-2.0.txt cannelloni/README.md cannelloni/SOURCES.md \ + cannelloni/SOURCES.md \ + cannelloni/cannelloni cannelloni/libcannelloni-common.so.0 cannelloni/cannelloni-license-gpl-2.0.txt cannelloni/README.md \ cannelloni/build-metadata.txt \ - cannelloni/libsctp* + cannelloni/libsctp-license.txt cannelloni/libsctp*.so* # create directory as output # RUN mkdir -p /cannelloni_${DOCKCROSS_IMAGE}_${VERSION}/ diff --git a/README.md b/README.md index bf6c28e..56bbdfd 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ CI pipeline to build [cannelloni](https://github.com/mguentner/cannelloni) for m Uses [dockcross](https://github.com/dockcross/dockcross) to compile for the specified architectures. * Configured architectures are: - * [linux-arm64](https://hub.docker.com/r/dockcross/linux-arm64), **arm64** for e.g. Yocto Linux - * [linux-x64](https://hub.docker.com/r/dockcross/linux-x64), **x86_64** for regular desktop (does not require cross) - * [linux-armv7](https://hub.docker.com/r/dockcross/linux-armv7), **armv7** for e.g. Raspberry Pi 3 + * [manylinux_2_28-x64](https://hub.docker.com/r/dockcross/manylinux_2_28-x64), **x86_64** for regular desktop (does not require cross, uses glibc 2.28) * [linux-armv6-lts](https://hub.docker.com/r/dockcross/linux-armv6-lts), for e.g. Raspberry Pi 3 with good old Raspbian, arm-linux-gnueabihf, armhf, glibc 2.28 + * [linux-armv7-lts](https://hub.docker.com/r/dockcross/linux-armv7-lts), **armv7** + * [linux-arm64-lts](https://hub.docker.com/r/dockcross/linux-arm64-lts), **arm64** for e.g. Yocto Linux ## Build for multiple architectures @@ -69,7 +69,7 @@ uname --all # print system information (kernel version, processor type uname --machine # print machine hardware information strings /lib/arm-linux-gnueabihf/libc.so.6 | grep GLIBC_ strings /lib/*/libc.so.6 | grep GLIBC_ -ldd --version # GCC version +ldd --version # GLIBC version gcc -v # GCC version gcc -print-multiarch # print target triple diff --git a/build.py b/build.py index 846110e..919fa4f 100644 --- a/build.py +++ b/build.py @@ -8,7 +8,6 @@ @dataclasses.dataclass class BuildMetadata: - debian_architecture: str dockcross_image: str dockcross_version: str @@ -18,29 +17,47 @@ class BuildMetadata: # Dockcross image names: https://github.com/dockcross/dockcross?tab=readme-ov-file#summary-cross-compilers # Debian architectures: https://wiki.debian.org/SupportedArchitectures BUILD_TARGETS = { - "linux-arm64": BuildMetadata(debian_architecture="arm64", dockcross_image="linux-arm64", dockcross_version="20240418-88c04a4"), - "linux-x64": BuildMetadata(debian_architecture="amd64", dockcross_image="linux-x64", dockcross_version="20240418-88c04a4"), - "linux-armv7": BuildMetadata(debian_architecture="armhf", dockcross_image="linux-armv7", dockcross_version="20240418-88c04a4"), - "linux-armv7-lts": BuildMetadata(debian_architecture="armhf", dockcross_image="linux-armv7-lts", dockcross_version="20240418-88c04a4"), - "linux-armv6": BuildMetadata(debian_architecture="armhf", dockcross_image="linux-armv6", dockcross_version="20240418-88c04a4"), - "linux-armv6-lts": BuildMetadata(debian_architecture="armhf", dockcross_image="linux-armv6-lts", dockcross_version="20240418-88c04a4"), + #"linux-x64": BuildMetadata(dockcross_image="linux-x64", dockcross_version="20240418-88c04a4"), + #"linux-armv6": BuildMetadata(dockcross_image="linux-armv6", dockcross_version="20240418-88c04a4"), + "linux-armv6-lts": BuildMetadata(dockcross_image="linux-armv6-lts", dockcross_version="20240418-88c04a4"), + #"linux-armv7": BuildMetadata(dockcross_image="linux-armv7", dockcross_version="20240418-88c04a4"), + "linux-armv7-lts": BuildMetadata(dockcross_image="linux-armv7-lts", dockcross_version="20240418-88c04a4"), + #"linux-arm64": BuildMetadata(dockcross_image="linux-arm64", dockcross_version="20240418-88c04a4"), + "linux-arm64-lts": BuildMetadata(dockcross_image="linux-arm64-lts", dockcross_version="20240418-88c04a4"), + "manylinux_2_28-x64": BuildMetadata(dockcross_image="manylinux_2_28-x64", dockcross_version="20240418-88c04a4"), } -def build_cannelloni(target: BuildMetadata, build_version: str, build_hash: str): +def build_cannelloni(build_metadata: BuildMetadata, build_version: str, build_hash: str): + print(f""" + Build cannelloni for your architecture. + + Dockcross image: dockcross/{build_metadata.dockcross_image}:{build_metadata.dockcross_version} + """) + cmd = f"""docker build --build-arg VERSION={build_version} --build-arg HASH={build_hash} - --build-arg DOCKCROSS_IMAGE={target.dockcross_image} - --build-arg DOCKCROSS_VERSION={target.dockcross_version} - --build-arg DEBIAN_ARCHITECTURE={target.debian_architecture} + --build-arg DOCKCROSS_IMAGE={build_metadata.dockcross_image} + --build-arg DOCKCROSS_VERSION={build_metadata.dockcross_version} --output type=local,dest=out .""" my_env = os.environ.copy() my_env["BUILDKIT_PROGRESS"] = "plain" # show progress output when building with docker result = subprocess.run(cmd.split(), env=my_env) if result.returncode != 0: - raise RuntimeError("Failed to build docker image for architecture={}".format(target.debian_architecture)) + raise RuntimeError("Failed to build docker image for architecture={}".format(build_metadata.dockcross_image)) + +def show_version(build_metadata: BuildMetadata): + print(f""" +Dockcross image : dockcross/{build_metadata.dockcross_image}:{build_metadata.dockcross_version}""") + + cmd = f"""docker run --entrypoint= --rm -v ./show_version.sh:/show_version.sh dockcross/{build_metadata.dockcross_image}:{build_metadata.dockcross_version} /show_version.sh""".split() + result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if result.returncode == 0: + print(result.stdout.decode().strip()) + else: + raise RuntimeError("Failed to build docker image for architecture={}".format(build_metadata.dockcross_image)) if __name__ == '__main__': @@ -48,6 +65,7 @@ def build_cannelloni(target: BuildMetadata, build_version: str, build_hash: str) parser.add_argument('--architecture', help='Architecture to build.', choices=BUILD_TARGETS.keys(), required=False) parser.add_argument('--version', help='Cannelloni release version to build.') parser.add_argument('--hash', help='Cannelloni release hash to do integrity check.') + parser.add_argument('--show', help='Show toolchain versions of dockcross images.', required=False, action='store_true') args = parser.parse_args() given_architecture = args.architecture @@ -62,10 +80,7 @@ def build_cannelloni(target: BuildMetadata, build_version: str, build_hash: str) for architecture in target_list: metadata = BUILD_TARGETS[architecture] - print(f""" - Build cannelloni for your architecture. - - Dockcross image: dockcross/{metadata.dockcross_image}:{metadata.dockcross_version} - Debian architecture: {metadata.debian_architecture} - """) - build_cannelloni(metadata, build_version, build_hash) + if args.show: + show_version(metadata) + else: + build_cannelloni(metadata, build_version, build_hash) diff --git a/build_libsctp.sh b/build_libsctp.sh new file mode 100755 index 0000000..3e27fc7 --- /dev/null +++ b/build_libsctp.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +set -x +set -e + +LIBSCTP_VERSION="${LIBSCTP_VERSION:-1.0.19}" +LIBSCTP_HASH="${LIBSCTP_HASH:-9251b1368472fb55aaeafe4787131bdde4e96758f6170620bc75b638449cef01}" + +if [ -z "$LIBSCTP_VERSION" ]; then + echo "No library version for libsctp specified! Set environment variable 'LIBSCTP_VERSION'!" + exit 1 +fi + +# for other architectures than x86_64, copy libraries to this location for cmake toolchain +set +e +TARGET_XCC_DIR="$(ls -d /usr/xcc/*/*/sysroot/)" +TARGET_TRIPLE="$(ls /usr/xcc/)" +set -e + +wget https://github.com/sctp/lksctp-tools/archive/refs/tags/v"$LIBSCTP_VERSION".tar.gz -O libsctp-"$LIBSCTP_VERSION".tar.gz +echo "$LIBSCTP_HASH libsctp-$LIBSCTP_VERSION.tar.gz" | sha256sum --check --status + +tar --strip-components=1 -xvf libsctp-"$LIBSCTP_VERSION".tar.gz +./bootstrap + +# CFLAGS are set to "MinSizeRel" +export CFLAGS="-Os -DNDEBUG" +# CFLAGS are set to "Release" +export CFLAGS="-O3 -DNDEBUG" +if [ -n "$TARGET_TRIPLE" ]; then + ./configure --host "$TARGET_TRIPLE" +else + ./configure +fi +make + +# show location of the following files for debug purposes +find . -name "libsctp*" +find . -name "sctp.h" + +if [ -n "$TARGET_XCC_DIR" ]; then + cp ./src/include/netinet/sctp.h "$TARGET_XCC_DIR"/usr/include/netinet/ + cp src/lib/.libs/libsctp.* "$TARGET_XCC_DIR"/usr/lib/ +else + echo "Not a cross build. Nothing to do for current architecture: $ARCHITECTURE" + cp ./src/include/netinet/sctp.h /usr/include/netinet/ + cp src/lib/.libs/libsctp.* /usr/lib/ +fi + +cp -a ./src/include/netinet/ /tmp/cannelloni/ +cp --no-dereference --preserve=links src/lib/.libs/libsctp.* /tmp/cannelloni/ diff --git a/copylib.sh b/copylib.sh deleted file mode 100755 index 9ff0a00..0000000 --- a/copylib.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -x - -# for other architectures than x86_64, copy libraries to this location for cmake toolchain -TARGET_XCC_DIR="$(ls -d /usr/xcc/*/*/sysroot/)" - -if [ -n "$TARGET_XCC_DIR" ]; then - cp /usr/include/netinet/sctp.h "$TARGET_XCC_DIR"/usr/include/netinet/ - cp /usr/lib/*/libsctp.* "$TARGET_XCC_DIR"/usr/lib/ -else - echo "Not a cross build. Nothing to do for current architecture: $ARCHITECTURE" -fi diff --git a/show_version.sh b/show_version.sh new file mode 100755 index 0000000..03dbcec --- /dev/null +++ b/show_version.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +TARGET_XCC_DIR="$(ls -d /usr/xcc/*/*/sysroot/ 2>/dev/null)" +TARGET_TRIPLE="$(ls /usr/xcc/)" +if [ -n "$TARGET_XCC_DIR" ]; then + LDD_VERSION="$("$TARGET_XCC_DIR"/usr/bin/ldd --version | head -n1)" +else + LDD_VERSION="$(ldd --version | head -n1)" + TARGET_TRIPLE="$(gcc -print-multiarch)" +fi + +echo "Glibc version : $LDD_VERSION" +echo "Target triple : $TARGET_TRIPLE"