Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 160 additions & 24 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CMake on multiple platforms
name: CMake Multi-Platform Build

on:
push:
Expand All @@ -7,39 +7,164 @@ on:
branches: [ "master" ]

jobs:
build:
runs-on: ${{ matrix.os }}
linux:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
build_type: [Release]
compiler: [gcc, clang]
build_type: [Release, Debug]
shared_libs: [ON, OFF]
include:
- os: ubuntu-latest
- compiler: gcc
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
- compiler: clang
c_compiler: clang
cpp_compiler: clang++
- os: windows-latest

steps:
- uses: actions/checkout@v4

- name: Start PostgreSQL
run: |
docker run -d --name postgres \
-e POSTGRES_HOST_AUTH_METHOD=trust \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD= \
-e POSTGRES_DB=postgres \
-p 5432:5432 postgres:latest
for i in {1..30}; do
docker exec postgres pg_isready -U postgres && break || sleep 1
done

- name: Start Redis
run: |
docker run -d --name redis -p 6379:6379 redis:latest
for i in {1..30}; do
docker exec redis redis-cli ping && break || sleep 1
done

- name: Setup vcpkg
uses: lukka/run-vcpkg@v11
with:
vcpkgDirectory: '${{ github.workspace }}/vcpkg'
vcpkgJsonGlob: 'vcpkg.json'

- name: Set VCPKG_ROOT
shell: bash
run: echo "VCPKG_ROOT=${{ github.workspace }}/vcpkg" >> $GITHUB_ENV

- name: Configure CMake
run: >
cmake -B build
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DBUILD_SHARED_LIBS=${{ matrix.shared_libs }}
-DBUILD_TESTS=ON
-DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake
-S Light

- name: Build
run: cmake --build build --config ${{ matrix.build_type }}

- name: Create config_test.json
working-directory: build
run: |
echo '{"app_name": "LightlibApp"}' > config_test.json
mkdir -p ${{ matrix.build_type }}
cp config_test.json ${{ matrix.build_type }}/
shell: bash

- name: Run tests
working-directory: build
run: ./lightlib_tests
shell: bash

windows:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
compiler: [cl]
build_type: [Release, Debug]
shared_libs: [ON, OFF]
include:
- compiler: cl
c_compiler: cl
cpp_compiler: cl
- os: macos-latest

steps:
- uses: actions/checkout@v4

- name: Setup vcpkg
uses: lukka/run-vcpkg@v11
with:
vcpkgDirectory: '${{ github.workspace }}/vcpkg'
vcpkgJsonGlob: 'vcpkg.json'

- name: Set VCPKG_ROOT
shell: bash
run: echo "VCPKG_ROOT=${{ github.workspace }}/vcpkg" >> $GITHUB_ENV

- name: Configure CMake
run: >
cmake -B build
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DBUILD_SHARED_LIBS=${{ matrix.shared_libs }}
-DBUILD_TESTS=ON
-DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake
-S Light

- name: Build
run: cmake --build build --config ${{ matrix.build_type }}

- name: Copy DLLs to test directory
run: |
$dest = "build\${{ matrix.build_type }}"
New-Item -ItemType Directory -Force -Path $dest | Out-Null
if ("${{ matrix.build_type }}" -eq "Release") {
Copy-Item -Path "build\vcpkg_installed\x64-windows\bin\*.dll" -Destination $dest -ErrorAction SilentlyContinue
} else {
Copy-Item -Path "build\vcpkg_installed\x64-windows\debug\bin\*.dll" -Destination $dest -ErrorAction SilentlyContinue
}
shell: pwsh

- name: Create config_test.json
working-directory: build
run: |
echo '{"app_name": "LightlibApp"}' > config_test.json
mkdir -p ${{ matrix.build_type }}
cp config_test.json ${{ matrix.build_type }}/
shell: bash

- name: Run tests
working-directory: build
run: ./${{ matrix.build_type }}/lightlib_tests.exe
shell: bash

macos:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
compiler: [clang]
build_type: [Release, Debug]
shared_libs: [ON, OFF]
include:
- compiler: clang
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl
- os: macos-latest
c_compiler: cl

steps:
- uses: actions/checkout@v4

- name: Install system dependencies
run: brew install autoconf

- name: Setup vcpkg
uses: lukka/run-vcpkg@v11
with:
Expand All @@ -52,16 +177,27 @@ jobs:

