diff --git a/build-base/CLAUDE.md b/build-base/CLAUDE.md index 407eb28..4891e51 100644 --- a/build-base/CLAUDE.md +++ b/build-base/CLAUDE.md @@ -36,8 +36,9 @@ This base image is designed to create statically-linked C++ executables using: 5. **cURL** (8.7.1) - HTTP client with OpenSSL support 6. **MariaDB Connector/C** (3.4.5) - MySQL/MariaDB client 7. **SQLite3** (3.45.0) - Embedded database -8. **MySQL client** (8.0.36) - MySQL client library -9. **Drogon** (latest from git) - C++ web framework +8. **fmt** (10.2.1) - Modern formatting library +9. **spdlog** (1.13.0) - Fast C++ logging library +10. **Drogon** (latest from git) - C++ web framework ### Build Characteristics - All libraries installed in `/usr/local/` with specific prefixes diff --git a/build-base/Dockerfile.dropshell-build-base b/build-base/Dockerfile.dropshell-build-base index a739e81..aae9a57 100644 --- a/build-base/Dockerfile.dropshell-build-base +++ b/build-base/Dockerfile.dropshell-build-base @@ -152,6 +152,30 @@ RUN wget https://www.sqlite.org/2024/sqlite-autoconf-3450000.tar.gz && \ # Skip MySQL build - use MariaDB Connector/C for MySQL support instead +# Build fmt library statically +ARG FMT_VERSION=10.2.1 +WORKDIR /tmp +RUN curl -LO https://github.com/fmtlib/fmt/archive/refs/tags/${FMT_VERSION}.tar.gz && \ + tar xzf ${FMT_VERSION}.tar.gz && \ + cd fmt-${FMT_VERSION} && \ + mkdir build && cd build && \ + cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=/usr/local && \ + make -j$(nproc) && \ + make install && \ + cd / && rm -rf /tmp/fmt-${FMT_VERSION} /tmp/${FMT_VERSION}.tar.gz + +# Build spdlog library statically +ARG SPDLOG_VERSION=1.13.0 +WORKDIR /tmp +RUN curl -LO https://github.com/gabime/spdlog/archive/refs/tags/v${SPDLOG_VERSION}.tar.gz && \ + tar xzf v${SPDLOG_VERSION}.tar.gz && \ + cd spdlog-${SPDLOG_VERSION} && \ + mkdir build && cd build && \ + cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=/usr/local -DSPDLOG_FMT_EXTERNAL=ON && \ + make -j$(nproc) && \ + make install && \ + cd / && rm -rf /tmp/spdlog-${SPDLOG_VERSION} /tmp/v${SPDLOG_VERSION}.tar.gz + #ARG DROGON_VERSION=1.9.5 WORKDIR /tmp RUN git clone --recurse-submodules https://github.com/drogonframework/drogon.git /tmp/drogon && \ diff --git a/build.sh b/build.sh index 1e76629..dde1097 100755 --- a/build.sh +++ b/build.sh @@ -17,5 +17,5 @@ docker build \ -f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \ --build-arg PROJECT="${PROJECT}" \ --output "${SCRIPT_DIR}/output" \ - "${SCRIPT_DIR}/${PROJECT}" + "${SCRIPT_DIR}/tests/${PROJECT}" diff --git a/test.sh b/test.sh index 4e38360..b07880e 100755 --- a/test.sh +++ b/test.sh @@ -4,9 +4,33 @@ set -euo pipefail SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -echo "Testing" +echo "Building and testing test_libs..." -[ -f "${SCRIPT_DIR}/output/ipdemo" ] || { echo "ipdemo binary not found"; exit 1; } +# Build test_libs +docker run --rm \ + -v "${SCRIPT_DIR}/tests:/tests" \ + -v "${SCRIPT_DIR}/output:/output" \ + -w /tests/test_libs \ + gitea.jde.nz/public/dropshell-build-base:latest \ + sh -c "mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make && cp test_libs /output/" -"${SCRIPT_DIR}/output/ipdemo" || echo "Success!" +# Run test_libs +if [ -f "${SCRIPT_DIR}/output/test_libs" ]; then + echo "Running test_libs..." + "${SCRIPT_DIR}/output/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/ipdemo" ]; then + echo "Running ipdemo..." + "${SCRIPT_DIR}/output/ipdemo" || echo "ipdemo test completed!" +else + echo "ipdemo binary not found - run ./build.sh first" +fi \ No newline at end of file diff --git a/ipdemo/CMakeLists.txt b/tests/ipdemo/CMakeLists.txt similarity index 100% rename from ipdemo/CMakeLists.txt rename to tests/ipdemo/CMakeLists.txt diff --git a/ipdemo/cmake_prebuild.sh b/tests/ipdemo/cmake_prebuild.sh similarity index 100% rename from ipdemo/cmake_prebuild.sh rename to tests/ipdemo/cmake_prebuild.sh diff --git a/ipdemo/src/assert.hpp b/tests/ipdemo/src/assert.hpp similarity index 100% rename from ipdemo/src/assert.hpp rename to tests/ipdemo/src/assert.hpp diff --git a/ipdemo/src/autogen/version.hpp b/tests/ipdemo/src/autogen/version.hpp similarity index 100% rename from ipdemo/src/autogen/version.hpp rename to tests/ipdemo/src/autogen/version.hpp diff --git a/ipdemo/src/http_utils.cpp b/tests/ipdemo/src/http_utils.cpp similarity index 100% rename from ipdemo/src/http_utils.cpp rename to tests/ipdemo/src/http_utils.cpp diff --git a/ipdemo/src/http_utils.hpp b/tests/ipdemo/src/http_utils.hpp similarity index 100% rename from ipdemo/src/http_utils.hpp rename to tests/ipdemo/src/http_utils.hpp diff --git a/ipdemo/src/httplib.hpp b/tests/ipdemo/src/httplib.hpp similarity index 100% rename from ipdemo/src/httplib.hpp rename to tests/ipdemo/src/httplib.hpp diff --git a/ipdemo/src/main.cpp b/tests/ipdemo/src/main.cpp similarity index 100% rename from ipdemo/src/main.cpp rename to tests/ipdemo/src/main.cpp diff --git a/ipdemo/src/version.hpp.in b/tests/ipdemo/src/version.hpp.in similarity index 100% rename from ipdemo/src/version.hpp.in rename to tests/ipdemo/src/version.hpp.in diff --git a/tests/test_libs/CMakeLists.txt b/tests/test_libs/CMakeLists.txt new file mode 100644 index 0000000..a571f43 --- /dev/null +++ b/tests/test_libs/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.16) +project(test_libs) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Force static linking +set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++") +set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") + +# Find packages +find_package(fmt REQUIRED) +find_package(spdlog REQUIRED) +find_package(SQLite3 REQUIRED) +find_package(Threads REQUIRED) + +add_executable(test_libs test_libs.cpp) + +target_link_libraries(test_libs + fmt::fmt + spdlog::spdlog + SQLite3::SQLite3 + Threads::Threads + rt +) \ No newline at end of file diff --git a/tests/test_libs/test_libs.cpp b/tests/test_libs/test_libs.cpp new file mode 100644 index 0000000..0dbc3c3 --- /dev/null +++ b/tests/test_libs/test_libs.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +#include + +int main() { + // Test fmt + std::string formatted = fmt::format("Testing fmt: {} + {} = {}", 1, 2, 3); + std::cout << formatted << std::endl; + + // Test spdlog + spdlog::info("Testing spdlog: Hello from spdlog!"); + spdlog::warn("This is a warning message"); + + // Test sqlite3 + sqlite3* db; + int rc = sqlite3_open(":memory:", &db); + if (rc == SQLITE_OK) { + spdlog::info("SQLite3 opened successfully, version: {}", sqlite3_libversion()); + sqlite3_close(db); + } else { + spdlog::error("Failed to open SQLite3"); + } + + // Test pthread + std::thread t([]() { + spdlog::info("Hello from thread!"); + }); + t.join(); + + // Test rt (real-time) - using clock_gettime + struct timespec ts; + if (clock_gettime(CLOCK_REALTIME, &ts) == 0) { + spdlog::info("Real-time clock: {}.{} seconds", ts.tv_sec, ts.tv_nsec); + } + + spdlog::info("All libraries linked successfully!"); + return 0; +} \ No newline at end of file