Skip to content

Commit

Permalink
Compile sctp
Browse files Browse the repository at this point in the history
  • Loading branch information
reimarstier committed May 22, 2024
1 parent b6c3b51 commit f95eb6b
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 52 deletions.
31 changes: 14 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,33 +23,29 @@ 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
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
RUN echo "You can find a copy of the libsctp source and license here: https://github.com/sctp/lksctp-tools" >> /tmp/cannelloni/SOURCES.md

# 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}/
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
53 changes: 34 additions & 19 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

@dataclasses.dataclass
class BuildMetadata:
debian_architecture: str
dockcross_image: str
dockcross_version: str

Expand All @@ -18,36 +17,55 @@ 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__':
parser = argparse.ArgumentParser(description='Build cannelloni for your architecture')
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
Expand All @@ -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)
50 changes: 50 additions & 0 deletions build_libsctp.sh
Original file line number Diff line number Diff line change
@@ -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/
12 changes: 0 additions & 12 deletions copylib.sh

This file was deleted.

13 changes: 13 additions & 0 deletions show_version.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit f95eb6b

Please sign in to comment.