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 # # 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 # Enable static builds with musl
ENV CFLAGS="-static -O2" \ ENV CFLAGS="-static -O2" \
@ -44,8 +54,7 @@ RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repo
patch \ patch \
gawk \ gawk \
xz-dev \ xz-dev \
crosstool-ng gcc-cross-embedded
######################################## ########################################
# nlohmann/json (compiled static .a) # # nlohmann/json (compiled static .a) #
@ -115,7 +124,7 @@ RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repo
linux-headers \ linux-headers \
ccache \ ccache \
mold \ mold \
crosstool-ng gcc-cross-embedded
# Configure mold as the default linker # Configure mold as the default linker
ENV LD=mold ENV LD=mold

View File

@ -1,3 +1,11 @@
#!/bin/bash #!/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,35 +1,74 @@
#!/bin/bash #!/bin/bash
# Create volume if it doesn't exist set -e
docker volume create cppbuild-cache
# Directory to copy the executable to PROJECT=ipdemo
OUTDIR="output"
# Build command to run in the container function title() {
BUILD_COMMAND="mkdir -p /app/build && \ # print a title with a line of dashes
cd /app/build && \ echo "--------------------------------"
cmake -G Ninja /app/src && \ echo "$1"
ninja -j$(nproc) && \ echo "--------------------------------"
mkdir /app/src/$OUTDIR && \ }
cp /app/build/ipdemo /app/src/$OUTDIR/ipdemo && \
chown -R $(id -u):$(id -g) /app/src/$OUTDIR"
# Run the build in the container function build() {
docker run --rm \ ARCH="$1"
-v cppbuild-cache:/app/build \
-v $(pwd):/app/src \ title "Building $PROJECT.$ARCH"
-w /app/src \
-e CCACHE_DIR=/app/build/.ccache \ if [ "$ARCH" != "arm64" ] && [ "$ARCH" != "amd64" ]; then
-e CC="ccache gcc" \ echo "Unsupported architecture: $ARCH"
-e CXX="ccache g++" \ exit 1
-e LD=mold \ fi
-e CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) \
-e NINJA_STATUS="[%f/%t] " \ # Create volume if it doesn't exist
cpp-httplib-builder:latest \ docker volume create cppbuild-cache-$ARCH
-c "$BUILD_COMMAND"
# 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 -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
docker run --rm \
-v cppbuild-cache:/app/build \
-v $(pwd):/app/src \
-w /app/src \
-e CCACHE_DIR=/app/build/.ccache \
-e CC="ccache gcc" \
-e CXX="ccache g++" \
-e LD=mold \
-e CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) \
-e NINJA_STATUS="[%f/%t] " \
$BUILD_IMAGE \
-c "$BUILD_COMMAND"
# Run the executable if it exists
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
# Run the executable if it exists
if [ -f $OUTDIR/ipdemo ]; then
$OUTDIR/ipdemo
fi

Binary file not shown.