Craziness with multiarch
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 1m18s

This commit is contained in:
Your Name 2025-05-25 22:12:14 +12:00
parent d3ceb3f4be
commit f45baa8362
4 changed files with 112 additions and 45 deletions

View File

@ -113,12 +113,21 @@ FetchContent_Declare(
) )
FetchContent_MakeAvailable(nlohmann_json) FetchContent_MakeAvailable(nlohmann_json)
# Find zlib
find_package(ZLIB REQUIRED)
# Link libraries # Link libraries
target_link_libraries(dropshell PRIVATE target_link_libraries(dropshell PRIVATE
libassert::assert libassert::assert
cpptrace::cpptrace cpptrace::cpptrace
httplib::httplib httplib::httplib
nlohmann_json::nlohmann_json nlohmann_json::nlohmann_json
ZLIB::ZLIB
)
# Set static linking flags
set_target_properties(dropshell PROPERTIES
LINK_FLAGS "-static-libstdc++ -static-libgcc -Wl,-Bstatic -Wl,-Bdynamic"
) )
# Install targets # Install targets

View File

@ -0,0 +1,70 @@
# syntax=docker/dockerfile:1.4
FROM --platform=$BUILDPLATFORM alpine:3.19 AS deps
# Install build dependencies
RUN apk add --no-cache \
build-base \
cmake \
git \
linux-headers \
musl-dev \
zlib-dev \
bzip2-dev \
xz-dev \
zstd-dev \
curl \
bash \
gcc \
g++ \
libstdc++ \
libstdc++-dev \
ccache \
ninja
FROM deps AS build
ARG TARGETARCH
WORKDIR /source
COPY . .
# Create and run build script
RUN printf '#!/bin/bash\n\
set -e\n\
echo "Setting up build directory..."\n\
mkdir -p /build/ccache\n\
mkdir -p /build/build_${TARGETARCH}\n\
\n\
echo "Setting up ccache..."\n\
export CCACHE_DIR=/build/ccache\n\
export CCACHE_MAXSIZE=2G\n\
export PATH="/usr/lib/ccache/bin:$PATH"\n\
\n\
echo "Running CMake configuration..."\n\
cd /build/build_${TARGETARCH}\n\
cmake /source -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_FIND_LIBRARY_SUFFIXES=".a" \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache 2>&1 | tee cmake.log\n\
\n\
echo "Starting build..."\n\
ninja -v -j$(nproc) 2>&1 | tee build.log\n\
\n\
echo "Build complete. Checking for binary..."\n\
if [ ! -f dropshell ]; then\n\
echo "Build failed. Directory contents:"\n\
ls -la\n\
echo "CMake log:"\n\
cat cmake.log\n\
echo "Build log:"\n\
cat build.log\n\
exit 1\n\
fi\n\
\n\
echo "ccache stats:"\n\
ccache -s\n' > /source/docker_build.sh && chmod +x /source/docker_build.sh && /source/docker_build.sh
# Final stage: copy out the binary
FROM scratch AS export-stage
ARG TARGETARCH
COPY --from=build /build/build_${TARGETARCH}/dropshell /dropshell

View File

@ -6,8 +6,7 @@ set -e
# src/utils/createagent.cpp # src/utils/createagent.cpp
# #
SCRIPT_DIR=$(dirname "$0") SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# check if dehydrate is installed # check if dehydrate is installed
if ! command -v dehydrate &> /dev/null; then if ! command -v dehydrate &> /dev/null; then
echo "dehydrate could not be found - installing" echo "dehydrate could not be found - installing"

View File

@ -7,53 +7,42 @@
set -e set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OUTPUT_DIR="$SCRIPT_DIR/output"
DOCKERFILE="$SCRIPT_DIR/Dockerfile.multiarch"
rm -f $SCRIPT_DIR/build_amd64/dropshell $SCRIPT_DIR/build_arm64/dropshell $SCRIPT_DIR/output/dropshell.amd64 $SCRIPT_DIR/output/dropshell.arm64 mkdir -p "$OUTPUT_DIR"
# Determine number of CPU cores for parallel build # Ensure buildx is available
if command -v nproc >/dev/null 2>&1; then if ! docker buildx version &>/dev/null; then
JOBS=$(nproc) echo "Docker Buildx is required. Please install Docker Buildx." >&2
else
JOBS=4 # fallback default
fi
PREV_PWD=$PWD
cd $SCRIPT_DIR
# Build for amd64 (musl)
echo "Building for amd64 (musl)..."
cmake -B build_amd64 -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=x86_64-linux-musl-gcc \
-DCMAKE_CXX_COMPILER=x86_64-linux-musl-g++ \
-DCMAKE_EXE_LINKER_FLAGS="-static" \
-DCMAKE_CXX_FLAGS="-march=x86-64" .
cmake --build build_amd64 --target dropshell --config Release -j"$JOBS"
mkdir -p output
cp build_amd64/dropshell output/dropshell.amd64
# Build for arm64 (musl)
echo "Building for arm64 (musl)..."
cmake -B build_arm64 -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=aarch64-linux-musl-gcc \
-DCMAKE_CXX_COMPILER=aarch64-linux-musl-g++ \
-DCMAKE_EXE_LINKER_FLAGS="-static" \
-DCMAKE_CXX_FLAGS="-march=armv8-a" \
-DCMAKE_SYSTEM_PROCESSOR=aarch64 .
cmake --build build_arm64 --target dropshell --config Release -j"$JOBS"
mkdir -p output
cp build_arm64/dropshell output/dropshell.arm64
if [ ! -f output/dropshell.amd64 ]; then
echo "output/dropshell.amd64 not found!" >&2
exit 1 exit 1
fi fi
if [ ! -f output/dropshell.arm64 ]; then # Build for x86_64
echo "output/dropshell.arm64 not found!" >&2 DOCKER_BUILDKIT=1 docker buildx build --platform linux/amd64 \
exit 1 -f "$DOCKERFILE" \
fi --output type=local,dest="$OUTPUT_DIR/amd64_tmp" \
--cache-from type=local,src=/tmp/dropshell-cache \
--cache-to type=local,dest=/tmp/dropshell-cache,mode=max \
"$SCRIPT_DIR"
mv "$OUTPUT_DIR/amd64_tmp/dropshell" "$OUTPUT_DIR/dropshell.amd64"
rm -rf "$OUTPUT_DIR/amd64_tmp"
echo "Built output/dropshell.amd64"
# Build for aarch64
DOCKER_BUILDKIT=1 docker buildx build --platform linux/arm64 \
-f "$DOCKERFILE" \
--output type=local,dest="$OUTPUT_DIR/arm64_tmp" \
--cache-from type=local,src=/tmp/dropshell-cache \
--cache-to type=local,dest=/tmp/dropshell-cache,mode=max \
"$SCRIPT_DIR"
mv "$OUTPUT_DIR/arm64_tmp/dropshell" "$OUTPUT_DIR/dropshell.arm64"
rm -rf "$OUTPUT_DIR/arm64_tmp"
echo "Built output/dropshell.arm64"
echo "Builds complete:" echo "Builds complete:"
ls -lh output/dropshell.* ls -lh "$OUTPUT_DIR"/dropshell.*
cd $PREV_PWD