diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 83bd4fd..9c6c6fd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,8 +20,6 @@ on: [push] jobs: build: runs-on: ubuntu-latest - env: - BUILD_WRAPPER_OUT_DIR: /srv/build strategy: fail-fast: false @@ -33,37 +31,11 @@ jobs: container: image: ghcr.io/anexperimentwithtime/compiler:${{ matrix.version }}-${{ matrix.type }}-${{ matrix.link }} - services: - mysql: - image: mysql:8.4 - env: - MYSQL_ALLOW_EMPTY_PASSWORD: false - MYSQL_ROOT_PASSWORD: state_password - MYSQL_USER: user - MYSQL_PASSWORD: state_password - MYSQL_DATABASE: state - ports: - - 3306:3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Prepares databases - env: - DB_HOST: mysql - DB_PORT: 3306 - run: | - bash scripts/prepare-database.sh - - name: Run build and test - env: - DB_HOST: mysql - DB_USER: user - DB_PASSWORD: state_password - DB_NAME: state - DB_PORT: 3306 run: | bash scripts/build-and-test.sh ${{ matrix.type }} ${{ matrix.link }} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c127c2..d20dc32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,33 +35,6 @@ if (ENABLE_STATIC_LINKING) set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_STATIC_RUNTIME ON) set(BOOST_ALL_NO_LIB ON) - set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries" FORCE) - set(ZLIB_USE_STATIC_LIBS ON) - set(OPENSSL_USE_STATIC_LIBS TRUE) - set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") - - if (ENABLE_CI) - set(OPENSSL_CRYPTO_LIBRARY "/usr/lib/libcrypto.a") - set(OPENSSL_SSL_LIBRARY "/usr/lib/libssl.a") - set(CURL_LIBRARY "/usr/lib/libcurl.a") - set(ZLIB_LIBRARY "/usr/lib/libz.a") - set(NGHTTP2_LIBRARY "/usr/lib/libnghttp2.a") - else () - if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") - set(ARCH_LIB_DIR "/usr/lib/aarch64-linux-gnu") - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") - set(ARCH_LIB_DIR "/usr/lib/x86_64-linux-gnu") - else() - message(FATAL_ERROR "Arquitectura no soportada: ${CMAKE_SYSTEM_PROCESSOR}") - endif() - set(OPENSSL_CRYPTO_LIBRARY "${ARCH_LIB_DIR}/libcrypto.a") - set(OPENSSL_SSL_LIBRARY "${ARCH_LIB_DIR}/libssl.a") - set(CURL_LIBRARY "${ARCH_LIB_DIR}/libcurl.a") - set(ZLIB_LIBRARY "${ARCH_LIB_DIR}/libz.a") - set(NGHTTP2_LIBRARY "${ARCH_LIB_DIR}/libnghttp2.a") - endif () - - set(OpenSSL_USE_STATIC_LIBS TRUE) if (ENABLE_NATIVE_OPTIMIZATION) set(CMAKE_CXX_FLAGS_RELEASE "-O3 -flto -march=native -mtune=native -g0 -static -static-libgcc") @@ -84,89 +57,38 @@ if (ENABLE_DEBUG) add_definitions(-DDEBUG_ENABLED) endif () - find_package(Boost REQUIRED COMPONENTS program_options json charconv) - -find_package( - Boost - REQUIRED - COMPONENTS - program_options - json -) - -find_package(OpenSSL REQUIRED) find_package(spdlog REQUIRED) find_package(fmt REQUIRED) -if (NOT ENABLE_STATIC_LINKING) - find_package(CURL REQUIRED) - find_package(sentry REQUIRED) - find_library(NGHTTP2_LIBRARY nghttp2 REQUIRED) -endif () - file(GLOB_RECURSE STATE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/objects/*.cpp") include_directories(src/include) add_library(objects OBJECT ${STATE_SOURCES}) -if (NOT ENABLE_STATIC_LINKING) - target_link_libraries(objects PRIVATE - ${Boost_LIBRARIES} - ${OPENSSL_SSL_LIBRARY} - ${OPENSSL_CRYPTO_LIBRARY} - spdlog::spdlog - sentry::sentry - fmt::fmt - ) -else () - target_link_libraries(objects PRIVATE - ${Boost_LIBRARIES} - ${OPENSSL_SSL_LIBRARY} - ${OPENSSL_CRYPTO_LIBRARY} - spdlog::spdlog - fmt::fmt - ) -endif () - -add_library(netdeps OBJECT - deps/asio.cxx - deps/beast.cxx -) - -target_link_libraries(netdeps PRIVATE +target_link_libraries(objects PRIVATE ${Boost_LIBRARIES} - ${OPENSSL_SSL_LIBRARY} - ${OPENSSL_CRYPTO_LIBRARY} + spdlog::spdlog + fmt::fmt ) +add_library(netdeps OBJECT deps/asio.cxx deps/beast.cxx) + +target_link_libraries(netdeps PRIVATE ${Boost_LIBRARIES}) + add_executable(state main.cpp) if (ENABLE_STATIC_LINKING) target_compile_options(state PRIVATE -static -static-libgcc -static-libstdc++) target_link_options(state PRIVATE -static -static-libgcc -static-libstdc++) endif() -if (NOT ENABLE_STATIC_LINKING) target_link_libraries(state PRIVATE objects netdeps ${Boost_LIBRARIES} - ${OPENSSL_SSL_LIBRARY} - ${OPENSSL_CRYPTO_LIBRARY} spdlog::spdlog - sentry::sentry fmt::fmt ) -else () - target_link_libraries(state PRIVATE objects - netdeps - ${Boost_LIBRARIES} - ${OPENSSL_SSL_LIBRARY} - ${OPENSSL_CRYPTO_LIBRARY} - spdlog::spdlog - fmt::fmt - ) -endif () if (ENABLE_TESTS) include(FetchContent) @@ -189,8 +111,6 @@ if (ENABLE_TESTS) netdeps GTest::gtest_main ${Boost_LIBRARIES} - ${OPENSSL_SSL_LIBRARY} - ${OPENSSL_CRYPTO_LIBRARY} spdlog::spdlog fmt::fmt ) diff --git a/main.cpp b/main.cpp index cd9c0e1..d997037 100644 --- a/main.cpp +++ b/main.cpp @@ -15,65 +15,21 @@ #include -#ifdef STATIC_ENABLED -#else -#include -#endif - #include #include #include #include #include -#include -#include -#include #include #include -#include #include #include #include #include - -std::string DEFAULT_SENTRY_DSN = - "https://{username}@{token}.ingest.{zone}.sentry.io/{app_id}"; -std::string DEFAULT_SENTRY_DEBUG = "OFF"; - -void sentry_start(const std::string &dsn, const bool debug) { -#ifdef STATIC_ENABLED - LOG_INFO("sentry start isn't available on static"); -#else - LOG_INFO("sentry starting"); - sentry_options_t *_options = sentry_options_new(); - sentry_options_set_dsn(_options, dsn.data()); - sentry_options_set_database_path(_options, ".sentry-native"); - - const std::string _release_name = - fmt::format("state@{}.{}.{}", aewt::version::get_major(), - aewt::version::get_minor(), aewt::version::get_patch()); - - sentry_options_set_release(_options, _release_name.data()); - sentry_options_set_debug(_options, debug); - sentry_init(_options); - LOG_INFO("sentry started"); -#endif -} - -void sentry_stop() { -#ifdef STATIC_ENABLED - LOG_INFO("sentry close isn't available on static"); -#else - LOG_INFO("sentry closing"); - sentry_close(); - LOG_INFO("sentry closed"); -#endif -} - int main(const int argc, const char *argv[]) { boost::program_options::options_description _options("Options"); auto _push_option = _options.add_options(); @@ -86,19 +42,10 @@ int main(const int argc, const char *argv[]) { _push_option("remote_address", boost::program_options::value()->default_value("localhost")); _push_option("remote_sessions_port", boost::program_options::value()->default_value(9000)); _push_option("remote_clients_port", boost::program_options::value()->default_value(10000)); - _push_option("sentry_enabled", boost::program_options::value()->default_value(false)); - _push_option("sentry_dsn", - boost::program_options::value()->default_value( - "https://{username}@{token}.ingest.{zone}.sentry.io/{app_id}")); - _push_option("sentry_debug", boost::program_options::value()->default_value(false)); boost::program_options::variables_map _vm; store(parse_command_line(argc, argv, _options), _vm); - if (_vm["sentry_enabled"].as()) { - sentry_start(_vm["sentry_dsn"].as(), _vm["sentry_debug"].as()); - } - const auto _server = std::make_shared(); _server->get_config()->address_ = _vm["address"].as(); @@ -122,15 +69,8 @@ int main(const int argc, const char *argv[]) { LOG_INFO("- remote_address: {}", _vm["remote_address"].as()); LOG_INFO("- remote_sessions_port: {}", _vm["remote_sessions_port"].as()); LOG_INFO("- remote_clients_port: {}", _vm["remote_clients_port"].as()); - LOG_INFO("- sentry_enabled: {}", _vm["sentry_enabled"].as()); - LOG_INFO("- sentry_debug: {}", _vm["sentry_debug"].as()); - LOG_INFO("- sentry_dsn: {}", _vm["sentry_dsn"].as()); _server->start(); - if (_vm["sentry_enabled"].as()) { - sentry_stop(); - } - return 0; } diff --git a/scripts/prepare-database.sh b/scripts/prepare-database.sh deleted file mode 100755 index df857f3..0000000 --- a/scripts/prepare-database.sh +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright (C) 2025 Ian Torres -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -#!/usr/bin/env bash -set -euo pipefail \ No newline at end of file diff --git a/src/objects/session_listener.cpp b/src/objects/session_listener.cpp index 96976ec..9d2ebbc 100644 --- a/src/objects/session_listener.cpp +++ b/src/objects/session_listener.cpp @@ -24,7 +24,8 @@ namespace aewt { session_listener::session_listener(boost::asio::io_context &ioc, const boost::asio::ip::tcp::endpoint &endpoint, - const std::shared_ptr &state) : ioc_(ioc), acceptor_(make_strand(ioc)), state_(state) { + const std::shared_ptr &state) : ioc_(ioc), acceptor_(make_strand(ioc)), + state_(state) { boost::beast::error_code ec; acceptor_.open(endpoint.protocol(), ec); @@ -52,7 +53,8 @@ namespace aewt { } state_->get_config()->sessions_port_.store(acceptor_.local_endpoint().port(), std::memory_order_release); - LOG_INFO("state_id=[{}] sessions is listening on [{}]", to_string(state_->get_id()), state_->get_config()->sessions_port_.load(std::memory_order_acquire)); + LOG_INFO("state_id=[{}] sessions is listening on [{}]", to_string(state_->get_id()), + state_->get_config()->sessions_port_.load(std::memory_order_acquire)); } void session_listener::on_accept(const boost::beast::error_code &ec, boost::asio::ip::tcp::socket socket) {