- name: Configure CMake
run: >
cmake -B ${{ github.workspace }}/build
cmake -B build
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DBUILD_SHARED_LIBS=${{ matrix.shared_libs }}
-DBUILD_TESTS=ON
-DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake
-S ${{ github.workspace }}
-S Light

- name: Build
run: cmake --build ${{ github.workspace }}/build --config ${{ matrix.build_type }}
run: cmake --build build --config ${{ matrix.build_type }}

- name: Create config_test.json
working-directory: build
run: |
echo '{"app_name": "LightlibApp"}' > config_test.json
mkdir -p ${{ matrix.build_type }}
cp config_test.json ${{ matrix.build_type }}/
shell: bash

- name: Test
working-directory: ${{ github.workspace }}/build
run: ctest --build-config ${{ matrix.build_type }} --output-on-failure
- name: Run tests
working-directory: build
run: ./lightlib_tests --gtest_filter=-RoutingTest.*
shell: bash
15 changes: 6 additions & 9 deletions Light/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(WIN32)
set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/vcpkg_installed/x64-windows" CACHE STRING "")
elseif(UNIX)
set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/vcpkg_installed/x64-linux" CACHE STRING "")
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if(WIN32)
set(CMAKE_THREAD_PREFER_PTHREAD OFF)
Expand Down Expand Up @@ -187,7 +182,7 @@ install(
DESTINATION share/lightlib
)

option(BUILD_TESTS "Build tests" OFF)
option(BUILD_TESTS "Build tests" ON)

if(BUILD_TESTS)
message(STATUS "Building tests")
Expand Down Expand Up @@ -229,8 +224,10 @@ if(BUILD_TESTS)
${LIBRARIES}
)

include(GoogleTest)
gtest_discover_tests(lightlib_tests)
# include(GoogleTest)
# gtest_discover_tests(lightlib_tests)

# add_test(NAME lightlib_tests COMMAND lightlib_tests)

add_custom_target(check
COMMAND $<TARGET_FILE:lightlib_tests>
Expand Down
3 changes: 2 additions & 1 deletion Light/include/lightlib/Database/Queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <hiredis/hiredis.h>
#include <iostream>
#include <cstdint>
#include <string>
#include <stdexcept>
#include "../vendor/Debug/Logger.hpp"
Expand All @@ -34,7 +35,7 @@ namespace lightlib {
static void disconnect();
static void push(const std::string& queue_name, const std::string& value);
static std::string pop(const std::string& queue_name);
static __int64 length(const std::string& queue_name);
static int64_t length(const std::string& queue_name);

private:
static redisContext* context_;
Expand Down
4 changes: 2 additions & 2 deletions Light/src/Database/Queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ std::string Queue::pop(const std::string& queue_name) {
return result;
}

__int64 Queue::length(const std::string& queue_name) {
int64_t Queue::length(const std::string& queue_name) {
if (!context_) {
Logger::log("Not connected to Redis.", "ERROR");
throw std::runtime_error("Not connected to Redis.");
Expand All @@ -112,7 +112,7 @@ __int64 Queue::length(const std::string& queue_name) {
throw std::runtime_error("Failed to execute LLEN command.");
}

__int64 len = reply->integer;
int64_t len = reply->integer;
freeReplyObject(reply);
std::cout << "Queue '" << queue_name << "' length: " << len << std::endl;
return len;
Expand Down
1 change: 1 addition & 0 deletions Light/tests/unit/filesystem/test_storage_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include <gtest/gtest.h>
#include <algorithm>
#include "../../../include/lightlib/Filesystem/StorageManager.hpp"
#include "../../../include/lightlib/Filesystem/FileDriver.hpp"

Expand Down
4 changes: 3 additions & 1 deletion Light/tests/unit/routing/routing_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ TEST_F(RoutingTest, AddRouteAndGet) {
R(GET, "/test/json", test_controller, json_response);
R(POST, "/test/echo", test_controller, echo_post);

std::this_thread::sleep_for(std::chrono::milliseconds(200));

lightlib::HttpClient client;
client.set_verify_ssl(false);
client.set_timeout(std::chrono::seconds(5));
client.set_timeout(std::chrono::seconds(10));

try {
auto response = RunAsync([&]() -> boost::asio::awaitable<lightlib::Response> {
Expand Down
Loading