108 lines
2.9 KiB
Markdown
108 lines
2.9 KiB
Markdown
# Dropshell Build
|
|
|
|
A Docker-based build system for creating statically-linked C++ executables using Alpine Linux and musl libc.
|
|
|
|
## Overview
|
|
|
|
This repository provides a comprehensive C++ development environment with:
|
|
|
|
1. **dropshell-build-base**: A base image with C++ toolchain and libraries
|
|
2. **dropshell-build**: Multi-stage Docker build system for C++ projects
|
|
3. **Test projects**: Sample applications demonstrating the build system
|
|
|
|
## Features
|
|
|
|
### Libraries Available
|
|
|
|
The base image includes statically-linked versions of:
|
|
|
|
- **Web Framework**: Drogon with async HTTP capabilities
|
|
- **Database Support**: PostgreSQL (libpq), MySQL/MariaDB, SQLite3
|
|
- **HTTP Clients**:
|
|
- Custom Drogon-based HTTP utilities (see `ipdemo`)
|
|
- CPR (C++ Requests) library for simplified HTTP requests
|
|
- **Networking**: cURL, c-ares, OpenSSL
|
|
- **JSON**: nlohmann/json, jsoncpp
|
|
- **Compression**: zlib, zstd, lzma
|
|
- **Logging**: spdlog, fmt
|
|
- **Utilities**: ccache, mold linker
|
|
|
|
### HTTP Client Options
|
|
|
|
Two HTTP client approaches are available:
|
|
|
|
1. **Drogon HTTP Utilities** (see `tests/ipdemo/src/http_utils.hpp`):
|
|
```cpp
|
|
auto response = http_get("example.com", "/api/endpoint", true, 10.0);
|
|
if (response.success && response.status_code == 200) {
|
|
std::cout << response.body << std::endl;
|
|
}
|
|
```
|
|
|
|
2. **CPR Library** (C++ Requests):
|
|
```cpp
|
|
#include <cpr/cpr.h>
|
|
cpr::Response r = cpr::Get(cpr::Url{"https://example.com/api"});
|
|
if (r.status_code == 200) {
|
|
std::cout << r.text << std::endl;
|
|
}
|
|
```
|
|
|
|
To use CPR in your CMakeLists.txt with proper static linking:
|
|
```cmake
|
|
find_package(nlohmann_json REQUIRED)
|
|
|
|
# Find OpenSSL libraries (path varies by architecture)
|
|
find_library(OPENSSL_SSL_LIB NAMES ssl PATHS /usr/local/lib64 /usr/local/lib NO_DEFAULT_PATH)
|
|
find_library(OPENSSL_CRYPTO_LIB NAMES crypto PATHS /usr/local/lib64 /usr/local/lib NO_DEFAULT_PATH)
|
|
|
|
# CPR static linking setup
|
|
add_library(cpr::cpr_static STATIC IMPORTED)
|
|
set_target_properties(cpr::cpr_static PROPERTIES
|
|
IMPORTED_LOCATION "/usr/local/lib/libcpr.a"
|
|
INTERFACE_INCLUDE_DIRECTORIES "/usr/local/include"
|
|
INTERFACE_LINK_LIBRARIES "/usr/local/lib/libcurl.a;${OPENSSL_SSL_LIB};${OPENSSL_CRYPTO_LIB};/usr/lib/libz.a;/usr/lib/libzstd.a;lzma;dl"
|
|
)
|
|
|
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
|
nlohmann_json::nlohmann_json
|
|
cpr::cpr_static)
|
|
```
|
|
|
|
## Quick Start
|
|
|
|
### Building the Base Image
|
|
|
|
```bash
|
|
cd build-base
|
|
./build.sh
|
|
```
|
|
|
|
### Building a Project
|
|
|
|
```bash
|
|
./build.sh
|
|
```
|
|
|
|
### Testing
|
|
|
|
```bash
|
|
./test.sh
|
|
```
|
|
|
|
## Project Structure
|
|
|
|
### Test Projects
|
|
|
|
- **ipdemo**: Demonstrates Drogon HTTP utilities and JSON processing
|
|
- **test_libs**: Tests all available libraries (fmt, spdlog, SQLite3, etc.)
|
|
- **cprdemo**: Example using CPR library for HTTP requests
|
|
|
|
### Environment Variables
|
|
|
|
- `CMAKE_BUILD_TYPE`: "Debug" or "Release" (default: Debug)
|
|
- `PROJECT`: Project name to build (default: ipdemo)
|
|
|
|
## Installation
|
|
|