75 lines
1.9 KiB
Bash
Executable File
75 lines
1.9 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"
|
|
|
|
# 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
|
|
|