Skip to content

Commit

Permalink
update: gha build (opentibiabr#2641)
Browse files Browse the repository at this point in the history
  • Loading branch information
beats-dh authored Oct 13, 2024
1 parent c4786c4 commit ff26833
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 27 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,37 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
os: [ubuntu-22.04, ubuntu-24.04]
buildtype: [linux-release, linux-debug]
include:
- os: ubuntu-22.04
triplet: x64-linux
- os: ubuntu-24.04
triplet: x64-linux

steps:
- name: Checkout repository
uses: actions/checkout@main

- name: Install Linux Dependencies
run: >
sudo apt-get update && sudo apt-get install ccache linux-headers-$(uname -r)
sudo apt-get update && sudo apt-get install ccache linux-headers-"$(uname -r)"
- name: Switch to gcc-12 on Ubuntu 22.04
if: matrix.os == 'ubuntu-22.04'
run: |
sudo apt install gcc-12 g++-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100 --slave /usr/bin/g++ g++ /usr/bin/g++-12 --slave /usr/bin/gcov gcov /usr/bin/gcov-12
sudo update-alternatives --set gcc /usr/bin/gcc-12
- name: Switch to gcc-11
if: matrix.os == 'ubuntu-20.04'
- name: Switch to gcc-14 on Ubuntu 24.04
if: matrix.os == 'ubuntu-24.04'
run: |
sudo apt install gcc-11 g++-11
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11
sudo update-alternatives --set gcc /usr/bin/gcc-11
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt-get update
sudo apt-get install gcc-14 g++-14 -y
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 100 --slave /usr/bin/g++ g++ /usr/bin/g++-14 --slave /usr/bin/gcov gcov /usr/bin/gcov-14
sudo update-alternatives --set gcc /usr/bin/gcc-14
- name: CCache
uses: hendrikmuhs/ccache-action@main
Expand All @@ -70,7 +81,7 @@ jobs:
run: |
vcpkgCommitId=$(grep '.builtin-baseline' vcpkg.json | awk -F: '{print $2}' | tr -d '," ')
echo "vcpkg commit ID: $vcpkgCommitId"
echo "VCPKG_GIT_COMMIT_ID=$vcpkgCommitId" >> $GITHUB_ENV
echo "VCPKG_GIT_COMMIT_ID=$vcpkgCommitId" >> "$GITHUB_ENV"
- name: Get vcpkg commit id from vcpkg.json
uses: lukka/run-vcpkg@main
Expand Down
30 changes: 26 additions & 4 deletions cmake/modules/BaseConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,43 @@ endif()
# === IPO Configuration ===
function(configure_linking target_name)
if(OPTIONS_ENABLE_IPO)
# Check if IPO/LTO is supported
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_output LANGUAGES CXX)

# Get the GCC compiler version, if applicable
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
OUTPUT_VARIABLE GCC_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()

if(ipo_supported)
set_property(TARGET ${target_name} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
message(STATUS "IPO/LTO enabled for target ${target_name}.")
log_option_enabled("IPO/LTO enabled for target ${target_name}.")

if(MSVC)
target_compile_options(${target_name} PRIVATE /GL)
target_link_options(${target_name} PRIVATE /LTCG)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(${target_name} PRIVATE -flto)
target_link_options(${target_name} PRIVATE -flto)
# Check if it's running on Linux, using GCC 14, and in Debug mode
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
GCC_VERSION VERSION_EQUAL "14" AND
CMAKE_BUILD_TYPE STREQUAL "Debug")
log_option_disabled("LTO disabled for GCC 14 in Debug mode on Linux for target ${target_name}.")
# Disable LTO for Debug builds with GCC 14
target_compile_options(${target_name} PRIVATE -fno-lto)
target_link_options(${target_name} PRIVATE -fno-lto)
else()
target_compile_options(${target_name} PRIVATE -flto=auto)
target_link_options(${target_name} PRIVATE -flto=auto)
endif()
endif()
else()
message(WARNING "IPO/LTO is not supported for target ${target_name}: ${ipo_output}")
log_option_disabled("IPO/LTO is not supported for target ${target_name}: ${ipo_output}")
endif()
endif()
endfunction()
Expand Down
3 changes: 1 addition & 2 deletions cmake/modules/CanaryLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ configure_linking(${PROJECT_NAME}_lib)
# === UNITY BUILD (compile time reducer) ===
if(SPEED_UP_BUILD_UNITY)
set_target_properties(${PROJECT_NAME}_lib PROPERTIES UNITY_BUILD ON)
log_option_enabled("Build unity for speed up compilation")
log_option_enabled("Build unity for speed up compilation for taget ${PROJECT_NAME}_lib")
else()
log_option_disabled("Build unity")
endif()
Expand Down Expand Up @@ -84,7 +84,6 @@ target_link_libraries(${PROJECT_NAME}_lib
spdlog::spdlog
unofficial::argon2::libargon2
unofficial::libmariadb
unofficial::mariadbclient
protobuf
)

Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/FindMySQL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ IF (WIN32)
ADD_DEFINITIONS(-DDBUG_OFF)
ENDIF (CMAKE_BUILD_TYPE STREQUAL Debug)

