getpkg/test/build.sh
2025-05-26 19:38:05 +12:00

82 lines
2.1 KiB
Bash
Executable File

#!/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-$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 -p /app/src/$OUTDIR && \
cp /app/build/$PROJECT /app/src/$OUTDIR/$PROJECT.$ARCH && \
chown -R $(id -u):$(id -g) /app/src/$OUTDIR"
case $ARCH in
"arm64") export TARGET_TRIPLE="aarch64-linux-musl";;
"amd64") export TARGET_TRIPLE="x86_64-linux-musl";;
*) echo "Unsupported architecture $ARCH"; exit 1;;
esac
export CC="ccache ${TARGET_TRIPLE}-gcc"
export CXX="ccache ${TARGET_TRIPLE}-g++"
# 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 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