Skip to content

Commit

Permalink
Fix Windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Mar 1, 2024
1 parent f1a90a2 commit b65292a
Show file tree
Hide file tree
Showing 25 changed files with 460 additions and 412 deletions.
14 changes: 0 additions & 14 deletions .dockerignore

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Formatting Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Run clang-format style check for C/C++ programs.
uses: jidicula/clang-format-action@v4.11.0
with:
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -53,7 +53,8 @@ jobs:

- name: Install dependencies
run: |
sudo apt update && sudo apt install libcurl4-gnutls-dev ninja-build ${{matrix.compiler}}
sudo apt update
sudo apt install libcurl4-gnutls-dev ninja-build ${{matrix.compiler}} --no-install-recommends
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

steps:
- name: Checkout repository code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Docker build
working-directory: ${{github.workspace}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: maxim-lobanov/setup-xcode@v1
with:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/ubuntu-clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ jobs:

steps:
- name: Checkout repository code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt update && sudo apt install libcurl4-gnutls-dev ninja-build
sudo apt update
sudo apt install libcurl4-gnutls-dev ninja-build
- name: Install clang (with clang-tidy)
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu-monitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

steps:
- name: Checkout repository code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Prerequisites
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

steps:
- name: Checkout repository code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install dependencies
run: |
Expand Down
23 changes: 9 additions & 14 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,27 @@ on:
pull_request:

jobs:
windows-build:
windows:
name: Build on Windows
runs-on: windows-latest
strategy:
matrix:
buildmode: [Debug, Release]
buildmode: [Debug]
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install dependencies
uses: crazy-max/ghaction-chocolatey@v1
with:
args: install curl openssl

- name: Add cURL directory in the path
run: |
$curlPath = Get-ChildItem -Path C:\ProgramData\chocolatey\lib\curl\tools\curl* -Name
echo "C:\ProgramData\chocolatey\lib\curl\tools\${curlPath}\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "C:\ProgramData\chocolatey\lib\curl\tools\${curlPath}\lib" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
vcpkg install openssl curl
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build
- name: End vcpkg install
run: |
vcpkg integrate install
- name: Configure CMake
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=${{matrix.buildmode}}
run: |
cmake -DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake" -DCMAKE_BUILD_TYPE=${{matrix.buildmode}} -S . -B build
- name: Build
working-directory: ${{github.workspace}}/build
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
*.creator*
*.files
*.includes
*.cmake
*.code-workspace
*.orig
*.tmp
Expand Down Expand Up @@ -59,13 +58,12 @@
#==============================================================================#

!.vscode/*.default
.ycm_extra_conf.py*
*-ut
cscope*
**/*secret.json
data/cache
data/log
data/secret
!data/secret/secret_test.json
data/static/exchangeconfig.json
data/static/generalconfig.json
monitoring/data/grafana/*
115 changes: 22 additions & 93 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,16 @@ endif()

set(CMAKE_CXX_STANDARD 20)

# openssl for requests
find_package(OpenSSL REQUIRED)

# curl - request library
find_package(CURL REQUIRED)

# External dependencies (linked with FetchContent)
include(FetchContent)

find_package(amc CONFIG)

if(amc_FOUND)
set(LINK_AMC FALSE)
else()
Expand Down Expand Up @@ -83,7 +88,7 @@ if(CCT_ENABLE_TESTS)
enable_testing()
endif()

# nlohmann_json - coincenter json library
# nlohmann_json - json library
find_package(nlohmann_json CONFIG)
if(NOT nlohmann_json_FOUND)
FetchContent_Declare(
Expand All @@ -95,18 +100,7 @@ if(NOT nlohmann_json_FOUND)
FetchContent_MakeAvailable(nlohmann_json)
endif()

# spdlog - coincenter logging library
find_package(spdlog CONFIG)
if(NOT spdlog_FOUND)
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.13.0
)

FetchContent_MakeAvailable(spdlog)
endif()

# prometheus for monitoring support
if(CCT_BUILD_PROMETHEUS_FROM_SRC)
# Disable Prometheus testing
set(ENABLE_TESTING OFF)
Expand Down Expand Up @@ -135,92 +129,27 @@ else()
endif()
endif()

# Unit Tests

#[[ Create an executable
Syntax:
add_exe(<name> src1 [src2 ...] [LIBRARIES lib1 lib2 ...] [DEFINITIONS def1 def2])
will compile an executable named <name> from source files src1 src2...
with pre-processor definitions def1 def2 (-Ddef1 -Ddef2 ... will be added to compile command)
and link against lib1 lib2 ...and libm

Examples:
add_exe(myexe src1.cpp)
add_exe(myexe src1.cpp
LIBRARIES ${CMAKE_SOURCE_DIR}/myLib
DEFINITIONS UNIT_TEST)
#]]
function(add_exe name)
set(cur_var "sources")
set(exe_sources "")
set(exe_libraries "")
set(exe_definitions "")
set(exe_include_dirs "")

foreach(arg IN LISTS ARGN)
if(arg STREQUAL "LIBRARIES")
set(cur_var "libraries")
elseif(arg STREQUAL "DEFINITIONS")
set(cur_var "definitions")
else()
list(APPEND exe_${cur_var} ${arg})

if(cur_var STREQUAL "sources")
get_filename_component(src_dir ${arg} DIRECTORY)
list(APPEND exe_include_dirs ${src_dir})
endif()
endif()
endforeach()

add_executable(${name} ${exe_sources})
set_target_properties(${name} PROPERTIES
COMPILE_DEFINITIONS "${exe_definitions}"
BUILD_RPATH "${runtime_path}")
target_link_libraries(${name} PRIVATE ${exe_libraries})
list(REMOVE_DUPLICATES exe_include_dirs)
target_include_directories(${name} PRIVATE ${exe_include_dirs} ${all_includes})
endfunction()

#[[ Create a unit test
Syntax:
add_unit_test(<name> src1 [src2 ...] [LIBRARIES lib1 lib2 ...] [DEFINITIONS def1 def2])
will compile an unit test named <name> from source files src1 src2...
with pre-processor definitions def1 def2 (-Ddef1 -Ddef2 ... will be added to compile command)
and link against lib1 lib2 ... and libm

Examples:
add_unit_test(myexe src1.cpp)
add_unit_test(myexe src1.cpp DEFINITIONS UNIT_TEST)
#]]
function(add_unit_test name)
set(oneValueArgs)
set(multiValueArgs)
cmake_parse_arguments(PARSE_ARGV 1 MY "${options}" "${oneValueArgs}" "${multiValueArgs}")

if(CCT_ENABLE_TESTS)
add_exe(${name} ${MY_UNPARSED_ARGUMENTS})
target_link_libraries(${name} PRIVATE GTest::gtest GTest::gmock GTest::gmock_main)

if(LINK_AMC)
target_link_libraries(${name} PRIVATE amc::amc)
endif()
# spdlog - logging library
find_package(spdlog CONFIG)
if(NOT spdlog_FOUND)
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.13.0
)

target_include_directories(${name} PRIVATE include)
target_include_directories(${name} PRIVATE ${CMAKE_SOURCE_DIR}/src/http-request/include)
FetchContent_MakeAvailable(spdlog)
endif()

add_test(NAME ${name} COMMAND ${name})
set_tests_properties(${name} PROPERTIES
ENVIRONMENT "UBSAN_OPTIONS=halt_on_error=1 abort_on_error=1 print_stacktrace=1;\
LSAN_OPTIONS=detect_leaks=1 malloc_context_size=2 print_suppressions=0"
WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY})
endif()
endfunction()
# Unit Tests
include(cmake/AddUnitTest.cmake)

if(MSVC)
add_compile_options(/W4)
add_compile_options(/W3)

# https://stackoverflow.com/questions/5004858/why-is-stdmin-failing-when-windows-h-is-included
add_compile_definitions(NOMINMAX)
add_compile_definitions(_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING)
else()
add_compile_options(-Wall -Wextra -pedantic)

Expand Down
23 changes: 16 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ FROM ubuntu:22.04 AS build
# Install base & build dependencies, needed certificates for curl to work with https
RUN apt update && \
apt upgrade -y && \
apt install build-essential curl libcurl4-gnutls-dev libssl-dev cmake git ca-certificates gzip -y && \
curl -L -o /usr/local/bin/ninja.gz https://github.com/ninja-build/ninja/releases/latest/download/ninja-linux.zip && \
gunzip /usr/local/bin/ninja.gz && \
chmod a+x /usr/local/bin/ninja
apt install build-essential ninja-build libcurl4-gnutls-dev libssl-dev cmake git ca-certificates gzip -y --no-install-recommends

# Copy source files
WORKDIR /app/src
COPY src .

# Set default directory for application
WORKDIR /app
COPY CMakeLists.txt *.md ./

WORKDIR /app/cmake
COPY cmake .

# Copy only the test secrets
WORKDIR /app/data/secret
COPY data/secret/secret_test.json .

# Copy all files, excluding the ones in '.dockerignore'
COPY . .
# Copy mandatory static configuration files
WORKDIR /app/data/static
COPY data/static/currency_prefix_translator.json data/static/currencyacronymtranslator.json data/static/stablecoins.json data/static/withdrawfees.json ./

# Create and go to 'bin' directory
WORKDIR /app/bin
Expand Down
Loading

0 comments on commit b65292a

Please sign in to comment.