'Generic Commit'
Some checks failed
dropshell-build / build (push) Has been cancelled

This commit is contained in:
Your Name
2025-06-14 22:07:46 +12:00
parent e4d0661d50
commit 1ac00e83f8
12 changed files with 164 additions and 144 deletions

View File

@ -0,0 +1,63 @@
ARG IMAGE_TAG
FROM gitea.jde.nz/public/dropshell-build-base:test AS builder
ARG PROJECT
ARG CMAKE_BUILD_TYPE=Debug
# Set working directory
WORKDIR /app
# Create cache directories
RUN mkdir -p /ccache /build-cache
# Set up ccache
ENV CCACHE_DIR=/ccache
ENV CCACHE_COMPILERCHECK=content
ENV CCACHE_MAXSIZE=2G
COPY . .
# Configure and build with ccache using cache mounts
RUN --mount=type=cache,target=/ccache \
--mount=type=cache,target=/build \
mkdir -p /build && \
cmake -G Ninja -S /app -B /build \
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=mold -static -g" \
-DCMAKE_CXX_FLAGS="-g -fno-omit-frame-pointer" \
-DCMAKE_C_FLAGS="-g -fno-omit-frame-pointer" \
-DCMAKE_FIND_LIBRARY_SUFFIXES=".a" \
-DZLIB_BUILD_SHARED=OFF \
-DZLIB_BUILD_STATIC=ON \
-DBUILD_SHARED_LIBS=OFF \
-DPROJECT_NAME="${PROJECT}" \
-DCMAKE_STRIP=OFF \
-DIGNORE_DYNAMIC_LOADING=ON \
-DOPENSSL_USE_STATIC_LIBS=TRUE \
${CMAKE_TOOLCHAIN_FILE:+-DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE}
# Build with cache mounts
RUN --mount=type=cache,target=/ccache \
--mount=type=cache,target=/build \
cmake --build /build --target run_prebuild_script
RUN --mount=type=cache,target=/ccache \
--mount=type=cache,target=/build \
cmake --build /build
# Copy the built executable to a regular directory for the final stage
RUN --mount=type=cache,target=/build \
mkdir -p /output && \
find /build -type f -executable -name "*${PROJECT}*" -exec cp {} /output/${PROJECT} \; || \
find /build -type f -executable -exec cp {} /output/${PROJECT} \;
# Final stage that only contains the binary
FROM scratch AS project
ARG PROJECT
# Copy the actual binary from the regular directory
COPY --from=builder /output/${PROJECT} /${PROJECT}

58
tests/build.sh Executable file
View File

@ -0,0 +1,58 @@
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
#make canonical
ROOT_DIR="$(cd "${SCRIPT_DIR}/../" &> /dev/null && pwd)"
export CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE:-Debug}"
# Function to build a project
build_project() {
local project="$1"
local platform="${2:-}"
local build_cmd
local tag
local output_dir
if [ -n "${platform}" ]; then
build_cmd=(docker buildx build "--platform" "${platform}")
local tag_suffix="${platform##*/}" # Extract arch from platform (e.g., linux/arm64 -> arm64)
tag="gitea.jde.nz/public/${project}-build-${tag_suffix}:test"
output_dir="${SCRIPT_DIR}/output/${tag_suffix}"
else
build_cmd=(docker build)
tag="gitea.jde.nz/public/${project}-build:test"
output_dir="${SCRIPT_DIR}/output/native"
fi
mkdir -p "${output_dir}"
"${build_cmd[@]}" \
-t "${tag}" \
-f "${SCRIPT_DIR}/Dockerfile.test-build" \
--build-arg PROJECT="${project}" \
--build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
--output "${output_dir}" \
"${SCRIPT_DIR}/${project}"
}
# Clean and prepare output directory
rm -rf "${SCRIPT_DIR}/output"
mkdir -p "${SCRIPT_DIR}/output"
# Build all projects
echo "Building ipdemo..."
build_project "ipdemo"
echo "Building ipdemo for aarch64..."
build_project "ipdemo" "linux/arm64"
echo "Building test_libs..."
build_project "test_libs"

19
tests/clear-cache.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
set -euo pipefail
echo "Clearing Docker build cache..."
# Clear the build cache
docker builder prune -af
# Optional: Also clear dangling images and containers
echo "Cleaning up dangling images and stopped containers..."
docker system prune -f
echo "Build cache cleared successfully!"
# Show disk usage after cleanup
echo ""
echo "Docker disk usage after cleanup:"
docker system df

View File

@ -29,7 +29,42 @@ target_include_directories(${PROJECT_NAME} PRIVATE
# Find packages
set(CMAKE_PREFIX_PATH /usr/local)
find_package(OpenSSL REQUIRED)
# Find OpenSSL libraries in multiple possible locations
find_library(OPENSSL_SSL_LIB
NAMES ssl libssl libssl.a
PATHS /usr/local/lib /usr/local/lib64 /usr/lib /usr/lib64
NO_DEFAULT_PATH
)
find_library(OPENSSL_CRYPTO_LIB
NAMES crypto libcrypto libcrypto.a
PATHS /usr/local/lib /usr/local/lib64 /usr/lib /usr/lib64
NO_DEFAULT_PATH
)
if(NOT OPENSSL_SSL_LIB OR NOT OPENSSL_CRYPTO_LIB)
message(FATAL_ERROR "Could not find OpenSSL libraries. SSL: ${OPENSSL_SSL_LIB}, Crypto: ${OPENSSL_CRYPTO_LIB}")
endif()
# Manually create OpenSSL targets for cross-compilation
if(NOT TARGET OpenSSL::Crypto)
add_library(OpenSSL::Crypto STATIC IMPORTED)
set_target_properties(OpenSSL::Crypto PROPERTIES
IMPORTED_LOCATION ${OPENSSL_CRYPTO_LIB}
INTERFACE_INCLUDE_DIRECTORIES /usr/local/include
)
endif()
if(NOT TARGET OpenSSL::SSL)
add_library(OpenSSL::SSL STATIC IMPORTED)
set_target_properties(OpenSSL::SSL PROPERTIES
IMPORTED_LOCATION ${OPENSSL_SSL_LIB}
INTERFACE_INCLUDE_DIRECTORIES /usr/local/include
INTERFACE_LINK_LIBRARIES OpenSSL::Crypto
)
endif()
find_package(Drogon CONFIG REQUIRED)
find_package(nlohmann_json REQUIRED)

41
tests/test.sh Executable file
View File

@ -0,0 +1,41 @@
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
echo ""
echo "testing test_libs..."
# Run test_libs
if [ -f "${SCRIPT_DIR}/output/native/test_libs" ]; then
echo "Running test_libs..."
"${SCRIPT_DIR}/output/native/test_libs"
echo "test_libs completed successfully!"
else
echo "test_libs binary not found"
exit 1
fi
echo ""
echo "Testing ipdemo..."
# Check if ipdemo exists
if [ -f "${SCRIPT_DIR}/output/native/ipdemo" ]; then
echo "Running ipdemo..."
"${SCRIPT_DIR}/output/native/ipdemo" || echo "ipdemo test completed!"
else
echo "ipdemo binary not found - run ./build.sh first"
fi
echo ""
echo "Testing cross-architecture builds..."
# Verify the binary was built and check its architecture
if [ -f "${SCRIPT_DIR}/output/arm64/ipdemo" ]; then
echo "aarch64 ipdemo binary built successfully!"
echo "Architecture info:"
file "${SCRIPT_DIR}/output/arm64/ipdemo" || true
else
echo "aarch64 ipdemo binary not found"
fi