This commit is contained in:
Your Name 2025-05-26 18:37:00 +12:00
parent c5d27dd31e
commit 6dc0b7c9c1
5 changed files with 90 additions and 34 deletions

View File

@ -3,7 +3,17 @@
########################
# Stage 1: build deps #
########################
FROM alpine:3.19 AS builder
FROM alpine:latest AS builder
ARG TARGET_ARCH
RUN case $TARGET_ARCH in \
"arm64") export TARGET_TRIPLE="aarch64-linux-musl";; \
"amd64") export TARGET_TRIPLE="x86_64-linux-musl";; \
*) echo "Unsupported architecture"; exit 1;; \
esac && \
export CC="${TARGET_TRIPLE}-gcc" && \
export CXX="${TARGET_TRIPLE}-g++"
# Enable static builds with musl
ENV CFLAGS="-static -O2" \
@ -44,8 +54,7 @@ RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repo
patch \
gawk \
xz-dev \
crosstool-ng
gcc-cross-embedded
########################################
# nlohmann/json (compiled static .a) #
@ -115,7 +124,7 @@ RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repo
linux-headers \
ccache \
mold \
crosstool-ng
gcc-cross-embedded
# Configure mold as the default linker
ENV LD=mold

View File

@ -1,3 +1,11 @@
#!/bin/bash
docker build -t cpp-httplib-builder .
docker build --build-arg TARGET_ARCH=arm64 -t cpp-httplib-builder:arm64 .
docker build --build-arg TARGET_ARCH=amd64 -t cpp-httplib-builder:amd64 .
docker tag cpp-httplib-builder:arm64 gitea.jde.nz/public/cpp-httplib-builder:arm64
docker tag cpp-httplib-builder:amd64 gitea.jde.nz/public/cpp-httplib-builder:amd64
docker tag cpp-httplib-builder:amd64 gitea.jde.nz/public/cpp-httplib-builder:latest
docker push gitea.jde.nz/public/cpp-httplib-builder:arm64
docker push gitea.jde.nz/public/cpp-httplib-builder:amd64

0
notes.txt Normal file
View File

View File

@ -1,18 +1,41 @@
#!/bin/bash
set -e
PROJECT=ipdemo
function title() {
# print a title with a line of dashes
echo "--------------------------------"
echo "$1"
echo "--------------------------------"
}
function build() {
ARCH="$1"
title "Building $PROJECT.$ARCH"
if [ "$ARCH" != "arm64" ] && [ "$ARCH" != "amd64" ]; then
echo "Unsupported architecture: $ARCH"
exit 1
fi
# Create volume if it doesn't exist
docker volume create cppbuild-cache
docker volume create cppbuild-cache-$ARCH
# Directory to copy the executable to
OUTDIR="output"
BUILD_IMAGE="gitea.jde.nz/public/cpp-httplib-builder:$ARCH"
# Build command to run in the container
BUILD_COMMAND="mkdir -p /app/build && \
cd /app/build && \
cmake -G Ninja /app/src && \
ninja -j$(nproc) && \
mkdir /app/src/$OUTDIR && \
cp /app/build/ipdemo /app/src/$OUTDIR/ipdemo && \
mkdir -p /app/src/$OUTDIR && \
cp /app/build/$PROJECT /app/src/$OUTDIR/$PROJECT.$ARCH && \
chown -R $(id -u):$(id -g) /app/src/$OUTDIR"
# Run the build in the container
@ -26,10 +49,26 @@ docker run --rm \
-e LD=mold \
-e CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) \
-e NINJA_STATUS="[%f/%t] " \
cpp-httplib-builder:latest \
$BUILD_IMAGE \
-c "$BUILD_COMMAND"
# Run the executable if it exists
if [ -f $OUTDIR/ipdemo ]; then
$OUTDIR/ipdemo
if [ ! -f $OUTDIR/$PROJECT.$ARCH ]; then
echo "Executable not found: $OUTDIR/$PROJECT.$ARCH"
exit 1
fi
# Check if the executable is dynamically linked using ldd
if ldd "$OUTDIR/$PROJECT.$ARCH"; then
echo "Error: Dynamic dependencies found for $OUTDIR/$PROJECT.$ARCH"
exit 1 # Exit the script with an error
else
echo "Successfully verified no dynamic dependencies for $OUTDIR/$PROJECT.$ARCH"
fi
file $OUTDIR/$PROJECT.$ARCH
}
build arm64
build amd64

Binary file not shown.