FIND_LIBRARY(MYSQL_LIB NAMES mysqlclient libmariadb
FIND_LIBRARY(MYSQL_LIB NAMES mariadbclient libmariadb
PATHS
$ENV{MYSQL_DIR}/lib/${libsuffixDist}
$ENV{MYSQL_DIR}/libmysql
Expand Down
15 changes: 14 additions & 1 deletion src/lua/functions/core/game/lua_enums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "enums/account_type.hpp"
#include "enums/account_group_type.hpp"

constexpr const char* soundNamespace = "SOUND_EFFECT_TYPE_";

#define registerMagicEnum(luaState, enumClassType) \
{ \
auto number = magic_enum::enum_integer(enumClassType); \
Expand Down Expand Up @@ -107,6 +109,9 @@ void LuaEnums::init(lua_State* L) {
initWebhookEnums(L);
initBosstiaryEnums(L);
initSoundEnums(L);
spelltSoundEnums(L);
monsterSoundEnums(L);
effectsSoundEnums(L);
initWheelEnums(L);
initAttributeConditionSubIdEnums(L);
initConcoctionsEnum(L);
Expand Down Expand Up @@ -1242,7 +1247,6 @@ void LuaEnums::initBosstiaryEnums(lua_State* L) {

// "SOUND_EFFECT_TYPE_" is the sound lua namespace
void LuaEnums::initSoundEnums(lua_State* L) {
std::string soundNamespace = "SOUND_EFFECT_TYPE_";
registerEnumNamespace(L, soundNamespace, SoundEffect_t::SILENCE);
registerEnumNamespace(L, soundNamespace, SoundEffect_t::HUMAN_CLOSE_ATK_FIST);
registerEnumNamespace(L, soundNamespace, SoundEffect_t::MONSTER_CLOSE_ATK_FIST);
Expand Down Expand Up @@ -1272,6 +1276,9 @@ void LuaEnums::initSoundEnums(lua_State* L) {
registerEnumNamespace(L, soundNamespace, SoundEffect_t::MONSTER_MELEE_ATK_MAGIC);
registerEnumNamespace(L, soundNamespace, SoundEffect_t::MONSTER_MELEE_ATK_ETHEREAL);
registerEnumNamespace(L, soundNamespace, SoundEffect_t::MONSTER_MELEE_ATK_CONSTRUCT);
}

void LuaEnums::spelltSoundEnums(lua_State* L) {
registerEnumNamespace(L, soundNamespace, SoundEffect_t::SPELL_LIGHT_HEALING);
registerEnumNamespace(L, soundNamespace, SoundEffect_t::SPELL_INTENSE_HEALING);
registerEnumNamespace(L, soundNamespace, SoundEffect_t::SPELL_ULTIMATE_HEALING);
Expand Down Expand Up @@ -1423,6 +1430,9 @@ void LuaEnums::initSoundEnums(lua_State* L) {
registerEnumNamespace(L, soundNamespace, SoundEffect_t::SPELL_EXPOSE_WEAKNESS);
registerEnumNamespace(L, soundNamespace, SoundEffect_t::SPELL_SAP_STRENGTH);
registerEnumNamespace(L, soundNamespace, SoundEffect_t::SPELL_CANCEL_MAGIC_SHIELD);
}

void LuaEnums::monsterSoundEnums(lua_State* L) {
registerEnumNamespace(L, soundNamespace, SoundEffect_t::MONSTER_SPELL_SINGLE_TARGET_FIRE);
registerEnumNamespace(L, soundNamespace, SoundEffect_t::MONSTER_SPELL_SINGLE_TARGET_ENERGY);
registerEnumNamespace(L, soundNamespace, SoundEffect_t::MONSTER_SPELL_SINGLE_TARGET_EARTH);
Expand Down Expand Up @@ -1487,6 +1497,9 @@ void LuaEnums::initSoundEnums(lua_State* L) {
registerEnumNamespace(L, soundNamespace, SoundEffect_t::MONSTER_SPELL_HIGHRISK_TELEPORT);
registerEnumNamespace(L, soundNamespace, SoundEffect_t::MONSTER_SPELL_MINION);
registerEnumNamespace(L, soundNamespace, SoundEffect_t::MONSTER_SPELL_AGONY);
}

void LuaEnums::effectsSoundEnums(lua_State* L) {
registerEnumNamespace(L, soundNamespace, SoundEffect_t::AMPHIBIC_BARK);
registerEnumNamespace(L, soundNamespace, SoundEffect_t::AQUATIC_BEAST_BARK);
registerEnumNamespace(L, soundNamespace, SoundEffect_t::AQUATIC_CRITTER_BARK);
Expand Down
3 changes: 3 additions & 0 deletions src/lua/functions/core/game/lua_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,8 @@ class LuaEnums final : LuaScriptInterface {
static void initWebhookEnums(lua_State* L);
static void initBosstiaryEnums(lua_State* L);
static void initSoundEnums(lua_State* L);
static void spelltSoundEnums(lua_State* L);
static void monsterSoundEnums(lua_State* L);
static void effectsSoundEnums(lua_State* L);
static void initWheelEnums(lua_State* L);
};
19 changes: 19 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,26 @@

#include "canary_server.hpp"
#include "lib/di/container.hpp"
// Define um conceito para garantir que a função só aceite contêineres de números
template <typename T>
concept NumberContainer = requires(T a) {
typename T::value_type;
requires std::integral<typename T::value_type> || std::floating_point<typename T::value_type>;
};

// Função que calcula a média de um contêiner de números
auto calculateAverage(const NumberContainer auto &container) {
// Utiliza ranges e std::views para processar o contêiner
return std::accumulate(container.begin(), container.end(), 0.0) / std::ranges::distance(container);
}

int main() {
std::vector<int> numbers = { 1, 2, 3, 4, 5 };

// Calcula a média usando a função com suporte a C++23
double average = calculateAverage(numbers);

std::cout << "Average: " << average << std::endl;

return inject<CanaryServer>().run();
}
7 changes: 4 additions & 3 deletions src/pch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@
#include <fmt/core.h>
#include <fmt/format.h>
#include <fmt/args.h>
#include <fmt/ranges.h>

// FMT Custom Formatter for Enums
template <typename E>
struct fmt::formatter<E, std::enable_if_t<std::is_enum_v<E>, char>> : formatter<std::underlying_type_t<E>> {
struct fmt::formatter<E, std::enable_if_t<std::is_enum_v<E>, char>> : fmt::formatter<std::underlying_type_t<E>> {
template <typename FormatContext>
auto format(E e, FormatContext &ctx) {
return formatter<std::underlying_type_t<E>>::format(
auto format(E e, FormatContext &ctx) const {
return fmt::formatter<std::underlying_type_t<E>>::format(
static_cast<std::underlying_type_t<E>>(e), ctx
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function(setup_test TARGET_NAME DIR)

if(SPEED_UP_BUILD_UNITY AND (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR CMAKE_BUILD_TYPE STREQUAL "Release"))
set_target_properties(${TARGET_NAME} PROPERTIES UNITY_BUILD ON)
log_option_enabled("Build unity for speed up compilation")
log_option_enabled("Build unity for speed up compilation for target ${TARGET_NAME}")
else()
log_option_disabled("Build unity")
endif()
Expand Down
9 changes: 2 additions & 7 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"bext-ut",
"curl",
"eventpp",
"libmariadb",
"luajit",
"magic-enum",
"mio",
Expand All @@ -23,12 +24,6 @@
"default-features": true,
"features": ["otlp-http", "prometheus"]
},
{
"name": "libmariadb",
"features": [
"mariadbclient"
]
},
{
"name": "gmp",
"platform": "linux"
Expand All @@ -38,5 +33,5 @@
"platform": "windows"
}
],
"builtin-baseline": "095ee06e7f60dceef7d713e3f8b1c2eb10d650d7"
"builtin-baseline": "9558037875497b9db8cf38fcd7db68ec661bffe7"
}

0 comments on commit ff26833

Please sign in to comment.