This commit is contained in:
parent
091c1f0850
commit
eeb5d44b73
@ -1,4 +1,4 @@
|
||||
FROM --platform=$BUILDPLATFORM gitea.jde.nz/public/dropshell-build-base:latest AS builder
|
||||
FROM gitea.jde.nz/public/dropshell-build-base:latest AS builder
|
||||
|
||||
ARG PROJECT
|
||||
ARG CMAKE_BUILD_TYPE=Debug
|
||||
@ -6,11 +6,25 @@ 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
|
||||
RUN --mount=type=cache,target=/build \
|
||||
# Multi-architecture OpenSSL detection handled in cmake step
|
||||
|
||||
# Configure and build with ccache using cache mounts
|
||||
RUN --mount=type=cache,target=/ccache \
|
||||
--mount=type=cache,target=/build \
|
||||
mkdir -p /build && \
|
||||
SSL_LIB=$(find /usr/local -name "libssl.a" | head -1) && \
|
||||
CRYPTO_LIB=$(find /usr/local -name "libcrypto.a" | head -1) && \
|
||||
echo "Found SSL: $SSL_LIB, Crypto: $CRYPTO_LIB" && \
|
||||
cmake -G Ninja -S /app -B /build \
|
||||
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
|
||||
@ -25,16 +39,25 @@ RUN --mount=type=cache,target=/build \
|
||||
-DPROJECT_NAME="${PROJECT}" \
|
||||
-DCMAKE_STRIP=OFF \
|
||||
-DIGNORE_DYNAMIC_LOADING=ON \
|
||||
-DOPENSSL_ROOT_DIR=/usr/local \
|
||||
-DOPENSSL_USE_STATIC_LIBS=TRUE \
|
||||
-DOPENSSL_SSL_LIBRARY="$SSL_LIB" \
|
||||
-DOPENSSL_CRYPTO_LIBRARY="$CRYPTO_LIB" \
|
||||
-DOPENSSL_INCLUDE_DIR=/usr/local/include \
|
||||
${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
|
||||
|
||||
# Explicitly build dependencies first (cached separately)
|
||||
RUN --mount=type=cache,target=/build cmake --build /build --target run_prebuild_script
|
||||
|
||||
RUN --mount=type=cache,target=/build cmake --build /build
|
||||
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 && \
|
||||
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} \;
|
||||
|
||||
|
@ -75,11 +75,19 @@ RUN curl -LO https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz &&
|
||||
fi && \
|
||||
./Configure no-shared no-dso no-tests no-async $OPENSSL_TARGET \
|
||||
--prefix=/usr/local \
|
||||
--openssldir=/usr/local/ssl \
|
||||
-static -fPIC && \
|
||||
make -j$(nproc) && \
|
||||
make install_sw && \
|
||||
cd / && rm -rf /tmp/openssl-${OPENSSL_VERSION} /tmp/openssl-${OPENSSL_VERSION}.tar.gz
|
||||
|
||||
# Set environment variables to help CMake and other tools find OpenSSL
|
||||
ENV OPENSSL_ROOT_DIR=/usr/local \
|
||||
OPENSSL_INCLUDE_DIR=/usr/local/include \
|
||||
OPENSSL_CRYPTO_LIBRARY=/usr/local/lib/libcrypto.a \
|
||||
OPENSSL_SSL_LIBRARY=/usr/local/lib/libssl.a \
|
||||
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
|
||||
|
||||
# Build jsoncpp statically with musl - use stable version known to work with Drogon
|
||||
ARG JSONCPP_VERSION=1.9.5
|
||||
WORKDIR /tmp
|
||||
|
60
build.sh
60
build.sh
@ -10,20 +10,48 @@ export CMAKE_BUILD_TYPE="Debug"
|
||||
rm -rf "${SCRIPT_DIR}/output"
|
||||
mkdir -p "${SCRIPT_DIR}/output"
|
||||
|
||||
PROJECT="ipdemo"
|
||||
docker build \
|
||||
-t "gitea.jde.nz/public/${PROJECT}-build:latest" \
|
||||
-f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \
|
||||
--build-arg PROJECT="${PROJECT}" \
|
||||
--build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
|
||||
--output "${SCRIPT_DIR}/output" \
|
||||
"${SCRIPT_DIR}/tests/${PROJECT}"
|
||||
# If PROJECT is set, build only that project
|
||||
if [ -n "${PROJECT:-}" ]; then
|
||||
docker build \
|
||||
-t "gitea.jde.nz/public/${PROJECT}-build:latest" \
|
||||
-f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \
|
||||
--build-arg PROJECT="${PROJECT}" \
|
||||
--build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
|
||||
--output "${SCRIPT_DIR}/output" \
|
||||
"${SCRIPT_DIR}/tests/${PROJECT}"
|
||||
else
|
||||
# Build all projects
|
||||
PROJECT="ipdemo"
|
||||
docker build \
|
||||
-t "gitea.jde.nz/public/${PROJECT}-build:latest" \
|
||||
-f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \
|
||||
--build-arg PROJECT="${PROJECT}" \
|
||||
--build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
|
||||
--output "${SCRIPT_DIR}/output" \
|
||||
"${SCRIPT_DIR}/tests/${PROJECT}"
|
||||
|
||||
|
||||
|
||||
# Test aarch64 build of ipdemo
|
||||
echo "Building ipdemo for aarch64..."
|
||||
PROJECT="ipdemo"
|
||||
docker buildx build \
|
||||
--platform linux/arm64 \
|
||||
-t "gitea.jde.nz/public/ipdemo-build:aarch64" \
|
||||
-f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \
|
||||
--build-arg PROJECT="${PROJECT}" \
|
||||
--build-arg CMAKE_BUILD_TYPE="Debug" \
|
||||
--output "${SCRIPT_DIR}/output/aarch64" \
|
||||
"${SCRIPT_DIR}/tests/${PROJECT}"
|
||||
|
||||
|
||||
PROJECT="test_libs"
|
||||
docker build \
|
||||
-t "gitea.jde.nz/public/${PROJECT}-build:latest" \
|
||||
-f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \
|
||||
--build-arg PROJECT="${PROJECT}" \
|
||||
--build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
|
||||
--output "${SCRIPT_DIR}/output" \
|
||||
"${SCRIPT_DIR}/tests/${PROJECT}"
|
||||
fi
|
||||
|
||||
PROJECT="test_libs"
|
||||
docker build \
|
||||
-t "gitea.jde.nz/public/${PROJECT}-build:latest" \
|
||||
-f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \
|
||||
--build-arg PROJECT="${PROJECT}" \
|
||||
--build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
|
||||
--output "${SCRIPT_DIR}/output" \
|
||||
"${SCRIPT_DIR}/tests/${PROJECT}"
|
||||
|
15
test.sh
15
test.sh
@ -4,7 +4,8 @@ set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
|
||||
echo "Building and testing test_libs..."
|
||||
echo ""
|
||||
echo "testing test_libs..."
|
||||
|
||||
# Run test_libs
|
||||
if [ -f "${SCRIPT_DIR}/output/test_libs" ]; then
|
||||
@ -25,4 +26,16 @@ if [ -f "${SCRIPT_DIR}/output/ipdemo" ]; then
|
||||
"${SCRIPT_DIR}/output/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/aarch64/ipdemo" ]; then
|
||||
echo "aarch64 ipdemo binary built successfully!"
|
||||
echo "Architecture info:"
|
||||
file "${SCRIPT_DIR}/output/aarch64/ipdemo" || true
|
||||
else
|
||||
echo "aarch64 ipdemo binary not found"
|
||||
fi
|
@ -169,6 +169,9 @@ void assert_failed(
|
||||
std::source_location location
|
||||
) {
|
||||
if (!condition) {
|
||||
std::cout << std::flush;
|
||||
std::cerr << std::flush;
|
||||
|
||||
std::cerr << colors::red << "Assertion failed at " << location.file_name() << ":" << location.line() << ": "
|
||||
<< location.function_name() << ": " << message << colors::reset << "\n";
|
||||
print_stacktrace();
|
||||
|
28
tests/path_checker/CMakeLists.txt
Normal file
28
tests/path_checker/CMakeLists.txt
Normal file
@ -0,0 +1,28 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
# Project setup
|
||||
if(NOT DEFINED PROJECT_NAME)
|
||||
set(PROJECT_NAME "path_checker")
|
||||
endif()
|
||||
|
||||
string(TIMESTAMP PROJECT_VERSION "%Y.%m%d.%H%M")
|
||||
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES CXX)
|
||||
|
||||
# Build configuration
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-static")
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
|
||||
# Configure version.hpp and create executable
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/version.hpp"
|
||||
"#pragma once\n#define PROJECT_VERSION \"${PROJECT_VERSION}\"\n")
|
||||
|
||||
add_custom_target(run_prebuild_script ALL
|
||||
COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/cmake_prebuild.sh
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
add_executable(${PROJECT_NAME} path_checker.cpp)
|
||||
add_dependencies(${PROJECT_NAME} run_prebuild_script)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
3
tests/path_checker/cmake_prebuild.sh
Normal file
3
tests/path_checker/cmake_prebuild.sh
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
# Prebuild script for path_checker
|
||||
echo "Running prebuild script for path_checker"
|
101
tests/path_checker/path_checker.cpp
Normal file
101
tests/path_checker/path_checker.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
#include <unistd.h>
|
||||
#include <sys/utsname.h>
|
||||
#include "version.hpp"
|
||||
|
||||
void checkPath(const std::string& path, const std::string& description) {
|
||||
std::cout << "\n=== " << description << " ===" << std::endl;
|
||||
std::cout << "Path: " << path << std::endl;
|
||||
|
||||
if (std::filesystem::exists(path)) {
|
||||
std::cout << "EXISTS: Yes" << std::endl;
|
||||
|
||||
if (std::filesystem::is_directory(path)) {
|
||||
std::cout << "TYPE: Directory" << std::endl;
|
||||
std::cout << "Contents:" << std::endl;
|
||||
|
||||
try {
|
||||
for (const auto& entry : std::filesystem::directory_iterator(path)) {
|
||||
std::cout << " " << entry.path().filename().string() << std::endl;
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
std::cout << " Error listing contents: " << e.what() << std::endl;
|
||||
}
|
||||
} else {
|
||||
std::cout << "TYPE: File" << std::endl;
|
||||
}
|
||||
} else {
|
||||
std::cout << "EXISTS: No" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void checkFile(const std::string& path, const std::string& description) {
|
||||
std::cout << "\n=== " << description << " ===" << std::endl;
|
||||
std::cout << "File: " << path << std::endl;
|
||||
|
||||
if (std::filesystem::exists(path)) {
|
||||
std::cout << "EXISTS: Yes" << std::endl;
|
||||
|
||||
std::ifstream file(path);
|
||||
if (file.is_open()) {
|
||||
std::string line;
|
||||
std::cout << "Contents:" << std::endl;
|
||||
while (std::getline(file, line)) {
|
||||
std::cout << " " << line << std::endl;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::cout << "EXISTS: No" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "Alpine Linux Library Path Checker" << std::endl;
|
||||
std::cout << "Version: " << PROJECT_VERSION << std::endl;
|
||||
|
||||
// Get system information
|
||||
struct utsname sys_info;
|
||||
if (uname(&sys_info) == 0) {
|
||||
std::cout << "\nSystem Information:" << std::endl;
|
||||
std::cout << " System: " << sys_info.sysname << std::endl;
|
||||
std::cout << " Machine: " << sys_info.machine << std::endl;
|
||||
std::cout << " Architecture: " << sys_info.machine << std::endl;
|
||||
}
|
||||
|
||||
// Check standard library directories
|
||||
checkPath("/lib", "System Libraries (/lib)");
|
||||
checkPath("/usr/lib", "User Libraries (/usr/lib)");
|
||||
checkPath("/usr/lib64", "64-bit Libraries (/usr/lib64)");
|
||||
checkPath("/usr/local/lib", "Local Libraries (/usr/local/lib)");
|
||||
|
||||
// Check include directories
|
||||
checkPath("/usr/include", "System Headers (/usr/include)");
|
||||
checkPath("/usr/local/include", "Local Headers (/usr/local/include)");
|
||||
|
||||
// Check architecture-specific paths
|
||||
checkPath("/usr/lib/x86_64-linux-gnu", "x86_64 GNU Libraries");
|
||||
checkPath("/usr/lib/aarch64-linux-gnu", "aarch64 GNU Libraries");
|
||||
checkPath("/lib64", "64-bit System Libraries");
|
||||
|
||||
// Check musl-specific configuration files
|
||||
checkFile("/etc/ld-musl-x86_64.path", "musl x86_64 Library Path Config");
|
||||
checkFile("/etc/ld-musl-aarch64.path", "musl aarch64 Library Path Config");
|
||||
|
||||
// Check for dynamic linker
|
||||
checkFile("/lib/ld-musl-x86_64.so.1", "musl x86_64 Dynamic Linker");
|
||||
checkFile("/lib/ld-musl-aarch64.so.1", "musl aarch64 Dynamic Linker");
|
||||
|
||||
// Check environment variables
|
||||
std::cout << "\n=== Environment Variables ===" << std::endl;
|
||||
const char* ld_library_path = std::getenv("LD_LIBRARY_PATH");
|
||||
std::cout << "LD_LIBRARY_PATH: " << (ld_library_path ? ld_library_path : "(not set)") << std::endl;
|
||||
|
||||
const char* pkg_config_path = std::getenv("PKG_CONFIG_PATH");
|
||||
std::cout << "PKG_CONFIG_PATH: " << (pkg_config_path ? pkg_config_path : "(not set)") << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user