From 8e8a5a03c5d98c175ad3d601d53b349079a90a96 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 15 Feb 2026 10:48:23 +0000 Subject: [PATCH 01/33] Fix CI gitea workflow --- .gitea/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 59e19c8..2923576 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Bigfoot +name: Bin2CPP on: push: From 1f61574360bf47559012e75c330874f378acb3bc Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 15 Feb 2026 10:48:55 +0000 Subject: [PATCH 02/33] Fix CI gitea workflow #2 --- .gitea/workflows/sonarqube.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/sonarqube.yml b/.gitea/workflows/sonarqube.yml index 9cdec62..2d8b34e 100644 --- a/.gitea/workflows/sonarqube.yml +++ b/.gitea/workflows/sonarqube.yml @@ -1,4 +1,4 @@ -name: Bigfoot +name: Bin2CPP on: push: From 529f053e60fba8d4dde4ca9aa8df18d269a6f839 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 15 Feb 2026 16:03:43 +0100 Subject: [PATCH 03/33] File layout --- Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt | 11 ++- .../Bin2CPPLib/GeneratedTemplate.hpp.in | 20 ++++ .../Bin2CPPLib/{touch.cpp => Generator.cpp} | 0 .../Bin2CPPLib/Include/Bin2CPPLib/Assert.hpp} | 0 .../Include/Bin2CPPLib/Generator.hpp | 0 .../Bin2CPPLib/Include/Bin2CPPLib/Log.hpp | 0 Bin2CPP/Sources/Bin2CPPLib/Log.cpp | 0 Bin2CPP/Sources/Bin2CPPLib/MimallocImpl.cpp | 96 +++++++++++++++++++ Bin2CPP/Tests/Bin2CPPLib/Assert.cpp | 0 Bin2CPP/Tests/Bin2CPPLib/Fixture/toto.txt | 1 + Bin2CPP/Tests/Bin2CPPLib/Generator.cpp | 0 Bin2CPP/Tests/Bin2CPPLib/Log.cpp | 0 CMakeLists.txt | 4 + 13 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in rename Bin2CPP/Sources/Bin2CPPLib/{touch.cpp => Generator.cpp} (100%) rename Bin2CPP/{Tests/Bin2CPPLib/touch.cpp => Sources/Bin2CPPLib/Include/Bin2CPPLib/Assert.hpp} (100%) create mode 100644 Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Generator.hpp create mode 100644 Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Log.hpp create mode 100644 Bin2CPP/Sources/Bin2CPPLib/Log.cpp create mode 100644 Bin2CPP/Sources/Bin2CPPLib/MimallocImpl.cpp create mode 100644 Bin2CPP/Tests/Bin2CPPLib/Assert.cpp create mode 100644 Bin2CPP/Tests/Bin2CPPLib/Generator.cpp create mode 100644 Bin2CPP/Tests/Bin2CPPLib/Log.cpp diff --git a/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt b/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt index 7235b2a..c5f1e6c 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt +++ b/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt @@ -12,6 +12,7 @@ file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp.in ) target_sources(${PROJECT_NAME} @@ -19,10 +20,18 @@ target_sources(${PROJECT_NAME} ${SOURCES} ) -target_link_libraries(${PROJECT_NAME} PUBLIC EASTL::EASTL rapidhash::rapidhash mimalloc) +target_link_libraries(${PROJECT_NAME} PUBLIC EASTL::EASTL mimalloc) target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_DL_LIBS}) target_link_libraries(${PROJECT_NAME} PRIVATE $<$:cpptrace::cpptrace> quill::quill) +target_compile_definitions(${PROJECT_NAME} + PUBLIC $<$:QUILL_NO_EXCEPTIONS> + PUBLIC $<$:QUILL_DISABLE_NON_PREFIXED_MACROS> + + PUBLIC MI_SHARED_LIB) + +set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/MimallocImpl.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) + source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX Src FILES ${SOURCES}) set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Bin2CPP/${ParentFolder}) \ No newline at end of file diff --git a/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in b/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in new file mode 100644 index 0000000..0a7caac --- /dev/null +++ b/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in @@ -0,0 +1,20 @@ +#ifndef {{GUARD_NAME}} +#define {{GUARD_NAME}} +/** + * Auto-generated header from: {{FILENAME}} + * Generated by Bin2CPP + * + * DO NOT TOUCH + */ +#include {{ARRAY_TYPE_INCLUDE}} +#include + +namespace {{NAMESPACE}} { + +constexpr {{ARRAY_TYPE}} {{ARRAY_NAME}} = { +{{DATA}} +}; + +} // namespace {{NAMESPACE}} + +#endif // {{GUARD_NAME}} \ No newline at end of file diff --git a/Bin2CPP/Sources/Bin2CPPLib/touch.cpp b/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp similarity index 100% rename from Bin2CPP/Sources/Bin2CPPLib/touch.cpp rename to Bin2CPP/Sources/Bin2CPPLib/Generator.cpp diff --git a/Bin2CPP/Tests/Bin2CPPLib/touch.cpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Assert.hpp similarity index 100% rename from Bin2CPP/Tests/Bin2CPPLib/touch.cpp rename to Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Assert.hpp diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Generator.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Generator.hpp new file mode 100644 index 0000000..e69de29 diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Log.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Log.hpp new file mode 100644 index 0000000..e69de29 diff --git a/Bin2CPP/Sources/Bin2CPPLib/Log.cpp b/Bin2CPP/Sources/Bin2CPPLib/Log.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Bin2CPP/Sources/Bin2CPPLib/MimallocImpl.cpp b/Bin2CPP/Sources/Bin2CPPLib/MimallocImpl.cpp new file mode 100644 index 0000000..bdb5e6a --- /dev/null +++ b/Bin2CPP/Sources/Bin2CPPLib/MimallocImpl.cpp @@ -0,0 +1,96 @@ +/********************************************************************* + * \file MimallocImpl.cpp + * + * \author Romain BOULLARD + * \date February 2026 + *********************************************************************/ +#if defined BIN2CPP_WINDOWS +#pragma comment(linker, "/include:mi_version") +#pragma warning(disable: 4100 4559) +#elif defined BIN2CPP_LINUX +#if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#else +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" +#endif +#endif + +// Taken from mimalloc-new-delete.h + +// clang-format off + +// ---------------------------------------------------------------------------- +// This header provides convenient overrides for the new and +// delete operations in C++. +// +// This header should be included in only one source file! +// +// On Windows, or when linking dynamically with mimalloc, these +// can be more performant than the standard new-delete operations. +// See +// --------------------------------------------------------------------------- +#if defined(__cplusplus) + #include + #include + + #if defined(_MSC_VER) && defined(_Ret_notnull_) && defined(_Post_writable_byte_size_) + // stay consistent with VCRT definitions + #define mi_decl_new(n) mi_decl_nodiscard mi_decl_restrict _Ret_notnull_ _Post_writable_byte_size_(n) + #define mi_decl_new_nothrow(n) mi_decl_nodiscard mi_decl_restrict _Ret_maybenull_ _Success_(return != NULL) _Post_writable_byte_size_(n) + #else + #define mi_decl_new(n) mi_decl_nodiscard mi_decl_restrict + #define mi_decl_new_nothrow(n) mi_decl_nodiscard mi_decl_restrict + #endif + + void operator delete(void* p) noexcept { mi_free(p); }; + void operator delete[](void* p) noexcept { mi_free(p); }; + + void operator delete (void* p, const std::nothrow_t&) noexcept { mi_free(p); } + void operator delete[](void* p, const std::nothrow_t&) noexcept { mi_free(p); } + + mi_decl_new(n) void* operator new(std::size_t n) noexcept(false) { return mi_new(n); } + mi_decl_new(n) void* operator new[](std::size_t n) noexcept(false) { return mi_new(n); } + + mi_decl_new_nothrow(n) void* operator new (std::size_t n, const std::nothrow_t& tag) noexcept { (void)(tag); return mi_new_nothrow(n); } + mi_decl_new_nothrow(n) void* operator new[](std::size_t n, const std::nothrow_t& tag) noexcept { (void)(tag); return mi_new_nothrow(n); } + + // Not from mimalloc-new-delete.h, but necessary for EASTL + void* operator new[](size_t size, const char* name, int flags, unsigned debugFlags, const char* file, int line) noexcept(false) { return mi_new(size); } + + #if (__cplusplus >= 201402L || _MSC_VER >= 1916) + void operator delete (void* p, std::size_t n) noexcept { mi_free_size(p,n); }; + void operator delete[](void* p, std::size_t n) noexcept { mi_free_size(p,n); }; + #endif + + #if (__cplusplus > 201402L || defined(__cpp_aligned_new)) + void operator delete (void* p, std::align_val_t al) noexcept { mi_free_aligned(p, static_cast(al)); } + void operator delete[](void* p, std::align_val_t al) noexcept { mi_free_aligned(p, static_cast(al)); } + void operator delete (void* p, std::size_t n, std::align_val_t al) noexcept { mi_free_size_aligned(p, n, static_cast(al)); }; + void operator delete[](void* p, std::size_t n, std::align_val_t al) noexcept { mi_free_size_aligned(p, n, static_cast(al)); }; + void operator delete (void* p, std::align_val_t al, const std::nothrow_t&) noexcept { mi_free_aligned(p, static_cast(al)); } + void operator delete[](void* p, std::align_val_t al, const std::nothrow_t&) noexcept { mi_free_aligned(p, static_cast(al)); } + + void* operator new (std::size_t n, std::align_val_t al) noexcept(false) { return mi_new_aligned(n, static_cast(al)); } + void* operator new[](std::size_t n, std::align_val_t al) noexcept(false) { return mi_new_aligned(n, static_cast(al)); } + void* operator new (std::size_t n, std::align_val_t al, const std::nothrow_t&) noexcept { return mi_new_aligned_nothrow(n, static_cast(al)); } + void* operator new[](std::size_t n, std::align_val_t al, const std::nothrow_t&) noexcept { return mi_new_aligned_nothrow(n, static_cast(al)); } + + // Not from mimalloc-new-delete.h, but necessary for EASTL + void* operator new[](size_t size, size_t alignment, size_t alignmentOffset, const char* pName, int flags, unsigned debugFlags, const char* file, int line) noexcept(false) { return mi_new_aligned(size, alignment); } + #endif + +#endif + +// clang-format on + +#if defined BIN2CPP_WINDOWS +#pragma warning(default: 4100 4559) +#elif defined BIN2CPP_LINUX +#if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) +#pragma GCC diagnostic pop +#else +#pragma clang diagnostic pop +#endif +#endif diff --git a/Bin2CPP/Tests/Bin2CPPLib/Assert.cpp b/Bin2CPP/Tests/Bin2CPPLib/Assert.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Bin2CPP/Tests/Bin2CPPLib/Fixture/toto.txt b/Bin2CPP/Tests/Bin2CPPLib/Fixture/toto.txt index e69de29..5e1c309 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/Fixture/toto.txt +++ b/Bin2CPP/Tests/Bin2CPPLib/Fixture/toto.txt @@ -0,0 +1 @@ +Hello World \ No newline at end of file diff --git a/Bin2CPP/Tests/Bin2CPPLib/Generator.cpp b/Bin2CPP/Tests/Bin2CPPLib/Generator.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Bin2CPP/Tests/Bin2CPPLib/Log.cpp b/Bin2CPP/Tests/Bin2CPPLib/Log.cpp new file mode 100644 index 0000000..e69de29 diff --git a/CMakeLists.txt b/CMakeLists.txt index b1e9505..e30b8e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,10 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_OPTIMIZE_DEPENDENCIES 1) add_compile_definitions( + $<$:BIN2CPP_OPTIMIZED> + $<$:BIN2CPP_NOT_OPTIMIZED> + $<$:BIN2CPP_WINDOWS> + $<$:BIN2CPP_LINUX> $<$:NOMINMAX> $<$:WIN32_LEAN_AND_MEAN>) From 23a3b4b90425d4a64e8a356c88974ed3b45a8d06 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 15 Feb 2026 16:09:35 +0100 Subject: [PATCH 04/33] remove rapidhash --- CMake/FindDependencies.cmake | 1 - conanfile.py | 1 - 2 files changed, 2 deletions(-) diff --git a/CMake/FindDependencies.cmake b/CMake/FindDependencies.cmake index 3c42c1c..4de3717 100644 --- a/CMake/FindDependencies.cmake +++ b/CMake/FindDependencies.cmake @@ -8,7 +8,6 @@ endif() find_package(EASTL REQUIRED) find_package(mimalloc REQUIRED) find_package(CLI11 REQUIRED) -find_package(rapidhash REQUIRED) find_package(quill REQUIRED) if(${IS_MULTI_CONFIG}) diff --git a/conanfile.py b/conanfile.py index 21e306c..7b7cc29 100644 --- a/conanfile.py +++ b/conanfile.py @@ -45,7 +45,6 @@ class Bigfoot(ConanFile): self.requires("eastl/3.27.01@bigfootdev/main", transitive_headers=True) self.requires("mimalloc/3.2.8@bigfootdev/main", transitive_headers=True) self.requires("cli11/2.6.1@bigfootdev/main") - self.requires("rapidhash/3.0@bigfootdev/main", transitive_headers=True) if(self.settings.build_type == "RelWithDebInfo" or self.settings.build_type == "Debug"): self.requires("cpptrace/1.0.4", transitive_headers=True) From 9f32d230d50f44b33441cf31e19c246dae98e0df Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Thu, 19 Feb 2026 17:54:54 +0100 Subject: [PATCH 05/33] ODR --- Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in b/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in index 0a7caac..3d8d9e1 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in +++ b/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in @@ -11,7 +11,7 @@ namespace {{NAMESPACE}} { -constexpr {{ARRAY_TYPE}} {{ARRAY_NAME}} = { +inline constexpr {{ARRAY_TYPE}} {{ARRAY_NAME}} = { {{DATA}} }; From 8fe1281cb72c728414db449f581646faa8927ed3 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Mon, 16 Feb 2026 20:58:47 +0100 Subject: [PATCH 06/33] Utilities --- Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt | 8 +- .../Bin2CPPLib/GeneratedTemplate.hpp.in | 4 +- Bin2CPP/Sources/Bin2CPPLib/Include/Assert.hpp | 138 ++++++++++++++++++ .../Bin2CPPLib/Include/Bin2CPPLib/Assert.hpp | 0 .../Bin2CPPLib/Include/Bin2CPPLib/Log.hpp | 0 .../Bin2CPPLib/Include/EASTLFormatters.hpp | 87 +++++++++++ .../Include/{Bin2CPPLib => }/Generator.hpp | 0 Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp | 116 +++++++++++++++ .../Sources/Bin2CPPLib/Include/Singleton.hpp | 104 +++++++++++++ Bin2CPP/Sources/Bin2CPPLib/Log.cpp | 49 +++++++ Bin2CPP/Tests/Bin2CPPLib/Assert.cpp | 0 Bin2CPP/Tests/Bin2CPPLib/Log.cpp | 39 +++++ Bin2CPP/Tests/Bin2CPPLib/Singleton.cpp | 3 + format.sh | 0 generate_bin2cpp.sh | 0 generate_dependencies.sh | 0 16 files changed, 541 insertions(+), 7 deletions(-) create mode 100644 Bin2CPP/Sources/Bin2CPPLib/Include/Assert.hpp delete mode 100644 Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Assert.hpp delete mode 100644 Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Log.hpp create mode 100644 Bin2CPP/Sources/Bin2CPPLib/Include/EASTLFormatters.hpp rename Bin2CPP/Sources/Bin2CPPLib/Include/{Bin2CPPLib => }/Generator.hpp (100%) create mode 100644 Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp create mode 100644 Bin2CPP/Sources/Bin2CPPLib/Include/Singleton.hpp delete mode 100644 Bin2CPP/Tests/Bin2CPPLib/Assert.cpp create mode 100644 Bin2CPP/Tests/Bin2CPPLib/Singleton.cpp mode change 100644 => 100755 format.sh mode change 100644 => 100755 generate_bin2cpp.sh mode change 100644 => 100755 generate_dependencies.sh diff --git a/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt b/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt index c5f1e6c..5331509 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt +++ b/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt @@ -20,13 +20,11 @@ target_sources(${PROJECT_NAME} ${SOURCES} ) -target_link_libraries(${PROJECT_NAME} PUBLIC EASTL::EASTL mimalloc) -target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_DL_LIBS}) -target_link_libraries(${PROJECT_NAME} PRIVATE $<$:cpptrace::cpptrace> quill::quill) +target_link_libraries(${PROJECT_NAME} PUBLIC EASTL::EASTL mimalloc quill::quill $<$:cpptrace::cpptrace>) target_compile_definitions(${PROJECT_NAME} - PUBLIC $<$:QUILL_NO_EXCEPTIONS> - PUBLIC $<$:QUILL_DISABLE_NON_PREFIXED_MACROS> + PUBLIC QUILL_NO_EXCEPTIONS + PUBLIC QUILL_DISABLE_NON_PREFIXED_MACROS PUBLIC MI_SHARED_LIB) diff --git a/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in b/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in index 3d8d9e1..8c280d8 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in +++ b/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in @@ -1,11 +1,11 @@ -#ifndef {{GUARD_NAME}} -#define {{GUARD_NAME}} /** * Auto-generated header from: {{FILENAME}} * Generated by Bin2CPP * * DO NOT TOUCH */ +#ifndef {{GUARD_NAME}} +#define {{GUARD_NAME}} #include {{ARRAY_TYPE_INCLUDE}} #include diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Assert.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Assert.hpp new file mode 100644 index 0000000..2370756 --- /dev/null +++ b/Bin2CPP/Sources/Bin2CPPLib/Include/Assert.hpp @@ -0,0 +1,138 @@ +/********************************************************************* + * \file Assert.hpp + * + * \author Romain BOULLARD + * \date October 2025 + *********************************************************************/ +#ifndef BIGFOOT_SYSTEM_ASSERT_HPP +#define BIGFOOT_SYSTEM_ASSERT_HPP +#include + +#if defined BIN2CPP_NOT_OPTIMIZED + +#include + +#include +#include + +#if defined BIN2CPP_LINUX +#include +#endif + +namespace Bin2CPP +{ +class AssertHandler +{ + public: + AssertHandler() = delete; + + AssertHandler(const AssertHandler& p_handler) = delete; + AssertHandler(AssertHandler&& p_handler) = delete; + + ~AssertHandler() = delete; + + /** + * Handle an assertion. + * + * \param p_location Location of the assertion. + * \param p_stacktrace The stack trace + * \param p_format Format string for the assertion message. + * \param p_args Arguments for the format string. + */ + template + static void Handle(const std::source_location& p_location, + const std::string_view p_stacktrace, + std::format_string p_format, + ARGS&&... p_args) + { + BIN2CPP_LOG_FATAL("Assert: {} (File:{}, Line:{}, Function:{}\n{}", + std::format(p_format, std::forward(p_args)...), + p_location.file_name(), + p_location.line(), + p_location.function_name(), + p_stacktrace); + } + + AssertHandler& operator=(const AssertHandler& p_handler) = delete; + AssertHandler& operator=(AssertHandler&& p_handler) = delete; +}; +} // namespace Bin2CPP + +#if defined BIN2CPP_WINDOWS +#define BIN2CPP_BREAK \ + do \ + { \ + __debugbreak(); \ + } while (false) +#elif defined BIN2CPP_LINUX +#define BIN2CPP_BREAK \ + do \ + { \ + std::raise(SIGTRAP); \ + } while (false) +#endif + +#define BIN2CPP_ASSERT(p_assert, p_message, ...) \ + do \ + { \ + constexpr std::source_location location = std::source_location::current(); \ + if (!(p_assert)) [[unlikely]] \ + { \ + constexpr auto stacktrace = []() -> std::string \ + { \ + const cpptrace::stacktrace stacktrace = cpptrace::generate_trace(); \ + return stacktrace.to_string(); \ + }; \ + \ + Bin2CPP::AssertHandler::Handle(location, stacktrace(), p_message __VA_OPT__(, ) __VA_ARGS__); \ + BIN2CPP_BREAK; \ + } \ + } while (false) + +#define BIN2CPP_SOFT_ASSERT(p_assert, p_message, ...) \ + do \ + { \ + constexpr std::source_location location = std::source_location::current(); \ + if (!(p_assert)) [[unlikely]] \ + { \ + constexpr auto stacktrace = []() -> std::string \ + { \ + const cpptrace::stacktrace stacktrace = cpptrace::generate_trace(); \ + return stacktrace.to_string(); \ + }; \ + \ + Bin2CPP::AssertHandler::Handle(location, stacktrace(), p_message __VA_OPT__(, ) __VA_ARGS__); \ + BIN2CPP_BREAK; \ + } \ + } while (false) + +#define BIN2CPP_CRITICAL_ASSERT(p_assert, p_message, ...) \ + do \ + { \ + constexpr std::source_location location = std::source_location::current(); \ + if (!(p_assert)) [[unlikely]] \ + { \ + constexpr auto stacktrace = []() -> std::string \ + { \ + const cpptrace::stacktrace stacktrace = cpptrace::generate_trace(); \ + return stacktrace.to_string(); \ + }; \ + \ + Bin2CPP::AssertHandler::Handle(location, stacktrace(), p_message __VA_OPT__(, ) __VA_ARGS__); \ + if (Bin2CPP::Singleton::HasInstance()) \ + { \ + Bin2CPP::Singleton::Instance().Flush(); \ + } \ + BIN2CPP_BREAK; \ + std::abort(); \ + } \ + } while (false) + +#else +#define BIN2CPP_ASSERT(p_assert, p_message, ...) + +#define BIN2CPP_SOFT_ASSERT(p_assert, p_message, ...) + +#define BIN2CPP_CRITICAL_ASSERT(p_assert, p_message, ...) +#endif +#endif diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Assert.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Assert.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Log.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Log.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/EASTLFormatters.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/EASTLFormatters.hpp new file mode 100644 index 0000000..2fbd09d --- /dev/null +++ b/Bin2CPP/Sources/Bin2CPPLib/Include/EASTLFormatters.hpp @@ -0,0 +1,87 @@ +/********************************************************************* + * \file EASTLFormatters.hpp + * + * \author Romain BOULLARD + * \date February 2026 + *********************************************************************/ +#ifndef BIN2CPP_EASTLFORMATTERS_HPP +#define BIN2CPP_EASTLFORMATTERS_HPP +#include + +#include + +#include +#include + +// STRING + +template<> +struct std::formatter +{ + constexpr auto parse(std::format_parse_context& ctx) + { + return ctx.begin(); + } + + template + auto format(const eastl::string& p_string, FormatContext& ctx) const + { + return std::format_to(ctx.out(), "{}", p_string.c_str()); + } +}; + +template<> +struct fmtquill::formatter +{ + constexpr auto parse(format_parse_context& ctx) + { + return ctx.begin(); + } + + auto format(const eastl::string& p_string, format_context& ctx) const + { + return fmtquill::format_to(ctx.out(), "{}", p_string.c_str()); + } +}; + +template<> +struct quill::Codec: quill::DeferredFormatCodec +{ +}; + +// STRING_VIEW + +template<> +struct std::formatter +{ + constexpr auto parse(std::format_parse_context& ctx) + { + return ctx.begin(); + } + + template + auto format(const eastl::string_view& p_stringView, FormatContext& ctx) const + { + return std::format_to(ctx.out(), "{}", p_stringView.data()); + } +}; + +template<> +struct fmtquill::formatter +{ + constexpr auto parse(format_parse_context& ctx) + { + return ctx.begin(); + } + + auto format(const eastl::string_view& p_stringView, format_context& ctx) const + { + return fmtquill::format_to(ctx.out(), "{}", p_stringView.data()); + } +}; + +template<> +struct quill::Codec: quill::DeferredFormatCodec +{ +}; +#endif diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Generator.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Generator.hpp similarity index 100% rename from Bin2CPP/Sources/Bin2CPPLib/Include/Bin2CPPLib/Generator.hpp rename to Bin2CPP/Sources/Bin2CPPLib/Include/Generator.hpp diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp new file mode 100644 index 0000000..4e90d38 --- /dev/null +++ b/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp @@ -0,0 +1,116 @@ +/********************************************************************* + * \file Log.hpp + * + * \author Romain BOULLARD + * \date February 2026 + *********************************************************************/ +#ifndef BIN2CPP_LOG_HPP +#define BIN2CPP_LOG_HPP +#include +#include + +#include + +#ifdef BIGFOOT_WINDOWS +#pragma warning(disable: 4702) +#endif +#include +#include +#include +#include +#include +#if defined BIGFOOT_WINDOWS +#pragma warning(default: 4702) +#endif + +namespace Bin2CPP +{ +class Log +{ + public: + Log(); + + Log(const Log& p_logger) = delete; + Log(Log&& p_logger) = delete; + + /** + * Register a logger. + * + * \return The logger, nullptr if it does not exist + */ + [[nodiscard]] + quill::Logger* GetLogger(); + + /* + * Flush all the loggers + * + */ + void Flush(); + + ~Log(); + + Log& operator=(const Log& p_logger) = delete; + Log& operator=(Log&& p_logger) = delete; + + private: + /* + * The sinks + */ + eastl::array, 1> m_sinks; +}; +} // namespace Bin2CPP + +#define BIN2CPP_LOG_DEBUG(fmt, ...) \ + do \ + { \ + if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + { \ + QUILL_LOG_DEBUG(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + } while (0) + +#define BIN2CPP_LOG_TRACE(fmt, ...) \ + do \ + { \ + if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + { \ + QUILL_LOG_TRACE_L3(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + } while (0) + +#define BIN2CPP_LOG_INFO(fmt, ...) \ + do \ + { \ + if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + { \ + QUILL_LOG_INFO(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + } while (0) + +#define BIN2CPP_LOG_WARN(fmt, ...) \ + do \ + { \ + if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + { \ + QUILL_LOG_WARNING(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + } while (0) + +#define BIN2CPP_LOG_ERROR(fmt, ...) \ + do \ + { \ + if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + { \ + QUILL_LOG_ERROR(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + } while (0) + +#define BIN2CPP_LOG_FATAL(fmt, ...) \ + do \ + { \ + if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + { \ + QUILL_LOG_CRITICAL(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ + } while (0) +#endif diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Singleton.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Singleton.hpp new file mode 100644 index 0000000..3fc8f3b --- /dev/null +++ b/Bin2CPP/Sources/Bin2CPPLib/Include/Singleton.hpp @@ -0,0 +1,104 @@ +/********************************************************************* + * \file Singleton.hpp + * + * \author Romain BOULLARD + * \date February 2026 + *********************************************************************/ +#ifndef BIN2CPP_SINGLETON_HPP +#define BIN2CPP_SINGLETON_HPP +#include + +namespace Bin2CPP +{ +template +class Singleton +{ + public: + Singleton() = delete; + + Singleton(const Singleton& p_singleton) = delete; + Singleton(Singleton&& p_singleton) = delete; + + ~Singleton() = delete; + + /** + * Get the instance. + * + * \return The instance + */ + static constexpr TYPE& Instance() + { + return ms_instance.value(); + } + + /** + * Is the instance initialized + * + * \return True if initialized, false otherwise + */ + static constexpr bool HasInstance() + { + return ms_instance.has_value(); + } + + class Lifetime + { + public: + /** + * Constructor. + * + * \param p_args Arguments for the singleton + */ + template + explicit Lifetime(ARGS&&... p_args) + { + Initialize(std::forward(p_args)...); + } + + Lifetime(const Lifetime& p_lifetime) = delete; + Lifetime(Lifetime&& p_lifetime) = delete; + + ~Lifetime() + { + Finalize(); + } + + [[nodiscard]] + Lifetime& operator=(const Lifetime& p_lifetime) = delete; + [[nodiscard]] + Lifetime& operator=(Lifetime&& p_lifetime) = delete; + }; + + [[nodiscard]] + Singleton& operator=(const Singleton& p_singleton) = delete; + [[nodiscard]] + Singleton& operator=(Singleton&& p_singleton) = delete; + + private: + /** + * Initialize the singleton. + * + * \param p_args Arguments for the singleton + */ + template + static void Initialize(ARGS&&... p_args) + { + ms_instance.emplace(std::forward(p_args)...); + } + + /** + * Finalize the singleton. + * + */ + static void Finalize() + { + ms_instance.reset(); + } + + /** + * The singleton. + */ + inline static eastl::optional ms_instance; +}; +} // namespace Bin2CPP +#endif diff --git a/Bin2CPP/Sources/Bin2CPPLib/Log.cpp b/Bin2CPP/Sources/Bin2CPPLib/Log.cpp index e69de29..525a093 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/Log.cpp +++ b/Bin2CPP/Sources/Bin2CPPLib/Log.cpp @@ -0,0 +1,49 @@ +/******************************************************************* + * \file Log.cpp + * + * \author Romain BOULLARD + * \date February 2026 + *********************************************************************/ +#include + +namespace Bin2CPP +{ +Log::Log() +{ + quill::Backend::start(); + + m_sinks[0] = quill::Frontend::create_or_get_sink("ConsoleSink"); + + quill::Logger* logger = quill::Frontend::create_or_get_logger("Bin2CPP", m_sinks[0]); + logger->set_log_level(quill::LogLevel::TraceL3); +} + +/****************************************************************************************/ + +quill::Logger* Log::GetLogger() +{ + return quill::Frontend::get_logger("Bin2CPP"); +} + +/****************************************************************************************/ + +void Log::Flush() +{ + for (quill::Logger* logger: quill::Frontend::get_all_loggers()) + { + logger->flush_log(); + } +} + +/****************************************************************************************/ + +Log::~Log() +{ + for (quill::Logger* logger: quill::Frontend::get_all_loggers()) + { + quill::Frontend::remove_logger(logger); + } + + quill::Backend::stop(); +} +} // namespace Bin2CPP diff --git a/Bin2CPP/Tests/Bin2CPPLib/Assert.cpp b/Bin2CPP/Tests/Bin2CPPLib/Assert.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Bin2CPP/Tests/Bin2CPPLib/Log.cpp b/Bin2CPP/Tests/Bin2CPPLib/Log.cpp index e69de29..47dabe7 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/Log.cpp +++ b/Bin2CPP/Tests/Bin2CPPLib/Log.cpp @@ -0,0 +1,39 @@ +/********************************************************************* + * \file Singleton.cpp + * + * \author Romain BOULLARD + * \date February 2026 + *********************************************************************/ +#include + +#include + +namespace Bin2CPP +{ +class SingletonFixture: public ::testing::Test +{ + protected: + Singleton::Lifetime m_lifetime{8}; +}; + +/****************************************************************************************/ + +TEST_F(SingletonFixture, HasInstance_ShouldReturnTrueIfSingletonIsInitialized) +{ + EXPECT_TRUE(Singleton::HasInstance()); +} + +/****************************************************************************************/ + +TEST_F(SingletonFixture, HasInstance_ShouldReturnFaleIfSingletonIsNotInitialized) +{ + EXPECT_FALSE(Singleton::HasInstance()); +} + +/****************************************************************************************/ + +TEST_F(SingletonFixture, Instance_ShouldReturnTheInstance) +{ + EXPECT_EQ(Singleton::Instance(), 8); +} +} // namespace Bin2CPP diff --git a/Bin2CPP/Tests/Bin2CPPLib/Singleton.cpp b/Bin2CPP/Tests/Bin2CPPLib/Singleton.cpp new file mode 100644 index 0000000..32421e9 --- /dev/null +++ b/Bin2CPP/Tests/Bin2CPPLib/Singleton.cpp @@ -0,0 +1,3 @@ +// +// Created by romain on 16/02/2026. +// diff --git a/format.sh b/format.sh old mode 100644 new mode 100755 diff --git a/generate_bin2cpp.sh b/generate_bin2cpp.sh old mode 100644 new mode 100755 diff --git a/generate_dependencies.sh b/generate_dependencies.sh old mode 100644 new mode 100755 From 56e558e830e71eadb0555bdcd78f13c188b9e149 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Mon, 16 Feb 2026 21:00:35 +0100 Subject: [PATCH 07/33] Fix guard name --- Bin2CPP/Sources/Bin2CPPLib/Include/Assert.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Assert.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Assert.hpp index 2370756..224308d 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/Include/Assert.hpp +++ b/Bin2CPP/Sources/Bin2CPPLib/Include/Assert.hpp @@ -4,8 +4,8 @@ * \author Romain BOULLARD * \date October 2025 *********************************************************************/ -#ifndef BIGFOOT_SYSTEM_ASSERT_HPP -#define BIGFOOT_SYSTEM_ASSERT_HPP +#ifndef BIN2CPP_ASSERT_HPP +#define BIN2CPP_ASSERT_HPP #include #if defined BIN2CPP_NOT_OPTIMIZED From 7c0f086969d37557604f6aac61a38169e514d0a2 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Mon, 16 Feb 2026 21:02:47 +0100 Subject: [PATCH 08/33] Layout --- Bin2CPP/Sources/Bin2CPPLib/Generator.cpp | 12 +++++++++++ .../Sources/Bin2CPPLib/Include/Generator.hpp | 14 +++++++++++++ Bin2CPP/Tests/Bin2CPPLib/Generator.cpp | 20 +++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp b/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp index e69de29..1a60466 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp +++ b/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp @@ -0,0 +1,12 @@ +/********************************************************************* +* \file Generator.cpp + * + * \author Romain BOULLARD + * \date February 2026 + *********************************************************************/ +#include + +namespace Bin2CPP +{ + +} // namespace Bin2CPP \ No newline at end of file diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Generator.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Generator.hpp index e69de29..db05dd8 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/Include/Generator.hpp +++ b/Bin2CPP/Sources/Bin2CPPLib/Include/Generator.hpp @@ -0,0 +1,14 @@ +/********************************************************************* + * \file Generator.hpp + * + * \author Romain BOULLARD + * \date February 2026 + *********************************************************************/ +#ifndef BIN2CPP_GENERATOR_HPP +#define BIN2CPP_GENERATOR_HPP + +namespace Bin2CPP +{ + +} // namespace Bin2CPP +#endif \ No newline at end of file diff --git a/Bin2CPP/Tests/Bin2CPPLib/Generator.cpp b/Bin2CPP/Tests/Bin2CPPLib/Generator.cpp index e69de29..25d72ca 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/Generator.cpp +++ b/Bin2CPP/Tests/Bin2CPPLib/Generator.cpp @@ -0,0 +1,20 @@ +/********************************************************************* +* \file Generator.cpp + * + * \author Romain BOULLARD + * \date February 2026 + *********************************************************************/ +#include + +#include + +#include + +namespace Bin2CPP +{ +class GeneratorFixture: public ::testing::Test +{ +protected: + Singleton::Lifetime m_lifetime; +}; +} // namespace Bin2CPP From 934b44c1f8492db2a1204dc39afa462e14f684b4 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Fri, 20 Feb 2026 19:44:57 +0100 Subject: [PATCH 09/33] Asan --- .gitea/workflows/ci.yml | 9 +++- Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt | 7 +-- Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt | 13 +++-- Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt | 7 +-- CMake/FindDependencies.cmake | 6 ++- CMake/Utils.cmake | 58 ----------------------- CMakeLists.txt | 3 -- ConanProfiles/clang | 26 ++++++++++ ConanProfiles/clang_coverage | 25 ++++++++++ ConanProfiles/clangd | 23 +++++++++ ConanProfiles/msvc | 22 +++++++++ ConanProfiles/msvc_ccache.cmake | 19 ++++++++ ConanProfiles/msvcd | 22 +++++++++ conanfile.py | 6 +-- generate_dependencies.bat | 9 ++-- generate_dependencies.sh | 15 +++--- 16 files changed, 178 insertions(+), 92 deletions(-) delete mode 100644 CMake/Utils.cmake create mode 100644 ConanProfiles/clang create mode 100644 ConanProfiles/clang_coverage create mode 100644 ConanProfiles/clangd create mode 100644 ConanProfiles/msvc create mode 100644 ConanProfiles/msvc_ccache.cmake create mode 100644 ConanProfiles/msvcd diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 2923576..5143c94 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -18,6 +18,13 @@ jobs: strategy: matrix: build_type: ["Debug", "RelWithDebInfo", "Release"] + include: + - build_type: Release + conan_profile: ./ConanProfiles/clang + - build_type: Debug + conan_profile: ./ConanProfiles/clangd + - build_type: RelWithDebInfo + conan_profile: ./ConanProfiles/clangd name: "Build & Test ${{ matrix.build_type }}" steps: - name: Install Node.js @@ -34,7 +41,7 @@ jobs: - name: Build run: | conan profile detect - conan install . --deployer=full_deploy --deployer-folder=build --remote=bigfootpackages --build=missing -s build_type=${{ matrix.build_type }} -o bin2cpp/*:build_tests=True + conan install . --deployer=full_deploy --deployer-folder=build --remote=bigfootpackages -pr:h=${{ matrix.conan_profile }} -pr:b=${{ matrix.conan_profile }} --build=missing -s build_type=${{ matrix.build_type }} -o bin2cpp/*:build_tests=True cmake -S . -B ./build/${{ matrix.build_type }} --toolchain ./build/${{ matrix.build_type }}/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -G "Ninja" cmake --build build/${{ matrix.build_type }} --parallel $(nproc) diff --git a/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt b/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt index e1d489b..ab00820 100644 --- a/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt +++ b/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt @@ -19,11 +19,12 @@ target_sources(${PROJECT_NAME} ${SOURCES} ) +target_compile_options(${PROJECT_NAME} PRIVATE ${BIN2CPP_CXX_FLAGS}) +target_link_options(${PROJECT_NAME} PRIVATE ${BIN2CPP_EXE_LINK_FLAGS}) + target_link_libraries(${PROJECT_NAME} PUBLIC CLI11::CLI11 Bin2CPPLib) target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_DL_LIBS}) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX Src FILES ${SOURCES}) -set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Bin2CPP/${ParentFolder}) - -bin2cpp_setup_dependencies("Bin2CPPExe") \ No newline at end of file +set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Bin2CPP/${ParentFolder}) \ No newline at end of file diff --git a/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt b/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt index 5331509..ac4b6de 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt +++ b/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt @@ -20,13 +20,18 @@ target_sources(${PROJECT_NAME} ${SOURCES} ) -target_link_libraries(${PROJECT_NAME} PUBLIC EASTL::EASTL mimalloc quill::quill $<$:cpptrace::cpptrace>) +target_compile_options(${PROJECT_NAME} PRIVATE ${BINN2CPP_CXX_FLAGS}) + +target_link_libraries(${PROJECT_NAME} PUBLIC + EASTL::EASTL + $<$:mimalloc-asan> + $<$:mimalloc-static> + quill::quill + $<$:cpptrace::cpptrace>) target_compile_definitions(${PROJECT_NAME} PUBLIC QUILL_NO_EXCEPTIONS - PUBLIC QUILL_DISABLE_NON_PREFIXED_MACROS - - PUBLIC MI_SHARED_LIB) + PUBLIC QUILL_DISABLE_NON_PREFIXED_MACROS) set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/MimallocImpl.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) diff --git a/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt b/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt index 046f1ca..056e8c9 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt +++ b/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt @@ -18,6 +18,9 @@ target_sources(${PROJECT_NAME} ${TEST_SOURCES} ) +target_compile_options(${PROJECT_NAME} PRIVATE ${BIN2CPP_CXX_FLAGS}) +target_link_options(${PROJECT_NAME} PRIVATE ${BIN2CPP_EXE_LINK_FLAGS}) + target_link_libraries(${PROJECT_NAME} PRIVATE gtest::gtest Bin2CPPLib) include(GoogleTest) @@ -48,6 +51,4 @@ add_custom_target(${PROJECT_NAME}Fixture add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}Fixture) -set_target_properties(${PROJECT_NAME}Fixture PROPERTIES FOLDER UtilityTargets/Tests/Bin2CPP/${ParentFolder}) - -bin2cpp_setup_dependencies("Tests/Bin2CPP") \ No newline at end of file +set_target_properties(${PROJECT_NAME}Fixture PROPERTIES FOLDER UtilityTargets/Tests/Bin2CPP/${ParentFolder}) \ No newline at end of file diff --git a/CMake/FindDependencies.cmake b/CMake/FindDependencies.cmake index 4de3717..f81ed4b 100644 --- a/CMake/FindDependencies.cmake +++ b/CMake/FindDependencies.cmake @@ -6,13 +6,17 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") endif() find_package(EASTL REQUIRED) -find_package(mimalloc REQUIRED) find_package(CLI11 REQUIRED) find_package(quill REQUIRED) if(${IS_MULTI_CONFIG}) + find_package(mimalloc REQUIRED) + find_package(mimalloc-asan REQUIRED) find_package(cpptrace REQUIRED) +elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release") + find_package(mimalloc REQUIRED) elseif(${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") + find_package(mimalloc-asan REQUIRED) find_package(cpptrace REQUIRED) endif() diff --git a/CMake/Utils.cmake b/CMake/Utils.cmake deleted file mode 100644 index 915a12f..0000000 --- a/CMake/Utils.cmake +++ /dev/null @@ -1,58 +0,0 @@ -function(bin2cpp_setup_dependencies ParentFolder) - set(CONAN_DEPLOYER_DIR "${CMAKE_SOURCE_DIR}/build/full_deploy/host") - - if(EXISTS ${CONAN_DEPLOYER_DIR}) - if(CMAKE_SYSTEM_NAME STREQUAL "Windows") - file(GLOB_RECURSE SHARED_BINARIES ${CONAN_DEPLOYER_DIR}/*mimalloc*.dll) - elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") - file(GLOB_RECURSE SHARED_BINARIES ${CONAN_DEPLOYER_DIR}/*mimalloc*.so*) - endif() - - if(${IS_MULTI_CONFIG}) - foreach(CONFIG ${CMAKE_CONFIGURATION_TYPES}) - foreach(file ${SHARED_BINARIES}) - if(file MATCHES "/${CONFIG}/") - list(APPEND SHARED_BINARIES_${CONFIG} ${file}) - endif() - endforeach() - endforeach() - - add_custom_target(${PROJECT_NAME}CopySharedBinaries - ALL DEPENDS SHARED_BINARIES - COMMAND ${CMAKE_COMMAND} -E make_directory $ - COMMAND ${CMAKE_COMMAND} -E $,copy_if_different,true> ${SHARED_BINARIES_Debug} $ - COMMAND ${CMAKE_COMMAND} -E $,copy_if_different,true> ${SHARED_BINARIES_Release} $ - COMMAND ${CMAKE_COMMAND} -E $,copy_if_different,true> ${SHARED_BINARIES_RelWithDebInfo} $ - COMMENT "Copy shared binaries for ${PROJECT_NAME}" - ) - add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}CopySharedBinaries) - set_target_properties(${PROJECT_NAME}CopySharedBinaries PROPERTIES FOLDER UtilityTargets/${ParentFolder}) - - else() - foreach(file ${SHARED_BINARIES}) - if(file MATCHES "/${CMAKE_BUILD_TYPE}/") - list(APPEND SHARED_BINARIES_${CMAKE_BUILD_TYPE} ${file}) - endif() - endforeach() - - add_custom_target(${PROJECT_NAME}CopySharedBinaries ALL - DEPENDS ${SHARED_BINARIES_${CMAKE_BUILD_TYPE}} - COMMAND ${CMAKE_COMMAND} -E make_directory $ - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SHARED_BINARIES_${CMAKE_BUILD_TYPE}} $ - COMMENT "Copy shared binaries for ${PROJECT_NAME}" - ) - add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}CopySharedBinaries) - set_target_properties(${PROJECT_NAME}CopySharedBinaries PROPERTIES FOLDER UtilityTargets/${ParentFolder}) - endif() - endif() - - if(CMAKE_SYSTEM_NAME STREQUAL "Windows") - add_custom_target(${PROJECT_NAME}PatchMinject ALL - COMMAND ${MINJECT_EXECUTABLE} -i -f $ - COMMENT "Patching ${PROJECT_NAME} to ensure mimalloc dynamic override" - ) - add_dependencies(${PROJECT_NAME}PatchMinject ${PROJECT_NAME}) - set_target_properties(${PROJECT_NAME}PatchMinject PROPERTIES FOLDER "UtilityTargets/${ParentFolder}") - endif() - -endfunction() \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index e30b8e2..315f7e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,9 +15,6 @@ set(CMAKE_CONFIGURATION_TYPES "Release;RelWithDebInfo;Debug" CACHE STRING "" FOR option(BUILD_TESTS OFF) include(${CMAKE_SOURCE_DIR}/CMake/FindDependencies.cmake) -include(${CMAKE_SOURCE_DIR}/CMake/Utils.cmake) - -find_program(MINJECT_EXECUTABLE NAMES minject) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_OPTIMIZE_DEPENDENCIES 1) diff --git a/ConanProfiles/clang b/ConanProfiles/clang new file mode 100644 index 0000000..a85443e --- /dev/null +++ b/ConanProfiles/clang @@ -0,0 +1,26 @@ +[settings] +os=Linux +arch=x86_64 +compiler=clang +compiler.version=20 +compiler.libcxx=libstdc++11 +compiler.cppstd=20 +compiler.cstd=17 +build_type=Release +[conf] +tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:generator=Ninja +tools.system.package_manager:mode=install +tools.system.package_manager:sudo=True +tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} + +tools.build:exelinkflags=["-fuse-ld=mold", "-flto"] +tools.build:sharedlinkflags=["-fuse-ld=mold", "-flto"] + +tools.build:cflags=["-flto"] +tools.build:cxxflags=["-flto"] + +[tool_requires] +!cmake/*: cmake/[>=4.2] \ No newline at end of file diff --git a/ConanProfiles/clang_coverage b/ConanProfiles/clang_coverage new file mode 100644 index 0000000..e94fdfc --- /dev/null +++ b/ConanProfiles/clang_coverage @@ -0,0 +1,25 @@ +[settings] +os=Linux +arch=x86_64 +compiler=clang +compiler.version=20 +compiler.libcxx=libstdc++11 +compiler.cppstd=20 +compiler.cstd=17 +build_type=Debug +[conf] +tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fprofile-instr-generate;-fcoverage-mapping', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fprofile-instr-generate;-fcoverage-mapping', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_SHARED_LINK_FLAGS': {'value': '-fprofile-instr-generate', 'cache': True, 'type': 'STRING', 'docstring': 'SHARED link flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fprofile-instr-generate', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:generator=Ninja +tools.system.package_manager:mode=install +tools.system.package_manager:sudo=True +tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} + +tools.build:exelinkflags=["-fuse-ld=mold"] +tools.build:sharedlinkflags=["-fuse-ld=mold"] + +[tool_requires] +!cmake/*: cmake/[>=4.2] \ No newline at end of file diff --git a/ConanProfiles/clangd b/ConanProfiles/clangd new file mode 100644 index 0000000..d3bc840 --- /dev/null +++ b/ConanProfiles/clangd @@ -0,0 +1,23 @@ +[settings] +os=Linux +arch=x86_64 +compiler=clang +compiler.version=20 +compiler.libcxx=libstdc++11 +compiler.cppstd=20 +compiler.cstd=17 +build_type=Debug +[conf] +tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:generator=Ninja +tools.system.package_manager:mode=install +tools.system.package_manager:sudo=True +tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} + +tools.build:exelinkflags=["-fuse-ld=mold"] +tools.build:sharedlinkflags=["-fuse-ld=mold"] + +[tool_requires] +!cmake/*: cmake/[>=4.2] \ No newline at end of file diff --git a/ConanProfiles/msvc b/ConanProfiles/msvc new file mode 100644 index 0000000..769a3fe --- /dev/null +++ b/ConanProfiles/msvc @@ -0,0 +1,22 @@ +[settings] +os=Windows +arch=x86_64 +compiler=msvc +compiler.version=195 +compiler.cppstd=20 +compiler.cstd=17 +compiler.runtime=dynamic +build_type=Release +[conf] +tools.cmake.cmaketoolchain:extra_variables={'BIN2CPP_CXX_FLAGS': {'value': '/W4;/WX;', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '/W4;/WX;', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:user_toolchain+={{profile_dir}}/msvc_ccache.cmake + +tools.build:exelinkflags=["/LTCG", "/INCREMENTAL:NO"] +tools.build:sharedlinkflags=["/LTCG", "/INCREMENTAL:NO"] + +tools.build:cflags=["/Zc:preprocessor", "/Zc:__STDC__", "/D_CRT_DECLARE_NONSTDC_NAMES=1", "/GL"] +tools.build:cxxflags=["/Zc:preprocessor", "/Zc:__cplusplus", "/Zc:enumTypes", "/Zc:templateScope", "/Zc:strictStrings", "/Zc:rvalueCast", "/Zc:hiddenFriend", "/Zc:externConstexpr", "/Zc:ternary", "/GL"] + +[tool_requires] +!cmake/*: cmake/[>=4.2] \ No newline at end of file diff --git a/ConanProfiles/msvc_ccache.cmake b/ConanProfiles/msvc_ccache.cmake new file mode 100644 index 0000000..2818eec --- /dev/null +++ b/ConanProfiles/msvc_ccache.cmake @@ -0,0 +1,19 @@ +# https://github.com/ccache/ccache/wiki/MS-Visual-Studio#usage-with-cmake + +find_program(ccache_exe ccache) +if(ccache_exe) + file(COPY_FILE + ${ccache_exe} ${CMAKE_BINARY_DIR}/cl.exe + ONLY_IF_DIFFERENT) + + # By default Visual Studio generators will use /Zi which is not compatible + # with ccache, so tell Visual Studio to use /Z7 instead. + message(STATUS "Setting MSVC debug information format to 'Embedded'") + set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$:Embedded>") + + set(CMAKE_VS_GLOBALS + "CLToolExe=cl.exe" + "CLToolPath=${CMAKE_BINARY_DIR}" + "UseMultiToolTask=true" + ) +endif() \ No newline at end of file diff --git a/ConanProfiles/msvcd b/ConanProfiles/msvcd new file mode 100644 index 0000000..13df5ce --- /dev/null +++ b/ConanProfiles/msvcd @@ -0,0 +1,22 @@ +[settings] +os=Windows +arch=x86_64 +compiler=msvc +compiler.version=195 +compiler.cppstd=20 +compiler.cstd=17 +compiler.runtime=dynamic +build_type=Debug +[conf] +tools.cmake.cmaketoolchain:extra_variables={'BIN2CPP_CXX_FLAGS': {'value': '/W4;/WX', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '/W4;/WX', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:user_toolchain+={{profile_dir}}/msvc_ccache.cmake + +tools.build:exelinkflags=["/INCREMENTAL:NO"] +tools.build:sharedlinkflags=["/INCREMENTAL:NO"] + +tools.build:cflags=["/Zc:preprocessor", "/Zc:__STDC__", "/D_CRT_DECLARE_NONSTDC_NAMES=1", "/fsanitize=address"] +tools.build:cxxflags=["/Zc:preprocessor", "/Zc:__cplusplus", "/Zc:enumTypes", "/Zc:templateScope", "/Zc:strictStrings", "/Zc:rvalueCast", "/Zc:hiddenFriend", "/Zc:externConstexpr", "/Zc:ternary", "/fsanitize=address"] + +[tool_requires] +!cmake/*: cmake/[>=4.2] \ No newline at end of file diff --git a/conanfile.py b/conanfile.py index 7b7cc29..7da4d35 100644 --- a/conanfile.py +++ b/conanfile.py @@ -35,10 +35,8 @@ class Bigfoot(ConanFile): if self.settings.os == "Windows": del self.options.fPIC - self.options['mimalloc'].override = True - self.options['mimalloc'].shared = True - if(self.settings.os == "Windows"): - self.options["mimalloc"].win_redirect = True + if(self.settings.build_type == "RelWithDebInfo" or self.settings.build_type == "Debug"): + self.options["mimalloc"].asan = True def requirements(self): self.requires("quill/11.0.2", transitive_headers=True) diff --git a/generate_dependencies.bat b/generate_dependencies.bat index 9ef984c..8be9eae 100644 --- a/generate_dependencies.bat +++ b/generate_dependencies.bat @@ -22,12 +22,9 @@ if "%~1"=="force" ( REM Add the remote conan remote add bigfootpackages https://conan.romainboullard.com/artifactory/api/conan/BigfootPackages -REM Install the conan configuration -conan config install https://git.romainboullard.com/BigfootDev/ConanProfiles.git - REM Install dependencies with the specified build option -conan install . --deployer=full_deploy --remote=bigfootpackages %build_option% -of build -s build_type=Release -o bin2cpp/*:build_tests=True -conan install . --deployer=full_deploy --remote=bigfootpackages %build_option% -of build -s build_type=RelWithDebInfo -o bin2cpp/*:build_tests=True -conan install . --deployer=full_deploy --remote=bigfootpackages %build_option% -of build -s build_type=Debug -o bin2cpp/*:build_tests=True +conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/msvc -pr:b=./ConanProfiles/msvc %build_option% -of build -s build_type=Release -o bin2cpp/*:build_tests=True +conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/msvcd -pr:b=./ConanProfiles/msvcd %build_option% -of build -s build_type=RelWithDebInfo -o bin2cpp/*:build_tests=True +conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/msvcd -pr:b=./ConanProfiles/msvcd %build_option% -of build -s build_type=Debug -o bin2cpp/*:build_tests=True endlocal diff --git a/generate_dependencies.sh b/generate_dependencies.sh index aed8021..23bdbd8 100755 --- a/generate_dependencies.sh +++ b/generate_dependencies.sh @@ -9,18 +9,15 @@ fi # Add the remote conan remote add bigfootpackages https://conan.romainboullard.com/artifactory/api/conan/BigfootPackages -# Install the conan configuration -conan config install https://git.romainboullard.com/BigfootDev/ConanProfiles.git - # Set the build option based on the argument if [ "$1" == "force" ]; then - conan install . --deployer=full_deploy --remote=bigfootpackages --build='*' -of build -s build_type=Release -o bin2cpp/*:build_tests=True - conan install . --deployer=full_deploy --remote=bigfootpackages --build='*' -of build -s build_type=RelWithDebInfo -o bin2cpp/*:build_tests=True - conan install . --deployer=full_deploy --remote=bigfootpackages --build='*' -of build -s build_type=Debug -o bin2cpp/*:build_tests=True + conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clang -pr:b=./ConanProfiles/clang --build='*' -of build -s build_type=Release -o bin2cpp/*:build_tests=True + conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clangd -pr:b=./ConanProfiles/clangd --build='*' -of build -s build_type=RelWithDebInfo -o bin2cpp/*:build_tests=True + conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clangd -pr:b=./ConanProfiles/clangd --build='*' -of build -s build_type=Debug -o bin2cpp/*:build_tests=True elif [ "$1" == "missing" ]; then - conan install . --deployer=full_deploy --remote=bigfootpackages --build=missing -of build -s build_type=Release -o bin2cpp/*:build_tests=True - conan install . --deployer=full_deploy --remote=bigfootpackages --build=missing -of build -s build_type=RelWithDebInfo -o bin2cpp/*:build_tests=True - conan install . --deployer=full_deploy --remote=bigfootpackages --build=missing -of build -s build_type=Debug -o bin2cpp/*:build_tests=True + conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clang -pr:b=./ConanProfiles/clang --build=missing -of build -s build_type=Release -o bin2cpp/*:build_tests=True + conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clangd -pr:b=./ConanProfiles/clangd --build=missing -of build -s build_type=RelWithDebInfo -o bin2cpp/*:build_tests=True + conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clangd -pr:b=./ConanProfiles/clangd --build=missing -of build -s build_type=Debug -o bin2cpp/*:build_tests=True echo "Invalid argument: $1" echo "Usage: $0 [force|missing]" exit 1 From f780e6f59a28b632edff7904a099b5e8ccafdf86 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Fri, 20 Feb 2026 21:01:49 +0100 Subject: [PATCH 10/33] Sanitizers --- Bin2CPP/Tests/Bin2CPPLib/Log.cpp | 56 +++++++++++++++++++++----- Bin2CPP/Tests/Bin2CPPLib/Singleton.cpp | 42 +++++++++++++++++-- ConanProfiles/clangd | 6 ++- 3 files changed, 88 insertions(+), 16 deletions(-) diff --git a/Bin2CPP/Tests/Bin2CPPLib/Log.cpp b/Bin2CPP/Tests/Bin2CPPLib/Log.cpp index 47dabe7..5cf401c 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/Log.cpp +++ b/Bin2CPP/Tests/Bin2CPPLib/Log.cpp @@ -1,39 +1,73 @@ /********************************************************************* - * \file Singleton.cpp +* \file Log.cpp * * \author Romain BOULLARD * \date February 2026 *********************************************************************/ -#include +#include #include namespace Bin2CPP { -class SingletonFixture: public ::testing::Test +class LogFixture: public ::testing::Test { - protected: - Singleton::Lifetime m_lifetime{8}; +protected: + Log m_log; }; /****************************************************************************************/ -TEST_F(SingletonFixture, HasInstance_ShouldReturnTrueIfSingletonIsInitialized) +TEST_F(LogFixture, GetLogger_ShouldReturnTheLogger) { - EXPECT_TRUE(Singleton::HasInstance()); + EXPECT_TRUE(m_log.GetLogger()); } /****************************************************************************************/ -TEST_F(SingletonFixture, HasInstance_ShouldReturnFaleIfSingletonIsNotInitialized) +TEST_F(LogFixture, LogDebug) { - EXPECT_FALSE(Singleton::HasInstance()); + Singleton::Lifetime singletonLifetime; + BIN2CPP_LOG_DEBUG("Hello"); } /****************************************************************************************/ -TEST_F(SingletonFixture, Instance_ShouldReturnTheInstance) +TEST_F(LogFixture, LogTrace) { - EXPECT_EQ(Singleton::Instance(), 8); + Singleton::Lifetime singletonLifetime; + BIN2CPP_LOG_TRACE("Hello"); +} + +/****************************************************************************************/ + +TEST_F(LogFixture, LogInfo) +{ + Singleton::Lifetime singletonLifetime; + BIN2CPP_LOG_INFO("Hello"); +} + +/****************************************************************************************/ + +TEST_F(LogFixture, LogWarn) +{ + Singleton::Lifetime singletonLifetime; + BIN2CPP_LOG_WARN("Hello"); +} + +/****************************************************************************************/ + +TEST_F(LogFixture, LogError) +{ + Singleton::Lifetime singletonLifetime; + BIN2CPP_LOG_ERROR("Hello"); +} + +/****************************************************************************************/ + +TEST_F(LogFixture, LogFatal) +{ + Singleton::Lifetime singletonLifetime; + BIN2CPP_LOG_FATAL("Hello"); } } // namespace Bin2CPP diff --git a/Bin2CPP/Tests/Bin2CPPLib/Singleton.cpp b/Bin2CPP/Tests/Bin2CPPLib/Singleton.cpp index 32421e9..47dabe7 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/Singleton.cpp +++ b/Bin2CPP/Tests/Bin2CPPLib/Singleton.cpp @@ -1,3 +1,39 @@ -// -// Created by romain on 16/02/2026. -// +/********************************************************************* + * \file Singleton.cpp + * + * \author Romain BOULLARD + * \date February 2026 + *********************************************************************/ +#include + +#include + +namespace Bin2CPP +{ +class SingletonFixture: public ::testing::Test +{ + protected: + Singleton::Lifetime m_lifetime{8}; +}; + +/****************************************************************************************/ + +TEST_F(SingletonFixture, HasInstance_ShouldReturnTrueIfSingletonIsInitialized) +{ + EXPECT_TRUE(Singleton::HasInstance()); +} + +/****************************************************************************************/ + +TEST_F(SingletonFixture, HasInstance_ShouldReturnFaleIfSingletonIsNotInitialized) +{ + EXPECT_FALSE(Singleton::HasInstance()); +} + +/****************************************************************************************/ + +TEST_F(SingletonFixture, Instance_ShouldReturnTheInstance) +{ + EXPECT_EQ(Singleton::Instance(), 8); +} +} // namespace Bin2CPP diff --git a/ConanProfiles/clangd b/ConanProfiles/clangd index d3bc840..cec5523 100644 --- a/ConanProfiles/clangd +++ b/ConanProfiles/clangd @@ -9,8 +9,10 @@ compiler.cstd=17 build_type=Debug [conf] tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_SHARED_LINK_FLAGS': {'value': '-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'SHARED link flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bigfoot', 'force': True}} tools.cmake.cmaketoolchain:generator=Ninja tools.system.package_manager:mode=install tools.system.package_manager:sudo=True From cec23c8c02c4c02706cd4fc3394acd8bd47b4e45 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sat, 21 Feb 2026 13:57:22 +0100 Subject: [PATCH 11/33] Fix generate dependencies script --- generate_dependencies.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/generate_dependencies.sh b/generate_dependencies.sh index 23bdbd8..d987b78 100755 --- a/generate_dependencies.sh +++ b/generate_dependencies.sh @@ -18,6 +18,7 @@ elif [ "$1" == "missing" ]; then conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clang -pr:b=./ConanProfiles/clang --build=missing -of build -s build_type=Release -o bin2cpp/*:build_tests=True conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clangd -pr:b=./ConanProfiles/clangd --build=missing -of build -s build_type=RelWithDebInfo -o bin2cpp/*:build_tests=True conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clangd -pr:b=./ConanProfiles/clangd --build=missing -of build -s build_type=Debug -o bin2cpp/*:build_tests=True +else echo "Invalid argument: $1" echo "Usage: $0 [force|missing]" exit 1 From 842ff8963c0b7501a76826e1757fa4c0e53ba18e Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sat, 21 Feb 2026 16:50:48 +0100 Subject: [PATCH 12/33] ASAN on Windows --- Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt | 16 +++++++++++++++- Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt | 16 +++++++++++++++- CMakeLists.txt | 10 ++++++++++ ConanProfiles/clang | 7 +++++-- ConanProfiles/clang_coverage | 7 +++++-- ConanProfiles/clangd | 7 +++++-- ConanProfiles/msvc | 3 ++- ConanProfiles/msvcd | 3 ++- 8 files changed, 59 insertions(+), 10 deletions(-) diff --git a/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt b/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt index ab00820..7cfa0a1 100644 --- a/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt +++ b/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt @@ -27,4 +27,18 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_DL_LIBS}) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX Src FILES ${SOURCES}) -set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Bin2CPP/${ParentFolder}) \ No newline at end of file +set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Bin2CPP/${ParentFolder}) + +##################ASAN SETUP################### + +if (MSVC) + get_filename_component(MSVC_BIN_DIR "${CMAKE_CXX_COMPILER}" DIRECTORY) + set(ASAN_DLL "${MSVC_BIN_DIR}/clang_rt.asan_dynamic-x86_64.dll") + + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "Copying ASan DLL: ${ASAN_DLL} to $" + COMMAND ${CMAKE_COMMAND} -E $,$>,copy_if_different,true> + "${ASAN_DLL}" + "$" + ) +endif() \ No newline at end of file diff --git a/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt b/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt index 056e8c9..5382a7e 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt +++ b/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt @@ -30,6 +30,20 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX Src/ FILES ${TEST_SOURCES}) set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Tests/Bin2CPP/${ParentFolder}) +##################ASAN SETUP################### + +if (MSVC) + get_filename_component(MSVC_BIN_DIR "${CMAKE_CXX_COMPILER}" DIRECTORY) + set(ASAN_DLL "${MSVC_BIN_DIR}/clang_rt.asan_dynamic-x86_64.dll") + + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "Copying ASan DLL: ${ASAN_DLL} to $" + COMMAND ${CMAKE_COMMAND} -E $,$>,copy_if_different,true> + "${ASAN_DLL}" + "$" + ) +endif() + ##################COPY FIXTURE FOLDER################### if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Fixture) @@ -46,7 +60,7 @@ add_custom_target(${PROJECT_NAME}Fixture COMMAND ${CMAKE_COMMAND} -E remove_directory $/Fixture COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Fixture $/Fixture DEPENDS ${FIXTURE_FILES} - COMMENT "Copying Fixture folder for ${PROJECT_NAME}" + COMMENT "Copying Fixture folder ${CMAKE_CURRENT_SOURCE_DIR}/Fixture to $/Fixture" ) add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}Fixture) diff --git a/CMakeLists.txt b/CMakeLists.txt index 315f7e2..27d1a5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,15 @@ cmake_minimum_required(VERSION 3.24) +foreach(config DEBUG RELWITHDEBINFO) + foreach(lang EXE SHARED MODULE) + if("${CMAKE_${lang}_LINKER_FLAGS_${config}}" MATCHES "/INCREMENTAL:NO") + string(REGEX REPLACE "/INCREMENTAL([^:]|$)" "" + CMAKE_${lang}_LINKER_FLAGS_${config} + "${CMAKE_${lang}_LINKER_FLAGS_${config}}") + endif() + endforeach() +endforeach() + project(Bin2CPP VERSION 0.1.0 DESCRIPTION "Bin2CPP" LANGUAGES CXX) diff --git a/ConanProfiles/clang b/ConanProfiles/clang index a85443e..997385f 100644 --- a/ConanProfiles/clang +++ b/ConanProfiles/clang @@ -6,15 +6,16 @@ compiler.version=20 compiler.libcxx=libstdc++11 compiler.cppstd=20 compiler.cstd=17 +compiler.runtime=static build_type=Release + [conf] tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} -tools.cmake.cmaketoolchain:generator=Ninja + tools.system.package_manager:mode=install tools.system.package_manager:sudo=True -tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} tools.build:exelinkflags=["-fuse-ld=mold", "-flto"] tools.build:sharedlinkflags=["-fuse-ld=mold", "-flto"] @@ -22,5 +23,7 @@ tools.build:sharedlinkflags=["-fuse-ld=mold", "-flto"] tools.build:cflags=["-flto"] tools.build:cxxflags=["-flto"] +tools.cmake.cmaketoolchain:generator=Ninja + [tool_requires] !cmake/*: cmake/[>=4.2] \ No newline at end of file diff --git a/ConanProfiles/clang_coverage b/ConanProfiles/clang_coverage index e94fdfc..b84c15a 100644 --- a/ConanProfiles/clang_coverage +++ b/ConanProfiles/clang_coverage @@ -6,20 +6,23 @@ compiler.version=20 compiler.libcxx=libstdc++11 compiler.cppstd=20 compiler.cstd=17 +compiler.runtime=static build_type=Debug + [conf] tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fprofile-instr-generate;-fcoverage-mapping', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fprofile-instr-generate;-fcoverage-mapping', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_SHARED_LINK_FLAGS': {'value': '-fprofile-instr-generate', 'cache': True, 'type': 'STRING', 'docstring': 'SHARED link flags for Bigfoot', 'force': True}} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fprofile-instr-generate', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bigfoot', 'force': True}} -tools.cmake.cmaketoolchain:generator=Ninja + tools.system.package_manager:mode=install tools.system.package_manager:sudo=True -tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} tools.build:exelinkflags=["-fuse-ld=mold"] tools.build:sharedlinkflags=["-fuse-ld=mold"] +tools.cmake.cmaketoolchain:generator=Ninja + [tool_requires] !cmake/*: cmake/[>=4.2] \ No newline at end of file diff --git a/ConanProfiles/clangd b/ConanProfiles/clangd index cec5523..8f27c93 100644 --- a/ConanProfiles/clangd +++ b/ConanProfiles/clangd @@ -6,20 +6,23 @@ compiler.version=20 compiler.libcxx=libstdc++11 compiler.cppstd=20 compiler.cstd=17 +compiler.runtime=static build_type=Debug + [conf] tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_SHARED_LINK_FLAGS': {'value': '-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'SHARED link flags for Bigfoot', 'force': True}} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bigfoot', 'force': True}} -tools.cmake.cmaketoolchain:generator=Ninja + tools.system.package_manager:mode=install tools.system.package_manager:sudo=True -tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} tools.build:exelinkflags=["-fuse-ld=mold"] tools.build:sharedlinkflags=["-fuse-ld=mold"] +tools.cmake.cmaketoolchain:generator=Ninja + [tool_requires] !cmake/*: cmake/[>=4.2] \ No newline at end of file diff --git a/ConanProfiles/msvc b/ConanProfiles/msvc index 769a3fe..e95cd6a 100644 --- a/ConanProfiles/msvc +++ b/ConanProfiles/msvc @@ -5,8 +5,9 @@ compiler=msvc compiler.version=195 compiler.cppstd=20 compiler.cstd=17 -compiler.runtime=dynamic +compiler.runtime=static build_type=Release + [conf] tools.cmake.cmaketoolchain:extra_variables={'BIN2CPP_CXX_FLAGS': {'value': '/W4;/WX;', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '/W4;/WX;', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} diff --git a/ConanProfiles/msvcd b/ConanProfiles/msvcd index 13df5ce..754b03f 100644 --- a/ConanProfiles/msvcd +++ b/ConanProfiles/msvcd @@ -5,8 +5,9 @@ compiler=msvc compiler.version=195 compiler.cppstd=20 compiler.cstd=17 -compiler.runtime=dynamic +compiler.runtime=static build_type=Debug + [conf] tools.cmake.cmaketoolchain:extra_variables={'BIN2CPP_CXX_FLAGS': {'value': '/W4;/WX', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '/W4;/WX', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} From 19e53feccdd94fcea9e799e0cd0d833c718299a4 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sat, 21 Feb 2026 16:54:10 +0100 Subject: [PATCH 13/33] fix clang --- ConanProfiles/clang | 2 ++ ConanProfiles/clang_coverage | 2 ++ ConanProfiles/clangd | 2 ++ 3 files changed, 6 insertions(+) diff --git a/ConanProfiles/clang b/ConanProfiles/clang index 997385f..644a21b 100644 --- a/ConanProfiles/clang +++ b/ConanProfiles/clang @@ -23,6 +23,8 @@ tools.build:sharedlinkflags=["-fuse-ld=mold", "-flto"] tools.build:cflags=["-flto"] tools.build:cxxflags=["-flto"] +tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} + tools.cmake.cmaketoolchain:generator=Ninja [tool_requires] diff --git a/ConanProfiles/clang_coverage b/ConanProfiles/clang_coverage index b84c15a..628727c 100644 --- a/ConanProfiles/clang_coverage +++ b/ConanProfiles/clang_coverage @@ -22,6 +22,8 @@ tools.system.package_manager:sudo=True tools.build:exelinkflags=["-fuse-ld=mold"] tools.build:sharedlinkflags=["-fuse-ld=mold"] +tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} + tools.cmake.cmaketoolchain:generator=Ninja [tool_requires] diff --git a/ConanProfiles/clangd b/ConanProfiles/clangd index 8f27c93..58fbc9a 100644 --- a/ConanProfiles/clangd +++ b/ConanProfiles/clangd @@ -24,5 +24,7 @@ tools.build:sharedlinkflags=["-fuse-ld=mold"] tools.cmake.cmaketoolchain:generator=Ninja +tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} + [tool_requires] !cmake/*: cmake/[>=4.2] \ No newline at end of file From 64bbcdd64a418e8304aa358fe0c24c691abd7e78 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sat, 21 Feb 2026 17:08:44 +0100 Subject: [PATCH 14/33] Formatting --- Bin2CPP/Sources/Bin2CPPLib/Generator.cpp | 4 ++-- Bin2CPP/Sources/Bin2CPPLib/Include/Generator.hpp | 2 +- Bin2CPP/Tests/Bin2CPPLib/Generator.cpp | 4 ++-- Bin2CPP/Tests/Bin2CPPLib/Log.cpp | 4 ++-- Bin2CPP/Tests/Bin2CPPLib/Singleton.cpp | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp b/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp index 1a60466..64f752e 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp +++ b/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp @@ -1,5 +1,5 @@ /********************************************************************* -* \file Generator.cpp + * \file Generator.cpp * * \author Romain BOULLARD * \date February 2026 @@ -9,4 +9,4 @@ namespace Bin2CPP { -} // namespace Bin2CPP \ No newline at end of file +} // namespace Bin2CPP diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Generator.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Generator.hpp index db05dd8..625f319 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/Include/Generator.hpp +++ b/Bin2CPP/Sources/Bin2CPPLib/Include/Generator.hpp @@ -11,4 +11,4 @@ namespace Bin2CPP { } // namespace Bin2CPP -#endif \ No newline at end of file +#endif diff --git a/Bin2CPP/Tests/Bin2CPPLib/Generator.cpp b/Bin2CPP/Tests/Bin2CPPLib/Generator.cpp index 25d72ca..e7e7dec 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/Generator.cpp +++ b/Bin2CPP/Tests/Bin2CPPLib/Generator.cpp @@ -1,5 +1,5 @@ /********************************************************************* -* \file Generator.cpp + * \file Generator.cpp * * \author Romain BOULLARD * \date February 2026 @@ -14,7 +14,7 @@ namespace Bin2CPP { class GeneratorFixture: public ::testing::Test { -protected: + protected: Singleton::Lifetime m_lifetime; }; } // namespace Bin2CPP diff --git a/Bin2CPP/Tests/Bin2CPPLib/Log.cpp b/Bin2CPP/Tests/Bin2CPPLib/Log.cpp index 5cf401c..17f609f 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/Log.cpp +++ b/Bin2CPP/Tests/Bin2CPPLib/Log.cpp @@ -1,5 +1,5 @@ /********************************************************************* -* \file Log.cpp + * \file Log.cpp * * \author Romain BOULLARD * \date February 2026 @@ -12,7 +12,7 @@ namespace Bin2CPP { class LogFixture: public ::testing::Test { -protected: + protected: Log m_log; }; diff --git a/Bin2CPP/Tests/Bin2CPPLib/Singleton.cpp b/Bin2CPP/Tests/Bin2CPPLib/Singleton.cpp index 47dabe7..490d7b5 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/Singleton.cpp +++ b/Bin2CPP/Tests/Bin2CPPLib/Singleton.cpp @@ -13,7 +13,7 @@ namespace Bin2CPP class SingletonFixture: public ::testing::Test { protected: - Singleton::Lifetime m_lifetime{8}; + Singleton::Lifetime m_lifetime {8}; }; /****************************************************************************************/ From c3b006c281f68a3539ff326c76e22cc1e0307ad6 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 22 Feb 2026 00:20:45 +0100 Subject: [PATCH 15/33] Fully embrace profiles --- Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt | 23 ++++++------- Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt | 7 ++-- Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt | 41 ++++++++--------------- CMake/FindDependencies.cmake | 11 +++--- CMakeLists.txt | 24 +++++++------ ConanProfiles/clang | 6 ++-- ConanProfiles/clang_coverage | 7 ++-- ConanProfiles/clangd | 8 +++-- ConanProfiles/msvc | 7 ++-- ConanProfiles/msvcd | 8 +++-- conanfile.py | 14 +++++--- generate_dependencies.bat | 6 ++-- generate_dependencies.sh | 12 +++---- 13 files changed, 85 insertions(+), 89 deletions(-) diff --git a/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt b/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt index 7cfa0a1..630d0f2 100644 --- a/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt +++ b/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt @@ -19,9 +19,6 @@ target_sources(${PROJECT_NAME} ${SOURCES} ) -target_compile_options(${PROJECT_NAME} PRIVATE ${BIN2CPP_CXX_FLAGS}) -target_link_options(${PROJECT_NAME} PRIVATE ${BIN2CPP_EXE_LINK_FLAGS}) - target_link_libraries(${PROJECT_NAME} PUBLIC CLI11::CLI11 Bin2CPPLib) target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_DL_LIBS}) @@ -31,14 +28,16 @@ set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Bin2CPP/${ParentFolder}) ##################ASAN SETUP################### -if (MSVC) - get_filename_component(MSVC_BIN_DIR "${CMAKE_CXX_COMPILER}" DIRECTORY) - set(ASAN_DLL "${MSVC_BIN_DIR}/clang_rt.asan_dynamic-x86_64.dll") +if(${ASAN}) + if (MSVC) + get_filename_component(MSVC_BIN_DIR "${CMAKE_CXX_COMPILER}" DIRECTORY) + set(ASAN_DLL "${MSVC_BIN_DIR}/clang_rt.asan_dynamic-x86_64.dll") - add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E echo "Copying ASan DLL: ${ASAN_DLL} to $" - COMMAND ${CMAKE_COMMAND} -E $,$>,copy_if_different,true> - "${ASAN_DLL}" - "$" - ) + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "Copying ASan DLL: ${ASAN_DLL} to $" + COMMAND ${CMAKE_COMMAND} -E $,$>,copy_if_different,true> + "${ASAN_DLL}" + "$" + ) + endif() endif() \ No newline at end of file diff --git a/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt b/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt index ac4b6de..2facf7a 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt +++ b/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt @@ -20,12 +20,9 @@ target_sources(${PROJECT_NAME} ${SOURCES} ) -target_compile_options(${PROJECT_NAME} PRIVATE ${BINN2CPP_CXX_FLAGS}) - -target_link_libraries(${PROJECT_NAME} PUBLIC +target_link_libraries(${PROJECT_NAME} PUBLIC EASTL::EASTL - $<$:mimalloc-asan> - $<$:mimalloc-static> + $,mimalloc-asan,mimalloc-static> quill::quill $<$:cpptrace::cpptrace>) diff --git a/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt b/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt index 5382a7e..9dbcad5 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt +++ b/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt @@ -18,9 +18,6 @@ target_sources(${PROJECT_NAME} ${TEST_SOURCES} ) -target_compile_options(${PROJECT_NAME} PRIVATE ${BIN2CPP_CXX_FLAGS}) -target_link_options(${PROJECT_NAME} PRIVATE ${BIN2CPP_EXE_LINK_FLAGS}) - target_link_libraries(${PROJECT_NAME} PRIVATE gtest::gtest Bin2CPPLib) include(GoogleTest) @@ -32,16 +29,18 @@ set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Tests/Bin2CPP/${ParentFo ##################ASAN SETUP################### -if (MSVC) - get_filename_component(MSVC_BIN_DIR "${CMAKE_CXX_COMPILER}" DIRECTORY) - set(ASAN_DLL "${MSVC_BIN_DIR}/clang_rt.asan_dynamic-x86_64.dll") +if(${ASAN}) + if (MSVC) + get_filename_component(MSVC_BIN_DIR "${CMAKE_CXX_COMPILER}" DIRECTORY) + set(ASAN_DLL "${MSVC_BIN_DIR}/clang_rt.asan_dynamic-x86_64.dll") - add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E echo "Copying ASan DLL: ${ASAN_DLL} to $" - COMMAND ${CMAKE_COMMAND} -E $,$>,copy_if_different,true> - "${ASAN_DLL}" - "$" - ) + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "Copying ASan DLL: ${ASAN_DLL} to $" + COMMAND ${CMAKE_COMMAND} -E $,$>,copy_if_different,true> + "${ASAN_DLL}" + "$" + ) + endif() endif() ##################COPY FIXTURE FOLDER################### @@ -50,19 +49,7 @@ if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Fixture) file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Fixture) endif() -# Track all fixture files -file(GLOB_RECURSE FIXTURE_FILES - CONFIGURE_DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/Fixture/* -) - -add_custom_target(${PROJECT_NAME}Fixture - COMMAND ${CMAKE_COMMAND} -E remove_directory $/Fixture - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Fixture $/Fixture - DEPENDS ${FIXTURE_FILES} +add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/Fixture $/Fixture COMMENT "Copying Fixture folder ${CMAKE_CURRENT_SOURCE_DIR}/Fixture to $/Fixture" -) - -add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}Fixture) - -set_target_properties(${PROJECT_NAME}Fixture PROPERTIES FOLDER UtilityTargets/Tests/Bin2CPP/${ParentFolder}) \ No newline at end of file +) \ No newline at end of file diff --git a/CMake/FindDependencies.cmake b/CMake/FindDependencies.cmake index f81ed4b..c2a83a0 100644 --- a/CMake/FindDependencies.cmake +++ b/CMake/FindDependencies.cmake @@ -9,14 +9,13 @@ find_package(EASTL REQUIRED) find_package(CLI11 REQUIRED) find_package(quill REQUIRED) -if(${IS_MULTI_CONFIG}) - find_package(mimalloc REQUIRED) +if(${ASAN}) find_package(mimalloc-asan REQUIRED) - find_package(cpptrace REQUIRED) -elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release") +else() find_package(mimalloc REQUIRED) -elseif(${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") - find_package(mimalloc-asan REQUIRED) +endif() + +if(${IS_MULTI_CONFIG} OR ${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") find_package(cpptrace REQUIRED) endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 27d1a5f..cf8572c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,4 @@ -cmake_minimum_required(VERSION 3.24) - -foreach(config DEBUG RELWITHDEBINFO) - foreach(lang EXE SHARED MODULE) - if("${CMAKE_${lang}_LINKER_FLAGS_${config}}" MATCHES "/INCREMENTAL:NO") - string(REGEX REPLACE "/INCREMENTAL([^:]|$)" "" - CMAKE_${lang}_LINKER_FLAGS_${config} - "${CMAKE_${lang}_LINKER_FLAGS_${config}}") - endif() - endforeach() -endforeach() +cmake_minimum_required(VERSION 3.26) project(Bin2CPP VERSION 0.1.0 DESCRIPTION "Bin2CPP" @@ -23,12 +13,24 @@ get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) set(CMAKE_CONFIGURATION_TYPES "Release;RelWithDebInfo;Debug" CACHE STRING "" FORCE) option(BUILD_TESTS OFF) +option(ASAN OFF) include(${CMAKE_SOURCE_DIR}/CMake/FindDependencies.cmake) +foreach(CONFIG DEBUG RELWITHDEBINFO) + if("${CMAKE_EXE_LINKER_FLAGS_${CONFIG}}" MATCHES "/INCREMENTAL:NO") + string(REGEX REPLACE "/INCREMENTAL([^:]|$)" "" + CMAKE_EXE_LINKER_FLAGS_${CONFIG} + "${CMAKE_EXE_LINKER_FLAGS_${CONFIG}}") + endif() +endforeach() + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_OPTIMIZE_DEPENDENCIES 1) +add_compile_options(${BIN2CPP_CXX_FLAGS}) +add_link_options(${BIN2CPP_EXE_LINK_FLAGS}) + add_compile_definitions( $<$:BIN2CPP_OPTIMIZED> $<$:BIN2CPP_NOT_OPTIMIZED> diff --git a/ConanProfiles/clang b/ConanProfiles/clang index 644a21b..a7ea222 100644 --- a/ConanProfiles/clang +++ b/ConanProfiles/clang @@ -12,7 +12,6 @@ build_type=Release [conf] tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} tools.system.package_manager:mode=install tools.system.package_manager:sudo=True @@ -28,4 +27,7 @@ tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} tools.cmake.cmaketoolchain:generator=Ninja [tool_requires] -!cmake/*: cmake/[>=4.2] \ No newline at end of file +!cmake/*: cmake/[>=4.2] + +[options] +Bin2CPP/*:build_tests=True \ No newline at end of file diff --git a/ConanProfiles/clang_coverage b/ConanProfiles/clang_coverage index 628727c..c156ac5 100644 --- a/ConanProfiles/clang_coverage +++ b/ConanProfiles/clang_coverage @@ -12,8 +12,6 @@ build_type=Debug [conf] tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fprofile-instr-generate;-fcoverage-mapping', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fprofile-instr-generate;-fcoverage-mapping', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_SHARED_LINK_FLAGS': {'value': '-fprofile-instr-generate', 'cache': True, 'type': 'STRING', 'docstring': 'SHARED link flags for Bigfoot', 'force': True}} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fprofile-instr-generate', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bigfoot', 'force': True}} tools.system.package_manager:mode=install @@ -27,4 +25,7 @@ tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} tools.cmake.cmaketoolchain:generator=Ninja [tool_requires] -!cmake/*: cmake/[>=4.2] \ No newline at end of file +!cmake/*: cmake/[>=4.2] + +[options] +Bin2CPP/*:build_tests=True \ No newline at end of file diff --git a/ConanProfiles/clangd b/ConanProfiles/clangd index 58fbc9a..8050768 100644 --- a/ConanProfiles/clangd +++ b/ConanProfiles/clangd @@ -12,8 +12,6 @@ build_type=Debug [conf] tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_SHARED_LINK_FLAGS': {'value': '-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'SHARED link flags for Bigfoot', 'force': True}} tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bigfoot', 'force': True}} tools.system.package_manager:mode=install @@ -27,4 +25,8 @@ tools.cmake.cmaketoolchain:generator=Ninja tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} [tool_requires] -!cmake/*: cmake/[>=4.2] \ No newline at end of file +!cmake/*: cmake/[>=4.2] + +[options] +Bin2CPP/*:asan=True +Bin2CPP/*:build_tests=True \ No newline at end of file diff --git a/ConanProfiles/msvc b/ConanProfiles/msvc index e95cd6a..08132fa 100644 --- a/ConanProfiles/msvc +++ b/ConanProfiles/msvc @@ -10,14 +10,15 @@ build_type=Release [conf] tools.cmake.cmaketoolchain:extra_variables={'BIN2CPP_CXX_FLAGS': {'value': '/W4;/WX;', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '/W4;/WX;', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} tools.cmake.cmaketoolchain:user_toolchain+={{profile_dir}}/msvc_ccache.cmake tools.build:exelinkflags=["/LTCG", "/INCREMENTAL:NO"] -tools.build:sharedlinkflags=["/LTCG", "/INCREMENTAL:NO"] tools.build:cflags=["/Zc:preprocessor", "/Zc:__STDC__", "/D_CRT_DECLARE_NONSTDC_NAMES=1", "/GL"] tools.build:cxxflags=["/Zc:preprocessor", "/Zc:__cplusplus", "/Zc:enumTypes", "/Zc:templateScope", "/Zc:strictStrings", "/Zc:rvalueCast", "/Zc:hiddenFriend", "/Zc:externConstexpr", "/Zc:ternary", "/GL"] [tool_requires] -!cmake/*: cmake/[>=4.2] \ No newline at end of file +!cmake/*: cmake/[>=4.2] + +[options] +Bin2CPP/*:build_tests=True \ No newline at end of file diff --git a/ConanProfiles/msvcd b/ConanProfiles/msvcd index 754b03f..1af6884 100644 --- a/ConanProfiles/msvcd +++ b/ConanProfiles/msvcd @@ -10,14 +10,16 @@ build_type=Debug [conf] tools.cmake.cmaketoolchain:extra_variables={'BIN2CPP_CXX_FLAGS': {'value': '/W4;/WX', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_C_FLAGS': {'value': '/W4;/WX', 'cache': True, 'type': 'STRING', 'docstring': 'C flags for Bigfoot', 'force': True}} tools.cmake.cmaketoolchain:user_toolchain+={{profile_dir}}/msvc_ccache.cmake tools.build:exelinkflags=["/INCREMENTAL:NO"] -tools.build:sharedlinkflags=["/INCREMENTAL:NO"] tools.build:cflags=["/Zc:preprocessor", "/Zc:__STDC__", "/D_CRT_DECLARE_NONSTDC_NAMES=1", "/fsanitize=address"] tools.build:cxxflags=["/Zc:preprocessor", "/Zc:__cplusplus", "/Zc:enumTypes", "/Zc:templateScope", "/Zc:strictStrings", "/Zc:rvalueCast", "/Zc:hiddenFriend", "/Zc:externConstexpr", "/Zc:ternary", "/fsanitize=address"] [tool_requires] -!cmake/*: cmake/[>=4.2] \ No newline at end of file +!cmake/*: cmake/[>=4.2] + +[options] +Bin2CPP/*:asan=True +Bin2CPP/*:build_tests=True diff --git a/conanfile.py b/conanfile.py index 7da4d35..dee2351 100644 --- a/conanfile.py +++ b/conanfile.py @@ -5,13 +5,14 @@ import os required_conan_version = ">=1.33.0" -class Bigfoot(ConanFile): - name = "bin2cpp" +class Bin2CPP(ConanFile): + name = "Bin2CPP" homepage = "https://git.romainboullard.com/rboullard/Bin2CPP" description = "A utility that converts files to CPP headers" topics = ("utility") license = "MIT" - version = "0.1.0" + version = "1.0.0" + package_type = "application" # Binary configuration settings = "os", "compiler", "build_type", "arch" @@ -19,11 +20,13 @@ class Bigfoot(ConanFile): "shared": [True, False], "fPIC": [True, False], "build_tests": [True, False], + "asan": [True, False] } default_options = { "shared": False, "fPIC": True, "build_tests": False, + "asan": False } generators = "CMakeDeps" @@ -35,7 +38,7 @@ class Bigfoot(ConanFile): if self.settings.os == "Windows": del self.options.fPIC - if(self.settings.build_type == "RelWithDebInfo" or self.settings.build_type == "Debug"): + if(self.options.asan and (self.settings.build_type == "RelWithDebInfo" or self.settings.build_type == "Debug")): self.options["mimalloc"].asan = True def requirements(self): @@ -52,8 +55,9 @@ class Bigfoot(ConanFile): def generate(self): tc = CMakeToolchain(self) - + tc.variables["BUILD_TESTS"] = self.options.build_tests + tc.variables["ASAN"] = self.options.asan tc.generate() diff --git a/generate_dependencies.bat b/generate_dependencies.bat index 8be9eae..8df20ad 100644 --- a/generate_dependencies.bat +++ b/generate_dependencies.bat @@ -23,8 +23,8 @@ REM Add the remote conan remote add bigfootpackages https://conan.romainboullard.com/artifactory/api/conan/BigfootPackages REM Install dependencies with the specified build option -conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/msvc -pr:b=./ConanProfiles/msvc %build_option% -of build -s build_type=Release -o bin2cpp/*:build_tests=True -conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/msvcd -pr:b=./ConanProfiles/msvcd %build_option% -of build -s build_type=RelWithDebInfo -o bin2cpp/*:build_tests=True -conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/msvcd -pr:b=./ConanProfiles/msvcd %build_option% -of build -s build_type=Debug -o bin2cpp/*:build_tests=True +conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/msvc -pr:b=./ConanProfiles/msvc %build_option% -of build -s build_type=Release +conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/msvcd -pr:b=./ConanProfiles/msvcd %build_option% -of build -s build_type=RelWithDebInfo +conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/msvcd -pr:b=./ConanProfiles/msvcd %build_option% -of build -s build_type=Debug endlocal diff --git a/generate_dependencies.sh b/generate_dependencies.sh index d987b78..bf47eb8 100755 --- a/generate_dependencies.sh +++ b/generate_dependencies.sh @@ -11,13 +11,13 @@ conan remote add bigfootpackages https://conan.romainboullard.com/artifactory/ap # Set the build option based on the argument if [ "$1" == "force" ]; then - conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clang -pr:b=./ConanProfiles/clang --build='*' -of build -s build_type=Release -o bin2cpp/*:build_tests=True - conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clangd -pr:b=./ConanProfiles/clangd --build='*' -of build -s build_type=RelWithDebInfo -o bin2cpp/*:build_tests=True - conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clangd -pr:b=./ConanProfiles/clangd --build='*' -of build -s build_type=Debug -o bin2cpp/*:build_tests=True + conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clang -pr:b=./ConanProfiles/clang --build='*' -of build -s build_type=Release + conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clangd -pr:b=./ConanProfiles/clangd --build='*' -of build -s build_type=RelWithDebInfo + conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clangd -pr:b=./ConanProfiles/clangd --build='*' -of build -s build_type=Debug elif [ "$1" == "missing" ]; then - conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clang -pr:b=./ConanProfiles/clang --build=missing -of build -s build_type=Release -o bin2cpp/*:build_tests=True - conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clangd -pr:b=./ConanProfiles/clangd --build=missing -of build -s build_type=RelWithDebInfo -o bin2cpp/*:build_tests=True - conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clangd -pr:b=./ConanProfiles/clangd --build=missing -of build -s build_type=Debug -o bin2cpp/*:build_tests=True + conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clang -pr:b=./ConanProfiles/clang --build=missing -of build -s build_type=Release + conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clangd -pr:b=./ConanProfiles/clangd --build=missing -of build -s build_type=RelWithDebInfo + conan install . --deployer=full_deploy --remote=bigfootpackages -pr:h=./ConanProfiles/clangd -pr:b=./ConanProfiles/clangd --build=missing -of build -s build_type=Debug else echo "Invalid argument: $1" echo "Usage: $0 [force|missing]" From d04876b18b886cf1bbe61a5661cd9ef235002837 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 22 Feb 2026 00:22:51 +0100 Subject: [PATCH 16/33] options now from profiles --- .gitea/workflows/ci.yml | 2 +- .gitea/workflows/sonarqube.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 5143c94..54770d3 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -41,7 +41,7 @@ jobs: - name: Build run: | conan profile detect - conan install . --deployer=full_deploy --deployer-folder=build --remote=bigfootpackages -pr:h=${{ matrix.conan_profile }} -pr:b=${{ matrix.conan_profile }} --build=missing -s build_type=${{ matrix.build_type }} -o bin2cpp/*:build_tests=True + conan install . --deployer=full_deploy --deployer-folder=build --remote=bigfootpackages -pr:h=${{ matrix.conan_profile }} -pr:b=${{ matrix.conan_profile }} --build=missing -s build_type=${{ matrix.build_type }} cmake -S . -B ./build/${{ matrix.build_type }} --toolchain ./build/${{ matrix.build_type }}/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -G "Ninja" cmake --build build/${{ matrix.build_type }} --parallel $(nproc) diff --git a/.gitea/workflows/sonarqube.yml b/.gitea/workflows/sonarqube.yml index 2d8b34e..c7530cb 100644 --- a/.gitea/workflows/sonarqube.yml +++ b/.gitea/workflows/sonarqube.yml @@ -26,7 +26,7 @@ jobs: - name: Generate run: | conan profile detect - conan install . --deployer=full_deploy --deployer-folder=build --remote=bigfootpackages --build=missing -s build_type=Debug -o bin2cpp/*:build_tests=True + conan install . --deployer=full_deploy --deployer-folder=build --remote=bigfootpackages --build=missing -s build_type=Debug cmake -S . -B ./build/Debug --toolchain ./build/Debug/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug -G "Ninja" cmake --build build/Debug --parallel $(nproc) From d67c041df1b4ebef173ccfa391b59a953f4c395b Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 22 Feb 2026 00:57:35 +0100 Subject: [PATCH 17/33] Multiple typos --- Bin2CPP/Sources/Bin2CPPLib/Include/Assert.hpp | 36 +++++++++---------- Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp | 4 +-- .../Sources/Bin2CPPLib/Include/Singleton.hpp | 4 +-- Bin2CPP/Tests/Bin2CPPLib/Log.cpp | 3 ++ ConanProfiles/clang | 2 +- ConanProfiles/clang_coverage | 4 +-- ConanProfiles/clangd | 4 +-- ConanProfiles/msvc | 2 +- ConanProfiles/msvcd | 2 +- 9 files changed, 30 insertions(+), 31 deletions(-) diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Assert.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Assert.hpp index 224308d..cd07ce1 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/Include/Assert.hpp +++ b/Bin2CPP/Sources/Bin2CPPLib/Include/Assert.hpp @@ -45,7 +45,7 @@ class AssertHandler std::format_string p_format, ARGS&&... p_args) { - BIN2CPP_LOG_FATAL("Assert: {} (File:{}, Line:{}, Function:{}\n{}", + BIN2CPP_LOG_FATAL("Assert: {} (File:{}, Line:{}, Function:{})\n{}", std::format(p_format, std::forward(p_args)...), p_location.file_name(), p_location.line(), @@ -78,13 +78,13 @@ class AssertHandler constexpr std::source_location location = std::source_location::current(); \ if (!(p_assert)) [[unlikely]] \ { \ - constexpr auto stacktrace = []() -> std::string \ + Bin2CPP::AssertHandler::Handle(location, \ + cpptrace::generate_trace().to_string(), \ + p_message __VA_OPT__(, ) __VA_ARGS__); \ + if (Bin2CPP::Singleton::HasInstance()) \ { \ - const cpptrace::stacktrace stacktrace = cpptrace::generate_trace(); \ - return stacktrace.to_string(); \ - }; \ - \ - Bin2CPP::AssertHandler::Handle(location, stacktrace(), p_message __VA_OPT__(, ) __VA_ARGS__); \ + Bin2CPP::Singleton::Instance().Flush(); \ + } \ BIN2CPP_BREAK; \ } \ } while (false) @@ -95,13 +95,13 @@ class AssertHandler constexpr std::source_location location = std::source_location::current(); \ if (!(p_assert)) [[unlikely]] \ { \ - constexpr auto stacktrace = []() -> std::string \ + Bin2CPP::AssertHandler::Handle(location, \ + cpptrace::generate_trace().to_string(), \ + p_message __VA_OPT__(, ) __VA_ARGS__); \ + if (Bin2CPP::Singleton::HasInstance()) \ { \ - const cpptrace::stacktrace stacktrace = cpptrace::generate_trace(); \ - return stacktrace.to_string(); \ - }; \ - \ - Bin2CPP::AssertHandler::Handle(location, stacktrace(), p_message __VA_OPT__(, ) __VA_ARGS__); \ + Bin2CPP::Singleton::Instance().Flush(); \ + } \ BIN2CPP_BREAK; \ } \ } while (false) @@ -112,13 +112,9 @@ class AssertHandler constexpr std::source_location location = std::source_location::current(); \ if (!(p_assert)) [[unlikely]] \ { \ - constexpr auto stacktrace = []() -> std::string \ - { \ - const cpptrace::stacktrace stacktrace = cpptrace::generate_trace(); \ - return stacktrace.to_string(); \ - }; \ - \ - Bin2CPP::AssertHandler::Handle(location, stacktrace(), p_message __VA_OPT__(, ) __VA_ARGS__); \ + Bin2CPP::AssertHandler::Handle(location, \ + cpptrace::generate_trace().to_string(), \ + p_message __VA_OPT__(, ) __VA_ARGS__); \ if (Bin2CPP::Singleton::HasInstance()) \ { \ Bin2CPP::Singleton::Instance().Flush(); \ diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp index 4e90d38..16f2a57 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp +++ b/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp @@ -11,7 +11,7 @@ #include -#ifdef BIGFOOT_WINDOWS +#ifdef BIN2CPP_WINDOWS #pragma warning(disable: 4702) #endif #include @@ -19,7 +19,7 @@ #include #include #include -#if defined BIGFOOT_WINDOWS +#if defined BIN2CPP_WINDOWS #pragma warning(default: 4702) #endif diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Singleton.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Singleton.hpp index 3fc8f3b..4f1a037 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/Include/Singleton.hpp +++ b/Bin2CPP/Sources/Bin2CPPLib/Include/Singleton.hpp @@ -26,7 +26,7 @@ class Singleton * * \return The instance */ - static constexpr TYPE& Instance() + static TYPE& Instance() { return ms_instance.value(); } @@ -36,7 +36,7 @@ class Singleton * * \return True if initialized, false otherwise */ - static constexpr bool HasInstance() + static bool HasInstance() { return ms_instance.has_value(); } diff --git a/Bin2CPP/Tests/Bin2CPPLib/Log.cpp b/Bin2CPP/Tests/Bin2CPPLib/Log.cpp index 17f609f..c6177f1 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/Log.cpp +++ b/Bin2CPP/Tests/Bin2CPPLib/Log.cpp @@ -8,6 +8,8 @@ #include +#include + namespace Bin2CPP { class LogFixture: public ::testing::Test @@ -36,6 +38,7 @@ TEST_F(LogFixture, LogDebug) TEST_F(LogFixture, LogTrace) { Singleton::Lifetime singletonLifetime; + BIN2CPP_LOG_TRACE("Hello"); } diff --git a/ConanProfiles/clang b/ConanProfiles/clang index a7ea222..e571591 100644 --- a/ConanProfiles/clang +++ b/ConanProfiles/clang @@ -11,7 +11,7 @@ build_type=Release [conf] tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} tools.system.package_manager:mode=install tools.system.package_manager:sudo=True diff --git a/ConanProfiles/clang_coverage b/ConanProfiles/clang_coverage index c156ac5..81c685d 100644 --- a/ConanProfiles/clang_coverage +++ b/ConanProfiles/clang_coverage @@ -11,8 +11,8 @@ build_type=Debug [conf] tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fprofile-instr-generate;-fcoverage-mapping', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fprofile-instr-generate', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fprofile-instr-generate;-fcoverage-mapping', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fprofile-instr-generate', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bin2CPP', 'force': True}} tools.system.package_manager:mode=install tools.system.package_manager:sudo=True diff --git a/ConanProfiles/clangd b/ConanProfiles/clangd index 8050768..1eb8657 100644 --- a/ConanProfiles/clangd +++ b/ConanProfiles/clangd @@ -11,8 +11,8 @@ build_type=Debug [conf] tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bin2CPP', 'force': True}} tools.system.package_manager:mode=install tools.system.package_manager:sudo=True diff --git a/ConanProfiles/msvc b/ConanProfiles/msvc index 08132fa..1cc7cdf 100644 --- a/ConanProfiles/msvc +++ b/ConanProfiles/msvc @@ -9,7 +9,7 @@ compiler.runtime=static build_type=Release [conf] -tools.cmake.cmaketoolchain:extra_variables={'BIN2CPP_CXX_FLAGS': {'value': '/W4;/WX;', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables={'BIN2CPP_CXX_FLAGS': {'value': '/W4;/WX;', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} tools.cmake.cmaketoolchain:user_toolchain+={{profile_dir}}/msvc_ccache.cmake tools.build:exelinkflags=["/LTCG", "/INCREMENTAL:NO"] diff --git a/ConanProfiles/msvcd b/ConanProfiles/msvcd index 1af6884..b184b6a 100644 --- a/ConanProfiles/msvcd +++ b/ConanProfiles/msvcd @@ -9,7 +9,7 @@ compiler.runtime=static build_type=Debug [conf] -tools.cmake.cmaketoolchain:extra_variables={'BIN2CPP_CXX_FLAGS': {'value': '/W4;/WX', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bigfoot', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables={'BIN2CPP_CXX_FLAGS': {'value': '/W4;/WX', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} tools.cmake.cmaketoolchain:user_toolchain+={{profile_dir}}/msvc_ccache.cmake tools.build:exelinkflags=["/INCREMENTAL:NO"] From 56418bb4019fbfb5b98791207803bb3cf7cdaec1 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 22 Feb 2026 11:33:19 +0100 Subject: [PATCH 18/33] more sanitizers --- .gitea/workflows/ci.yml | 17 ++++++++++------- ConanProfiles/clangd | 4 ++-- ConanProfiles/clangd2 | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 ConanProfiles/clangd2 diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 54770d3..1d944aa 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -21,11 +21,20 @@ jobs: include: - build_type: Release conan_profile: ./ConanProfiles/clang + name: Release - build_type: Debug conan_profile: ./ConanProfiles/clangd + name: Debug (ASAN, LSAN, UBSAN) + - build_type: Debug + conan_profile: ./ConanProfiles/clangd2 + name: Debug (TSAN, MSAN) - build_type: RelWithDebInfo conan_profile: ./ConanProfiles/clangd - name: "Build & Test ${{ matrix.build_type }}" + name: RelWithDebInfo (ASAN, LSAN, UBSAN) + - build_type: RelWithDebInfo + conan_profile: ./ConanProfiles/clangd2 + name: RelWithDebInfo (TSAN, MSAN) + name: "Build & Test ${{ matrix.name }}" steps: - name: Install Node.js run: apt-get update && apt-get install -y nodejs @@ -35,9 +44,6 @@ jobs: with: submodules: recursive - - name: Show ccache stats before - run: ccache --zero-stats - - name: Build run: | conan profile detect @@ -45,9 +51,6 @@ jobs: cmake -S . -B ./build/${{ matrix.build_type }} --toolchain ./build/${{ matrix.build_type }}/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -G "Ninja" cmake --build build/${{ matrix.build_type }} --parallel $(nproc) - - name: Show ccache stats after - run: ccache --show-stats - - name: Unit Tests run: | cd ./build/${{ matrix.build_type }} diff --git a/ConanProfiles/clangd b/ConanProfiles/clangd index 1eb8657..5219090 100644 --- a/ConanProfiles/clangd +++ b/ConanProfiles/clangd @@ -11,8 +11,8 @@ build_type=Debug [conf] tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fsanitize=address,undefined', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bin2CPP', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined,leak;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fsanitize=address,undefined,leak', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bin2CPP', 'force': True}} tools.system.package_manager:mode=install tools.system.package_manager:sudo=True diff --git a/ConanProfiles/clangd2 b/ConanProfiles/clangd2 new file mode 100644 index 0000000..fddd5be --- /dev/null +++ b/ConanProfiles/clangd2 @@ -0,0 +1,32 @@ +[settings] +os=Linux +arch=x86_64 +compiler=clang +compiler.version=20 +compiler.libcxx=libstdc++11 +compiler.cppstd=20 +compiler.cstd=17 +compiler.runtime=static +build_type=Debug + +[conf] +tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=memory,thread;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fsanitize=memory,thread', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bin2CPP', 'force': True}} + +tools.system.package_manager:mode=install +tools.system.package_manager:sudo=True + +tools.build:exelinkflags=["-fuse-ld=mold"] +tools.build:sharedlinkflags=["-fuse-ld=mold"] + +tools.cmake.cmaketoolchain:generator=Ninja + +tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} + +[tool_requires] +!cmake/*: cmake/[>=4.2] + +[options] +Bin2CPP/*:asan=True +Bin2CPP/*:build_tests=True \ No newline at end of file From a682d8ade2ef41404e57ba0d5643aee761c4a4b2 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 22 Feb 2026 11:36:54 +0100 Subject: [PATCH 19/33] more sanitizers --- .gitea/workflows/ci.yml | 10 ++++++++-- ConanProfiles/clangd2 | 4 ++-- ConanProfiles/clangd3 | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 ConanProfiles/clangd3 diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 1d944aa..da0e546 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -27,13 +27,19 @@ jobs: name: Debug (ASAN, LSAN, UBSAN) - build_type: Debug conan_profile: ./ConanProfiles/clangd2 - name: Debug (TSAN, MSAN) + name: Debug (TSAN) + - build_type: Debug + conan_profile: ./ConanProfiles/clangd3 + name: Debug (MSAN) - build_type: RelWithDebInfo conan_profile: ./ConanProfiles/clangd name: RelWithDebInfo (ASAN, LSAN, UBSAN) - build_type: RelWithDebInfo conan_profile: ./ConanProfiles/clangd2 - name: RelWithDebInfo (TSAN, MSAN) + name: RelWithDebInfo (TSAN) + - build_type: RelWithDebInfo + conan_profile: ./ConanProfiles/clangd3 + name: RelWithDebInfo (MSAN) name: "Build & Test ${{ matrix.name }}" steps: - name: Install Node.js diff --git a/ConanProfiles/clangd2 b/ConanProfiles/clangd2 index fddd5be..64321a1 100644 --- a/ConanProfiles/clangd2 +++ b/ConanProfiles/clangd2 @@ -11,8 +11,8 @@ build_type=Debug [conf] tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=memory,thread;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fsanitize=memory,thread', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bin2CPP', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=thread;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fsanitize=thread', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bin2CPP', 'force': True}} tools.system.package_manager:mode=install tools.system.package_manager:sudo=True diff --git a/ConanProfiles/clangd3 b/ConanProfiles/clangd3 new file mode 100644 index 0000000..7050f4c --- /dev/null +++ b/ConanProfiles/clangd3 @@ -0,0 +1,32 @@ +[settings] +os=Linux +arch=x86_64 +compiler=clang +compiler.version=20 +compiler.libcxx=libstdc++11 +compiler.cppstd=20 +compiler.cstd=17 +compiler.runtime=static +build_type=Debug + +[conf] +tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=memory;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fsanitize=memory', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bin2CPP', 'force': True}} + +tools.system.package_manager:mode=install +tools.system.package_manager:sudo=True + +tools.build:exelinkflags=["-fuse-ld=mold"] +tools.build:sharedlinkflags=["-fuse-ld=mold"] + +tools.cmake.cmaketoolchain:generator=Ninja + +tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} + +[tool_requires] +!cmake/*: cmake/[>=4.2] + +[options] +Bin2CPP/*:asan=True +Bin2CPP/*:build_tests=True \ No newline at end of file From 30b366572113bd9492cce3df423de539a4c6c507 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 22 Feb 2026 11:39:21 +0100 Subject: [PATCH 20/33] less sanitizers --- .gitea/workflows/ci.yml | 12 ------------ ConanProfiles/clangd2 | 32 -------------------------------- ConanProfiles/clangd3 | 32 -------------------------------- 3 files changed, 76 deletions(-) delete mode 100644 ConanProfiles/clangd2 delete mode 100644 ConanProfiles/clangd3 diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index da0e546..a3c5419 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -25,21 +25,9 @@ jobs: - build_type: Debug conan_profile: ./ConanProfiles/clangd name: Debug (ASAN, LSAN, UBSAN) - - build_type: Debug - conan_profile: ./ConanProfiles/clangd2 - name: Debug (TSAN) - - build_type: Debug - conan_profile: ./ConanProfiles/clangd3 - name: Debug (MSAN) - build_type: RelWithDebInfo conan_profile: ./ConanProfiles/clangd name: RelWithDebInfo (ASAN, LSAN, UBSAN) - - build_type: RelWithDebInfo - conan_profile: ./ConanProfiles/clangd2 - name: RelWithDebInfo (TSAN) - - build_type: RelWithDebInfo - conan_profile: ./ConanProfiles/clangd3 - name: RelWithDebInfo (MSAN) name: "Build & Test ${{ matrix.name }}" steps: - name: Install Node.js diff --git a/ConanProfiles/clangd2 b/ConanProfiles/clangd2 deleted file mode 100644 index 64321a1..0000000 --- a/ConanProfiles/clangd2 +++ /dev/null @@ -1,32 +0,0 @@ -[settings] -os=Linux -arch=x86_64 -compiler=clang -compiler.version=20 -compiler.libcxx=libstdc++11 -compiler.cppstd=20 -compiler.cstd=17 -compiler.runtime=static -build_type=Debug - -[conf] -tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=thread;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fsanitize=thread', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bin2CPP', 'force': True}} - -tools.system.package_manager:mode=install -tools.system.package_manager:sudo=True - -tools.build:exelinkflags=["-fuse-ld=mold"] -tools.build:sharedlinkflags=["-fuse-ld=mold"] - -tools.cmake.cmaketoolchain:generator=Ninja - -tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} - -[tool_requires] -!cmake/*: cmake/[>=4.2] - -[options] -Bin2CPP/*:asan=True -Bin2CPP/*:build_tests=True \ No newline at end of file diff --git a/ConanProfiles/clangd3 b/ConanProfiles/clangd3 deleted file mode 100644 index 7050f4c..0000000 --- a/ConanProfiles/clangd3 +++ /dev/null @@ -1,32 +0,0 @@ -[settings] -os=Linux -arch=x86_64 -compiler=clang -compiler.version=20 -compiler.libcxx=libstdc++11 -compiler.cppstd=20 -compiler.cstd=17 -compiler.runtime=static -build_type=Debug - -[conf] -tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=memory;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fsanitize=memory', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bin2CPP', 'force': True}} - -tools.system.package_manager:mode=install -tools.system.package_manager:sudo=True - -tools.build:exelinkflags=["-fuse-ld=mold"] -tools.build:sharedlinkflags=["-fuse-ld=mold"] - -tools.cmake.cmaketoolchain:generator=Ninja - -tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} - -[tool_requires] -!cmake/*: cmake/[>=4.2] - -[options] -Bin2CPP/*:asan=True -Bin2CPP/*:build_tests=True \ No newline at end of file From 8b3d9818c8061008e99dd41170bb2f6c1deedb4f Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 22 Feb 2026 12:04:54 +0100 Subject: [PATCH 21/33] memory sanitizer --- .gitea/workflows/ci.yml | 6 ++++++ ConanProfiles/clangd2 | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 ConanProfiles/clangd2 diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index a3c5419..0388cab 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -25,9 +25,15 @@ jobs: - build_type: Debug conan_profile: ./ConanProfiles/clangd name: Debug (ASAN, LSAN, UBSAN) + - build_type: Debug + conan_profile: ./ConanProfiles/clangd2 + name: Debug (MSAN) - build_type: RelWithDebInfo conan_profile: ./ConanProfiles/clangd name: RelWithDebInfo (ASAN, LSAN, UBSAN) + - build_type: RelWithDebInfo + conan_profile: ./ConanProfiles/clangd2 + name: RelWithDebInfo (MSAN) name: "Build & Test ${{ matrix.name }}" steps: - name: Install Node.js diff --git a/ConanProfiles/clangd2 b/ConanProfiles/clangd2 new file mode 100644 index 0000000..4192a88 --- /dev/null +++ b/ConanProfiles/clangd2 @@ -0,0 +1,34 @@ +[settings] +os=Linux +arch=x86_64 +compiler=clang +compiler.version=20 +compiler.libcxx=libstdc++11 +compiler.cppstd=20 +compiler.cstd=17 +compiler.runtime=static +build_type=Debug + +[conf] +tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} +tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} + +tools.system.package_manager:mode=install +tools.system.package_manager:sudo=True + +tools.build:cflags=["-fsanitize=memory", "-fno-sanitize-recover=all"] +tools.build:cxxflags=["-fsanitize=memory", "-fno-sanitize-recover=all"] + +tools.build:exelinkflags=["-fuse-ld=mold", "-fsanitize=memory"] +tools.build:sharedlinkflags=["-fuse-ld=mold", "-fsanitize=memory"] + +tools.cmake.cmaketoolchain:generator=Ninja + +tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} + +[tool_requires] +!cmake/*: cmake/[>=4.2] + +[options] +Bin2CPP/*:asan=True +Bin2CPP/*:build_tests=True \ No newline at end of file From 6b8e73edc433966902eb2261384e7bdc7c66ab14 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 22 Feb 2026 12:10:10 +0100 Subject: [PATCH 22/33] remove asan from memsanitizer build --- ConanProfiles/clangd2 | 1 - 1 file changed, 1 deletion(-) diff --git a/ConanProfiles/clangd2 b/ConanProfiles/clangd2 index 4192a88..c072036 100644 --- a/ConanProfiles/clangd2 +++ b/ConanProfiles/clangd2 @@ -30,5 +30,4 @@ tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} !cmake/*: cmake/[>=4.2] [options] -Bin2CPP/*:asan=True Bin2CPP/*:build_tests=True \ No newline at end of file From c00fee259f47319bde52f3fd377539aa6aadba42 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 22 Feb 2026 12:12:17 +0100 Subject: [PATCH 23/33] less sanitizers --- .gitea/workflows/ci.yml | 6 ------ ConanProfiles/clangd2 | 33 --------------------------------- 2 files changed, 39 deletions(-) delete mode 100644 ConanProfiles/clangd2 diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 0388cab..a3c5419 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -25,15 +25,9 @@ jobs: - build_type: Debug conan_profile: ./ConanProfiles/clangd name: Debug (ASAN, LSAN, UBSAN) - - build_type: Debug - conan_profile: ./ConanProfiles/clangd2 - name: Debug (MSAN) - build_type: RelWithDebInfo conan_profile: ./ConanProfiles/clangd name: RelWithDebInfo (ASAN, LSAN, UBSAN) - - build_type: RelWithDebInfo - conan_profile: ./ConanProfiles/clangd2 - name: RelWithDebInfo (MSAN) name: "Build & Test ${{ matrix.name }}" steps: - name: Install Node.js diff --git a/ConanProfiles/clangd2 b/ConanProfiles/clangd2 deleted file mode 100644 index c072036..0000000 --- a/ConanProfiles/clangd2 +++ /dev/null @@ -1,33 +0,0 @@ -[settings] -os=Linux -arch=x86_64 -compiler=clang -compiler.version=20 -compiler.libcxx=libstdc++11 -compiler.cppstd=20 -compiler.cstd=17 -compiler.runtime=static -build_type=Debug - -[conf] -tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} - -tools.system.package_manager:mode=install -tools.system.package_manager:sudo=True - -tools.build:cflags=["-fsanitize=memory", "-fno-sanitize-recover=all"] -tools.build:cxxflags=["-fsanitize=memory", "-fno-sanitize-recover=all"] - -tools.build:exelinkflags=["-fuse-ld=mold", "-fsanitize=memory"] -tools.build:sharedlinkflags=["-fuse-ld=mold", "-fsanitize=memory"] - -tools.cmake.cmaketoolchain:generator=Ninja - -tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} - -[tool_requires] -!cmake/*: cmake/[>=4.2] - -[options] -Bin2CPP/*:build_tests=True \ No newline at end of file From 09c27d52422d605db44a856b1c6ff98bd010b5c9 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Thu, 26 Feb 2026 07:58:12 +0100 Subject: [PATCH 24/33] Cleaner CMake --- .gitea/workflows/ci.yml | 5 ++-- .gitea/workflows/sonarqube.yml | 2 +- Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt | 3 ++- Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt | 3 ++- Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt | 3 ++- CMake/CustomTargets.cmake | 32 +++++++++++++++++++++++ CMakeLists.txt | 29 ++++---------------- ConanProfiles/clang | 1 - ConanProfiles/clang_coverage | 9 +++---- ConanProfiles/clangd | 9 ++++--- ConanProfiles/msvc | 2 +- ConanProfiles/msvcd | 2 +- conanfile.py | 7 +++-- 13 files changed, 63 insertions(+), 44 deletions(-) create mode 100644 CMake/CustomTargets.cmake diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index a3c5419..228f452 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -18,6 +18,7 @@ jobs: strategy: matrix: build_type: ["Debug", "RelWithDebInfo", "Release"] + unity_build: ["ON", "OFF"] include: - build_type: Release conan_profile: ./ConanProfiles/clang @@ -28,7 +29,7 @@ jobs: - build_type: RelWithDebInfo conan_profile: ./ConanProfiles/clangd name: RelWithDebInfo (ASAN, LSAN, UBSAN) - name: "Build & Test ${{ matrix.name }}" + name: "Build & Test ${{ matrix.name }} (Unity Build: ${{ matrix.unity_build }})" steps: - name: Install Node.js run: apt-get update && apt-get install -y nodejs @@ -42,7 +43,7 @@ jobs: run: | conan profile detect conan install . --deployer=full_deploy --deployer-folder=build --remote=bigfootpackages -pr:h=${{ matrix.conan_profile }} -pr:b=${{ matrix.conan_profile }} --build=missing -s build_type=${{ matrix.build_type }} - cmake -S . -B ./build/${{ matrix.build_type }} --toolchain ./build/${{ matrix.build_type }}/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -G "Ninja" + cmake -S . -B ./build/${{ matrix.build_type }} --toolchain ./build/${{ matrix.build_type }}/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_UNITY_BUILD=${{ matrix.unity_build }} -G "Ninja" cmake --build build/${{ matrix.build_type }} --parallel $(nproc) - name: Unit Tests diff --git a/.gitea/workflows/sonarqube.yml b/.gitea/workflows/sonarqube.yml index c7530cb..3732faa 100644 --- a/.gitea/workflows/sonarqube.yml +++ b/.gitea/workflows/sonarqube.yml @@ -26,7 +26,7 @@ jobs: - name: Generate run: | conan profile detect - conan install . --deployer=full_deploy --deployer-folder=build --remote=bigfootpackages --build=missing -s build_type=Debug + conan install . --deployer=full_deploy --deployer-folder=build --remote=bigfootpackages -pr:h=./ConanProfiles/clang_coverage -pr:b=./ConanProfiles/clang_coverage --build=missing -s build_type=Debug cmake -S . -B ./build/Debug --toolchain ./build/Debug/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug -G "Ninja" cmake --build build/Debug --parallel $(nproc) diff --git a/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt b/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt index 630d0f2..e27c20a 100644 --- a/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt +++ b/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt @@ -2,7 +2,7 @@ get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME) project(${PackageName}) add_executable(${PROJECT_NAME}) -set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20) target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Include) @@ -19,6 +19,7 @@ target_sources(${PROJECT_NAME} ${SOURCES} ) +target_link_libraries(${PROJECT_NAME} PRIVATE Bin2CPPCompileAndLinkFlags) target_link_libraries(${PROJECT_NAME} PUBLIC CLI11::CLI11 Bin2CPPLib) target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_DL_LIBS}) diff --git a/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt b/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt index 2facf7a..1da8ebe 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt +++ b/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt @@ -2,7 +2,7 @@ get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME) project(${PackageName}) add_library(${PROJECT_NAME} STATIC) -set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20) target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Include) @@ -20,6 +20,7 @@ target_sources(${PROJECT_NAME} ${SOURCES} ) +target_link_libraries(${PROJECT_NAME} PRIVATE Bin2CPPCompileAndLinkFlags) target_link_libraries(${PROJECT_NAME} PUBLIC EASTL::EASTL $,mimalloc-asan,mimalloc-static> diff --git a/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt b/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt index 9dbcad5..2475d5f 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt +++ b/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt @@ -2,7 +2,7 @@ get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME) project(${PackageName}Tests) add_executable(${PROJECT_NAME}) -set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20) target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Include) @@ -18,6 +18,7 @@ target_sources(${PROJECT_NAME} ${TEST_SOURCES} ) +target_link_libraries(${PROJECT_NAME} PRIVATE Bin2CPPCompileAndLinkFlags) target_link_libraries(${PROJECT_NAME} PRIVATE gtest::gtest Bin2CPPLib) include(GoogleTest) diff --git a/CMake/CustomTargets.cmake b/CMake/CustomTargets.cmake new file mode 100644 index 0000000..2f6a29c --- /dev/null +++ b/CMake/CustomTargets.cmake @@ -0,0 +1,32 @@ +foreach(CONFIG DEBUG RELWITHDEBINFO) + if("${CMAKE_EXE_LINKER_FLAGS_${CONFIG}}" MATCHES "/INCREMENTAL:NO") + string(REGEX REPLACE "/INCREMENTAL([^:]|$)" "" + CMAKE_EXE_LINKER_FLAGS_${CONFIG} + "${CMAKE_EXE_LINKER_FLAGS_${CONFIG}}") + endif() + if("${CMAKE_SHARED_LINKER_FLAGS_${CONFIG}}" MATCHES "/INCREMENTAL:NO") + string(REGEX REPLACE "/INCREMENTAL([^:]|$)" "" + CMAKE_SHARED_LINKER_FLAGS_${CONFIG} + "${CMAKE_SHARED_LINKER_FLAGS_${CONFIG}}") + endif() +endforeach() + +add_library(Bin2CPPCompileAndLinkFlags INTERFACE) + +target_compile_options(Bin2CPPCompileAndLinkFlags INTERFACE + $<$:/W4 /WX> + $<$:-Wall -Wextra -Wpedantic -Werror> + $<$,$>:-fprofile-instr-generate -fcoverage-mapping> +) + +target_link_options(Bin2CPPCompileAndLinkFlags INTERFACE + $<$,$>:-fprofile-instr-generate> +) + +target_compile_definitions(Bin2CPPCompileAndLinkFlags INTERFACE + $<$:BIN2CPP_OPTIMIZED> + $<$:BIN2CPP_NOT_OPTIMIZED> + $<$:BIN2CPP_WINDOWS> + $<$:BIN2CPP_LINUX> + $<$:NOMINMAX> + $<$:WIN32_LEAN_AND_MEAN>) \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index cf8572c..6041a4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,41 +4,22 @@ project(Bin2CPP VERSION 0.1.0 DESCRIPTION "Bin2CPP" LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED True) - set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + +include(${CMAKE_SOURCE_DIR}/CMake/CustomTargets.cmake) +include(${CMAKE_SOURCE_DIR}/CMake/FindDependencies.cmake) + set(CMAKE_CONFIGURATION_TYPES "Release;RelWithDebInfo;Debug" CACHE STRING "" FORCE) option(BUILD_TESTS OFF) option(ASAN OFF) - -include(${CMAKE_SOURCE_DIR}/CMake/FindDependencies.cmake) - -foreach(CONFIG DEBUG RELWITHDEBINFO) - if("${CMAKE_EXE_LINKER_FLAGS_${CONFIG}}" MATCHES "/INCREMENTAL:NO") - string(REGEX REPLACE "/INCREMENTAL([^:]|$)" "" - CMAKE_EXE_LINKER_FLAGS_${CONFIG} - "${CMAKE_EXE_LINKER_FLAGS_${CONFIG}}") - endif() -endforeach() +option(COVERAGE OFF) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_OPTIMIZE_DEPENDENCIES 1) -add_compile_options(${BIN2CPP_CXX_FLAGS}) -add_link_options(${BIN2CPP_EXE_LINK_FLAGS}) - -add_compile_definitions( - $<$:BIN2CPP_OPTIMIZED> - $<$:BIN2CPP_NOT_OPTIMIZED> - $<$:BIN2CPP_WINDOWS> - $<$:BIN2CPP_LINUX> - $<$:NOMINMAX> - $<$:WIN32_LEAN_AND_MEAN>) - if(BUILD_TESTS) enable_testing() endif() diff --git a/ConanProfiles/clang b/ConanProfiles/clang index e571591..86ec4bf 100644 --- a/ConanProfiles/clang +++ b/ConanProfiles/clang @@ -11,7 +11,6 @@ build_type=Release [conf] tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} tools.system.package_manager:mode=install tools.system.package_manager:sudo=True diff --git a/ConanProfiles/clang_coverage b/ConanProfiles/clang_coverage index 81c685d..f536fd9 100644 --- a/ConanProfiles/clang_coverage +++ b/ConanProfiles/clang_coverage @@ -11,8 +11,6 @@ build_type=Debug [conf] tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fprofile-instr-generate;-fcoverage-mapping', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fprofile-instr-generate', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bin2CPP', 'force': True}} tools.system.package_manager:mode=install tools.system.package_manager:sudo=True @@ -20,12 +18,13 @@ tools.system.package_manager:sudo=True tools.build:exelinkflags=["-fuse-ld=mold"] tools.build:sharedlinkflags=["-fuse-ld=mold"] -tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} - tools.cmake.cmaketoolchain:generator=Ninja +tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} + [tool_requires] !cmake/*: cmake/[>=4.2] [options] -Bin2CPP/*:build_tests=True \ No newline at end of file +Bin2CPP/*:build_tests=True +Bin2CPP/*:coverage=True diff --git a/ConanProfiles/clangd b/ConanProfiles/clangd index 5219090..9a8fc1e 100644 --- a/ConanProfiles/clangd +++ b/ConanProfiles/clangd @@ -11,14 +11,15 @@ build_type=Debug [conf] tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_CXX_FLAGS': {'value': '-Wall;-Wextra;-Wpedantic;-Werror;-fsanitize=address,undefined,leak;-fno-sanitize-recover=all', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} -tools.cmake.cmaketoolchain:extra_variables*={'BIN2CPP_EXE_LINK_FLAGS': {'value': '-fsanitize=address,undefined,leak', 'cache': True, 'type': 'STRING', 'docstring': 'EXE link flags for Bin2CPP', 'force': True}} tools.system.package_manager:mode=install tools.system.package_manager:sudo=True -tools.build:exelinkflags=["-fuse-ld=mold"] -tools.build:sharedlinkflags=["-fuse-ld=mold"] +tools.build:exelinkflags=["-fuse-ld=mold", "-fsanitize=address,undefined,leak"] +tools.build:sharedlinkflags=["-fuse-ld=mold", "-fsanitize=address,undefined,leak"] + +tools.build:cflags=["-fsanitize=address,undefined,leak", "-fno-sanitize-recover=all"] +tools.build:cxxflags=["-fsanitize=address,undefined,leak", "-fno-sanitize-recover=all"] tools.cmake.cmaketoolchain:generator=Ninja diff --git a/ConanProfiles/msvc b/ConanProfiles/msvc index 1cc7cdf..f462118 100644 --- a/ConanProfiles/msvc +++ b/ConanProfiles/msvc @@ -9,10 +9,10 @@ compiler.runtime=static build_type=Release [conf] -tools.cmake.cmaketoolchain:extra_variables={'BIN2CPP_CXX_FLAGS': {'value': '/W4;/WX;', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} tools.cmake.cmaketoolchain:user_toolchain+={{profile_dir}}/msvc_ccache.cmake tools.build:exelinkflags=["/LTCG", "/INCREMENTAL:NO"] +tools.build:sharedlinkflags=["/LTCG", "/INCREMENTAL:NO"] tools.build:cflags=["/Zc:preprocessor", "/Zc:__STDC__", "/D_CRT_DECLARE_NONSTDC_NAMES=1", "/GL"] tools.build:cxxflags=["/Zc:preprocessor", "/Zc:__cplusplus", "/Zc:enumTypes", "/Zc:templateScope", "/Zc:strictStrings", "/Zc:rvalueCast", "/Zc:hiddenFriend", "/Zc:externConstexpr", "/Zc:ternary", "/GL"] diff --git a/ConanProfiles/msvcd b/ConanProfiles/msvcd index b184b6a..aa385c6 100644 --- a/ConanProfiles/msvcd +++ b/ConanProfiles/msvcd @@ -9,10 +9,10 @@ compiler.runtime=static build_type=Debug [conf] -tools.cmake.cmaketoolchain:extra_variables={'BIN2CPP_CXX_FLAGS': {'value': '/W4;/WX', 'cache': True, 'type': 'STRING', 'docstring': 'CXX flags for Bin2CPP', 'force': True}} tools.cmake.cmaketoolchain:user_toolchain+={{profile_dir}}/msvc_ccache.cmake tools.build:exelinkflags=["/INCREMENTAL:NO"] +tools.build:sharedlinkflags=["/INCREMENTAL:NO"] tools.build:cflags=["/Zc:preprocessor", "/Zc:__STDC__", "/D_CRT_DECLARE_NONSTDC_NAMES=1", "/fsanitize=address"] tools.build:cxxflags=["/Zc:preprocessor", "/Zc:__cplusplus", "/Zc:enumTypes", "/Zc:templateScope", "/Zc:strictStrings", "/Zc:rvalueCast", "/Zc:hiddenFriend", "/Zc:externConstexpr", "/Zc:ternary", "/fsanitize=address"] diff --git a/conanfile.py b/conanfile.py index dee2351..a27c36c 100644 --- a/conanfile.py +++ b/conanfile.py @@ -20,13 +20,15 @@ class Bin2CPP(ConanFile): "shared": [True, False], "fPIC": [True, False], "build_tests": [True, False], - "asan": [True, False] + "asan": [True, False], + "coverage": [True, False] } default_options = { "shared": False, "fPIC": True, "build_tests": False, - "asan": False + "asan": False, + "coverage": False } generators = "CMakeDeps" @@ -58,6 +60,7 @@ class Bin2CPP(ConanFile): tc.variables["BUILD_TESTS"] = self.options.build_tests tc.variables["ASAN"] = self.options.asan + tc.variables["COVERAGE"] = self.options.coverage tc.generate() From 122d4652a6255c99c53be53c074a93d94518df71 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sat, 28 Feb 2026 10:46:03 +0100 Subject: [PATCH 25/33] more profiles --- .gitea/workflows/ci.yml | 14 ++------ Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt | 28 ++++++++++----- Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt | 42 +++++++++++++++-------- Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt | 25 ++++++++++---- CMake/FindDependencies.cmake | 4 ++- ConanProfiles/clangd | 8 ++--- ConanProfiles/clangd_asan | 33 ++++++++++++++++++ ConanProfiles/msvcd | 8 ++--- ConanProfiles/msvcd_asan | 25 ++++++++++++++ 9 files changed, 132 insertions(+), 55 deletions(-) create mode 100644 ConanProfiles/clangd_asan create mode 100644 ConanProfiles/msvcd_asan diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 228f452..82c227a 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -19,17 +19,8 @@ jobs: matrix: build_type: ["Debug", "RelWithDebInfo", "Release"] unity_build: ["ON", "OFF"] - include: - - build_type: Release - conan_profile: ./ConanProfiles/clang - name: Release - - build_type: Debug - conan_profile: ./ConanProfiles/clangd - name: Debug (ASAN, LSAN, UBSAN) - - build_type: RelWithDebInfo - conan_profile: ./ConanProfiles/clangd - name: RelWithDebInfo (ASAN, LSAN, UBSAN) - name: "Build & Test ${{ matrix.name }} (Unity Build: ${{ matrix.unity_build }})" + conan_profile: ["./ConanProfiles/clang", "./ConanProfiles/clangd", "./ConanProfiles/clangd_asan"] + name: "Build & Test ${{ matrix.name }} with ${{ matrix.conan_profile }} (Unity Build: ${{ matrix.unity_build }})" steps: - name: Install Node.js run: apt-get update && apt-get install -y nodejs @@ -41,7 +32,6 @@ jobs: - name: Build run: | - conan profile detect conan install . --deployer=full_deploy --deployer-folder=build --remote=bigfootpackages -pr:h=${{ matrix.conan_profile }} -pr:b=${{ matrix.conan_profile }} --build=missing -s build_type=${{ matrix.build_type }} cmake -S . -B ./build/${{ matrix.build_type }} --toolchain ./build/${{ matrix.build_type }}/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_UNITY_BUILD=${{ matrix.unity_build }} -G "Ninja" cmake --build build/${{ matrix.build_type }} --parallel $(nproc) diff --git a/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt b/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt index e27c20a..ab3ca17 100644 --- a/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt +++ b/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt @@ -4,26 +4,36 @@ project(${PackageName}) add_executable(${PROJECT_NAME}) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20) -target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Include) +file(GLOB_RECURSE BIN2CPPEXE_SOURCES + CONFIGURE_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp +) -# collect sources (reconfigure when files are added/removed) -file(GLOB_RECURSE SOURCES +file(GLOB_RECURSE BIN2CPPEXE_HEADERS CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ) target_sources(${PROJECT_NAME} PRIVATE - ${SOURCES} + ${BIN2CPPEXE_SOURCES} + PRIVATE + FILE_SET HEADERS + BASE_DIRS + ${CMAKE_CURRENT_SOURCE_DIR}/Include + FILES + ${BIN2CPPEXE_HEADERS} ) -target_link_libraries(${PROJECT_NAME} PRIVATE Bin2CPPCompileAndLinkFlags) -target_link_libraries(${PROJECT_NAME} PUBLIC CLI11::CLI11 Bin2CPPLib) -target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_DL_LIBS}) +target_link_libraries(${PROJECT_NAME} + PRIVATE + Bin2CPPCompileAndLinkFlags + Bin2CPPLib + CLI11::CLI11 + ${CMAKE_DL_LIBS}) -source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX Src FILES ${SOURCES}) +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX Src FILES ${BIN2CPPEXE_SOURCES} ${BIN2CPPEXE_HEADERS}) set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Bin2CPP/${ParentFolder}) diff --git a/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt b/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt index 1da8ebe..5807ce3 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt +++ b/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt @@ -4,35 +4,49 @@ project(${PackageName}) add_library(${PROJECT_NAME} STATIC) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20) -target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Include) +file(GLOB_RECURSE BIN2CPPLIB_SOURCES + CONFIGURE_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp +) -# collect sources (reconfigure when files are added/removed) -file(GLOB_RECURSE SOURCES +file(GLOB_RECURSE BIN2CPPLIB_HEADERS CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp +) + +file(GLOB_RECURSE BIN2CPPLIB_OTHERS + CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp.in ) target_sources(${PROJECT_NAME} PRIVATE - ${SOURCES} + ${BIN2CPPLIB_SOURCES} + PUBLIC + FILE_SET HEADERS + BASE_DIRS + ${CMAKE_CURRENT_SOURCE_DIR}/Include + FILES + ${BIN2CPPLIB_HEADERS} ) -target_link_libraries(${PROJECT_NAME} PRIVATE Bin2CPPCompileAndLinkFlags) -target_link_libraries(${PROJECT_NAME} PUBLIC - EASTL::EASTL - $,mimalloc-asan,mimalloc-static> - quill::quill - $<$:cpptrace::cpptrace>) +target_link_libraries(${PROJECT_NAME} + PRIVATE + Bin2CPPCompileAndLinkFlags + PUBLIC + $,mimalloc-asan,mimalloc-static> + EASTL::EASTL + quill::quill + $<$:cpptrace::cpptrace>) target_compile_definitions(${PROJECT_NAME} - PUBLIC QUILL_NO_EXCEPTIONS - PUBLIC QUILL_DISABLE_NON_PREFIXED_MACROS) + PUBLIC + QUILL_NO_EXCEPTIONS + QUILL_DISABLE_NON_PREFIXED_MACROS) set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/MimallocImpl.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) -source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX Src FILES ${SOURCES}) +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX Src FILES ${BIN2CPPLIB_SOURCES} ${BIN2CPPLIB_HEADERS} ${BIN2CPPLIB_OTHERS}) set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Bin2CPP/${ParentFolder}) \ No newline at end of file diff --git a/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt b/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt index 2475d5f..c5bfae5 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt +++ b/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt @@ -4,27 +4,38 @@ project(${PackageName}Tests) add_executable(${PROJECT_NAME}) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20) -target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Include) +file(GLOB_RECURSE BIN2CPPLIBTESTS_SOURCES + CONFIGURE_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp +) -file(GLOB_RECURSE TEST_SOURCES +file(GLOB_RECURSE BIN2CPPLIBTESTS_HEADERS CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ) target_sources(${PROJECT_NAME} PRIVATE - ${TEST_SOURCES} + ${BIN2CPPLIBTESTS_SOURCES} + PRIVATE + FILE_SET HEADERS + BASE_DIRS + ${CMAKE_CURRENT_SOURCE_DIR}/Include + FILES + ${BIN2CPPLIBTESTS_HEADERS} ) -target_link_libraries(${PROJECT_NAME} PRIVATE Bin2CPPCompileAndLinkFlags) -target_link_libraries(${PROJECT_NAME} PRIVATE gtest::gtest Bin2CPPLib) +target_link_libraries(${PROJECT_NAME} + PRIVATE + Bin2CPPCompileAndLinkFlags + Bin2CPPLib + gtest::gtest) include(GoogleTest) gtest_discover_tests(${PROJECT_NAME} XML_OUTPUT_DIR ${CMAKE_BINARY_DIR}/TestResults/) -source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX Src/ FILES ${TEST_SOURCES}) +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX Src/ FILES ${BIN2CPPLIBTESTS_SOURCES} ${BIN2CPPLIBTESTS_HEADERS}) set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Tests/Bin2CPP/${ParentFolder}) diff --git a/CMake/FindDependencies.cmake b/CMake/FindDependencies.cmake index c2a83a0..9f40144 100644 --- a/CMake/FindDependencies.cmake +++ b/CMake/FindDependencies.cmake @@ -15,7 +15,9 @@ else() find_package(mimalloc REQUIRED) endif() -if(${IS_MULTI_CONFIG} OR ${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") +if(${IS_MULTI_CONFIG}) + find_package(cpptrace REQUIRED) +elseif(${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") find_package(cpptrace REQUIRED) endif() diff --git a/ConanProfiles/clangd b/ConanProfiles/clangd index 9a8fc1e..0fa3339 100644 --- a/ConanProfiles/clangd +++ b/ConanProfiles/clangd @@ -15,11 +15,8 @@ tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccac tools.system.package_manager:mode=install tools.system.package_manager:sudo=True -tools.build:exelinkflags=["-fuse-ld=mold", "-fsanitize=address,undefined,leak"] -tools.build:sharedlinkflags=["-fuse-ld=mold", "-fsanitize=address,undefined,leak"] - -tools.build:cflags=["-fsanitize=address,undefined,leak", "-fno-sanitize-recover=all"] -tools.build:cxxflags=["-fsanitize=address,undefined,leak", "-fno-sanitize-recover=all"] +tools.build:exelinkflags=["-fuse-ld=mold"] +tools.build:sharedlinkflags=["-fuse-ld=mold"] tools.cmake.cmaketoolchain:generator=Ninja @@ -29,5 +26,4 @@ tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} !cmake/*: cmake/[>=4.2] [options] -Bin2CPP/*:asan=True Bin2CPP/*:build_tests=True \ No newline at end of file diff --git a/ConanProfiles/clangd_asan b/ConanProfiles/clangd_asan new file mode 100644 index 0000000..9a8fc1e --- /dev/null +++ b/ConanProfiles/clangd_asan @@ -0,0 +1,33 @@ +[settings] +os=Linux +arch=x86_64 +compiler=clang +compiler.version=20 +compiler.libcxx=libstdc++11 +compiler.cppstd=20 +compiler.cstd=17 +compiler.runtime=static +build_type=Debug + +[conf] +tools.cmake.cmaketoolchain:extra_variables={'CMAKE_CXX_COMPILER_LAUNCHER': 'ccache', 'CMAKE_C_COMPILER_LAUNCHER': 'ccache'} + +tools.system.package_manager:mode=install +tools.system.package_manager:sudo=True + +tools.build:exelinkflags=["-fuse-ld=mold", "-fsanitize=address,undefined,leak"] +tools.build:sharedlinkflags=["-fuse-ld=mold", "-fsanitize=address,undefined,leak"] + +tools.build:cflags=["-fsanitize=address,undefined,leak", "-fno-sanitize-recover=all"] +tools.build:cxxflags=["-fsanitize=address,undefined,leak", "-fno-sanitize-recover=all"] + +tools.cmake.cmaketoolchain:generator=Ninja + +tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} + +[tool_requires] +!cmake/*: cmake/[>=4.2] + +[options] +Bin2CPP/*:asan=True +Bin2CPP/*:build_tests=True \ No newline at end of file diff --git a/ConanProfiles/msvcd b/ConanProfiles/msvcd index aa385c6..74ff47a 100644 --- a/ConanProfiles/msvcd +++ b/ConanProfiles/msvcd @@ -11,15 +11,11 @@ build_type=Debug [conf] tools.cmake.cmaketoolchain:user_toolchain+={{profile_dir}}/msvc_ccache.cmake -tools.build:exelinkflags=["/INCREMENTAL:NO"] -tools.build:sharedlinkflags=["/INCREMENTAL:NO"] - -tools.build:cflags=["/Zc:preprocessor", "/Zc:__STDC__", "/D_CRT_DECLARE_NONSTDC_NAMES=1", "/fsanitize=address"] -tools.build:cxxflags=["/Zc:preprocessor", "/Zc:__cplusplus", "/Zc:enumTypes", "/Zc:templateScope", "/Zc:strictStrings", "/Zc:rvalueCast", "/Zc:hiddenFriend", "/Zc:externConstexpr", "/Zc:ternary", "/fsanitize=address"] +tools.build:cflags=["/Zc:preprocessor", "/Zc:__STDC__", "/D_CRT_DECLARE_NONSTDC_NAMES=1"] +tools.build:cxxflags=["/Zc:preprocessor", "/Zc:__cplusplus", "/Zc:enumTypes", "/Zc:templateScope", "/Zc:strictStrings", "/Zc:rvalueCast", "/Zc:hiddenFriend", "/Zc:externConstexpr", "/Zc:ternary"] [tool_requires] !cmake/*: cmake/[>=4.2] [options] -Bin2CPP/*:asan=True Bin2CPP/*:build_tests=True diff --git a/ConanProfiles/msvcd_asan b/ConanProfiles/msvcd_asan new file mode 100644 index 0000000..13ad410 --- /dev/null +++ b/ConanProfiles/msvcd_asan @@ -0,0 +1,25 @@ +[settings] +os=Windows +arch=x86_64 +compiler=msvc +compiler.version=195 +compiler.cppstd=20 +compiler.cstd=17 +compiler.runtime=static +build_type=Debug + +[conf] +tools.cmake.cmaketoolchain:user_toolchain+={{profile_dir}}/msvc_ccache.cmake + +tools.build:exelinkflags=["/INCREMENTAL:NO"] +tools.build:sharedlinkflags=["/INCREMENTAL:NO"] + +tools.build:cflags=["/Zc:preprocessor", "/Zc:__STDC__", "/D_CRT_DECLARE_NONSTDC_NAMES=1"] +tools.build:cxxflags=["/Zc:preprocessor", "/Zc:__cplusplus", "/Zc:enumTypes", "/Zc:templateScope", "/Zc:strictStrings", "/Zc:rvalueCast", "/Zc:hiddenFriend", "/Zc:externConstexpr", "/Zc:ternary"] + +[tool_requires] +!cmake/*: cmake/[>=4.2] + +[options] +Bin2CPP/*:asan=True +Bin2CPP/*:build_tests=True From a0d43a31e9e6ed5cd761e878b6d87a95fa335a7e Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sat, 28 Feb 2026 10:47:08 +0100 Subject: [PATCH 26/33] Fix name --- .gitea/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 82c227a..cc9263a 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: build_type: ["Debug", "RelWithDebInfo", "Release"] unity_build: ["ON", "OFF"] conan_profile: ["./ConanProfiles/clang", "./ConanProfiles/clangd", "./ConanProfiles/clangd_asan"] - name: "Build & Test ${{ matrix.name }} with ${{ matrix.conan_profile }} (Unity Build: ${{ matrix.unity_build }})" + name: "Build & Test ${{ matrix.build_type }} with ${{ matrix.conan_profile }} (Unity Build: ${{ matrix.unity_build }})" steps: - name: Install Node.js run: apt-get update && apt-get install -y nodejs From 589bc61c6e53cd6bd82bf9a24569b3b1c0c5282f Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sat, 28 Feb 2026 10:52:27 +0100 Subject: [PATCH 27/33] Fix asan --- conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conanfile.py b/conanfile.py index a27c36c..6893e79 100644 --- a/conanfile.py +++ b/conanfile.py @@ -40,7 +40,7 @@ class Bin2CPP(ConanFile): if self.settings.os == "Windows": del self.options.fPIC - if(self.options.asan and (self.settings.build_type == "RelWithDebInfo" or self.settings.build_type == "Debug")): + if(self.options.asan): self.options["mimalloc"].asan = True def requirements(self): From 29491b8c3e675446d765bf75bdfac17cb91b8f20 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sat, 28 Feb 2026 11:01:52 +0100 Subject: [PATCH 28/33] fix asan --- Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt | 4 +--- Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt b/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt index ab3ca17..6b8e2d4 100644 --- a/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt +++ b/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt @@ -46,9 +46,7 @@ if(${ASAN}) add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo "Copying ASan DLL: ${ASAN_DLL} to $" - COMMAND ${CMAKE_COMMAND} -E $,$>,copy_if_different,true> - "${ASAN_DLL}" - "$" + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${ASAN_DLL}" "$" ) endif() endif() \ No newline at end of file diff --git a/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt b/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt index c5bfae5..4f283e1 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt +++ b/Bin2CPP/Tests/Bin2CPPLib/CMakeLists.txt @@ -48,9 +48,7 @@ if(${ASAN}) add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo "Copying ASan DLL: ${ASAN_DLL} to $" - COMMAND ${CMAKE_COMMAND} -E $,$>,copy_if_different,true> - "${ASAN_DLL}" - "$" + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${ASAN_DLL}" "$" ) endif() endif() From 1328b17b4734f03b5ee68f999fe581de138b8c7c Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sat, 28 Mar 2026 23:02:28 +0100 Subject: [PATCH 29/33] Bin2Cpp --- Bin2CPP/Sources/Bin2CPPExe/main.cpp | 60 +++- Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt | 4 +- .../Bin2CPPLib/GeneratedTemplate.hpp.in | 20 -- Bin2CPP/Sources/Bin2CPPLib/Generator.cpp | 268 ++++++++++++++++++ .../Bin2CPPLib/Include/EASTLFormatters.hpp | 87 ------ .../Bin2CPPLib/Include/GeneratedTemplate.hpp | 36 +++ .../Sources/Bin2CPPLib/Include/Generator.hpp | 143 ++++++++++ Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp | 5 +- .../Sources/Bin2CPPLib/Include/Singleton.hpp | 4 +- Bin2CPP/Tests/Bin2CPPLib/Generator.cpp | 119 ++++++++ CMake/FindDependencies.cmake | 2 +- ConanProfiles/msvc | 2 +- ConanProfiles/msvcd | 3 +- ConanProfiles/msvcd_asan | 2 +- conanfile.py | 2 +- 15 files changed, 636 insertions(+), 121 deletions(-) delete mode 100644 Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in delete mode 100644 Bin2CPP/Sources/Bin2CPPLib/Include/EASTLFormatters.hpp create mode 100644 Bin2CPP/Sources/Bin2CPPLib/Include/GeneratedTemplate.hpp diff --git a/Bin2CPP/Sources/Bin2CPPExe/main.cpp b/Bin2CPP/Sources/Bin2CPPExe/main.cpp index 427d4ab..f5bc1c9 100644 --- a/Bin2CPP/Sources/Bin2CPPExe/main.cpp +++ b/Bin2CPP/Sources/Bin2CPPExe/main.cpp @@ -1,4 +1,62 @@ -int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) +#include +#include + +#include + +int main(int argc, char** argv) { + Bin2CPP::Singleton::Lifetime loggerLifetime; + + CLI::App app {"Bin2CPP allows you to generate a C++ header containing the binary content of an input file"}; + argv = app.ensure_utf8(argv); + + std::string input; + app.add_option("-f,--input", input, "The input file")->required(); + std::string output; + app.add_option("-o,--output", output, "The output file")->required(); + std::optional arrayType; + app.add_option("--arrayType", arrayType, "The type of the array"); + std::optional arrayInclude; + app.add_option("--arrayInclude", arrayInclude, "Include for the array type"); + std::optional arrayName; + app.add_option("--arrayName", arrayName, "The array name"); + std::optional customNamespace; + app.add_option("--namespace", customNamespace, "The namespace"); + + CLI11_PARSE(app, argc, argv); + + Bin2CPP::Generator generator(input); + if (arrayType) + { + generator.SetMapping(Bin2CPP::MappingKey::ARRAY_TYPE, arrayType.value()); + } + if (arrayInclude) + { + generator.SetMapping(Bin2CPP::MappingKey::ARRAY_TYPE_INCLUDE, arrayInclude.value()); + } + if (arrayName) + { + generator.SetMapping(Bin2CPP::MappingKey::ARRAY_NAME, arrayName.value()); + } + if (customNamespace) + { + generator.SetMapping(Bin2CPP::MappingKey::NAMESPACE, customNamespace.value()); + } + + if (generator.Generate()) + { + std::ofstream out(output); + if (!out) + { + BIN2CPP_LOG_ERROR("Failed to open '{}'", output); + return 1; + } + + out << generator.Get(); + out.close(); + } + + BIN2CPP_LOG_INFO("'{}' Generated !", output); + return 0; } diff --git a/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt b/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt index 5807ce3..d548139 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt +++ b/Bin2CPP/Sources/Bin2CPPLib/CMakeLists.txt @@ -36,9 +36,9 @@ target_link_libraries(${PROJECT_NAME} Bin2CPPCompileAndLinkFlags PUBLIC $,mimalloc-asan,mimalloc-static> - EASTL::EASTL quill::quill - $<$:cpptrace::cpptrace>) + $<$:cpptrace::cpptrace> + magic_enum::magic_enum) target_compile_definitions(${PROJECT_NAME} PUBLIC diff --git a/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in b/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in deleted file mode 100644 index 8c280d8..0000000 --- a/Bin2CPP/Sources/Bin2CPPLib/GeneratedTemplate.hpp.in +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Auto-generated header from: {{FILENAME}} - * Generated by Bin2CPP - * - * DO NOT TOUCH - */ -#ifndef {{GUARD_NAME}} -#define {{GUARD_NAME}} -#include {{ARRAY_TYPE_INCLUDE}} -#include - -namespace {{NAMESPACE}} { - -inline constexpr {{ARRAY_TYPE}} {{ARRAY_NAME}} = { -{{DATA}} -}; - -} // namespace {{NAMESPACE}} - -#endif // {{GUARD_NAME}} \ No newline at end of file diff --git a/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp b/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp index 64f752e..547cef6 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp +++ b/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp @@ -6,7 +6,275 @@ *********************************************************************/ #include +#include +#include + +#include +#include +#include +#include +#include +#include + namespace Bin2CPP { +Generator::Generator(const std::string_view p_inputFile): + m_inputFile(p_inputFile) +{ +} +/****************************************************************************************/ + +void Generator::SetMapping(const MappingKey p_key, const std::string_view p_value) +{ + const std::optional index = magic_enum::enum_index(p_key); + BIN2CPP_CRITICAL_ASSERT(index.has_value(), "Incorrect mapping key! Got {}", magic_enum::enum_integer(p_key)); + + m_mappingTable[index.value()] = p_value; +} + +/****************************************************************************************/ + +bool Generator::Generate() +{ + if (!ComputeMappings()) + { + BIN2CPP_LOG_ERROR("Invalid mappings! Can't generate file!"); + return false; + } + + m_result = g_generatedTemplate; + + for (std::uint32_t i = 0; i < m_mappingTable.size(); ++i) + { + const std::string KEY = magic_enum::enum_name(magic_enum::enum_value(i)).data(); + const std::string& VALUE = m_mappingTable[i]; + + const std::string pattern = "\\{\\{" + KEY + "\\}\\}"; + std::regex placeholderRegex(pattern); + m_result = std::regex_replace(m_result, placeholderRegex, VALUE); + } + + return Validate(); +} + +/****************************************************************************************/ + +std::string_view Generator::Get() const +{ + return m_result; +} + +/****************************************************************************************/ + +bool Generator::ComputeMappings() +{ + std::filesystem::path file {m_inputFile.data()}; + if (!std::filesystem::exists(file)) + { + BIN2CPP_LOG_ERROR("File '{}' does not exists!", m_inputFile); + return false; + } + if (std::filesystem::is_directory(file)) + { + BIN2CPP_LOG_ERROR("'{}' is not a file!", m_inputFile); + return false; + } + + if (!ComputeFilename()) + { + BIN2CPP_LOG_ERROR("Failed to compute filename"); + return false; + } + if (!ComputeGuardName()) + { + BIN2CPP_LOG_ERROR("Failed to compute GuardName"); + return false; + } + if (!ComputeArrayTypeInclude()) + { + BIN2CPP_LOG_ERROR("Failed to compute ArrayTypeInclude"); + return false; + } + if (!ComputeArrayType()) + { + BIN2CPP_LOG_ERROR("Failed to compute ArrayType"); + return false; + } + if (!ComputeArrayName()) + { + BIN2CPP_LOG_ERROR("Failed to compute ArrayName"); + return false; + } + + std::ifstream in {m_inputFile.data(), std::ios::binary}; + if (!in) + { + BIN2CPP_LOG_ERROR("Failed to open '{}'", m_inputFile); + return false; + } + in.seekg(0, std::ios::end); + const size_t fileSize = static_cast(in.tellg()); + in.seekg(0, std::ios::beg); + + std::vector data(fileSize); + in.read(std::bit_cast(data.data()), fileSize); + + if (!ComputeArraySize(data)) + { + BIN2CPP_LOG_ERROR("Failed to compute ArraySize"); + return false; + } + if (!ComputeData(data)) + { + BIN2CPP_LOG_ERROR("Failed to compute Data"); + return false; + } + + return true; +} + +/****************************************************************************************/ + +bool Generator::ComputeFilename() +{ + std::filesystem::path file {m_inputFile.data()}; + m_mappingTable[magic_enum::enum_index(MappingKey::FILENAME).value()] = file.filename().string().c_str(); + + return true; +} + +/****************************************************************************************/ + +bool Generator::ComputeGuardName() +{ + std::filesystem::path file {m_inputFile.data()}; + std::string guardName = file.filename().string(); + + std::transform(guardName.begin(), + guardName.end(), + guardName.begin(), + [](const char c) + { + if (!std::isalnum(c)) + { + return static_cast('_'); + } + else + { + return std::toupper(c); + } + }); + m_mappingTable[magic_enum::enum_index(MappingKey::GUARD_NAME).value()] = std::format("{}_HPP", guardName); + + return true; +} + +/****************************************************************************************/ + +bool Generator::ComputeArrayTypeInclude() +{ + std::string& value = m_mappingTable[magic_enum::enum_index(MappingKey::ARRAY_TYPE_INCLUDE).value()]; + if (value.empty()) + { + value = ""; + } + + return true; +} + +/****************************************************************************************/ + +bool Generator::ComputeArrayType() +{ + std::string& value = m_mappingTable[magic_enum::enum_index(MappingKey::ARRAY_TYPE).value()]; + if (value.empty()) + { + value = "std::array"; + } + + return true; +} + +/****************************************************************************************/ + +bool Generator::ComputeArrayName() +{ + std::string& value = m_mappingTable[magic_enum::enum_index(MappingKey::ARRAY_NAME).value()]; + if (value.empty()) + { + std::filesystem::path file {m_inputFile.data()}; + value = std::format("g_{}", file.filename().string()); + + std::transform(value.begin(), + value.end(), + value.begin(), + [](const char c) + { + if (!std::isalnum(c)) + { + return static_cast('_'); + } + else + { + return static_cast(c); + } + }); + } + + return true; +} + +/****************************************************************************************/ + +bool Generator::ComputeArraySize(const std::span p_data) +{ + m_mappingTable[magic_enum::enum_index(MappingKey::ARRAY_SIZE).value()] = std::to_string(p_data.size()); + return true; +} + +/****************************************************************************************/ + +bool Generator::ComputeData(const std::span p_data) +{ + std::string& value = m_mappingTable[magic_enum::enum_index(MappingKey::DATA).value()]; + value.clear(); + + constexpr std::size_t bytesPerLine = 5; + constexpr std::string_view linePrefix = "\n "; + + for (std::size_t i = 0; i < p_data.size(); ++i) + { + if (i > 0 && i % bytesPerLine == 0) + { + value.append(linePrefix.data(), linePrefix.size()); + } + + const std::string element = std::format("std::byte{{0x{:02X}}}", std::to_integer(p_data[i])); + value.append(element.data(), element.size()); + + if (i + 1 < p_data.size()) + { + value.append(", "); + } + } + + return true; +} + +/****************************************************************************************/ + +bool Generator::Validate() +{ + std::regex unreplacedRegex(R"(\{\{[A-Z_]+\}\})"); + std::smatch match; + + if (std::regex_search(m_result, match, unreplacedRegex)) + { + BIN2CPP_LOG_ERROR("Warning: Unreplaced placeholder found: {}", match.str()); + return false; + } + + return true; +} } // namespace Bin2CPP diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/EASTLFormatters.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/EASTLFormatters.hpp deleted file mode 100644 index 2fbd09d..0000000 --- a/Bin2CPP/Sources/Bin2CPPLib/Include/EASTLFormatters.hpp +++ /dev/null @@ -1,87 +0,0 @@ -/********************************************************************* - * \file EASTLFormatters.hpp - * - * \author Romain BOULLARD - * \date February 2026 - *********************************************************************/ -#ifndef BIN2CPP_EASTLFORMATTERS_HPP -#define BIN2CPP_EASTLFORMATTERS_HPP -#include - -#include - -#include -#include - -// STRING - -template<> -struct std::formatter -{ - constexpr auto parse(std::format_parse_context& ctx) - { - return ctx.begin(); - } - - template - auto format(const eastl::string& p_string, FormatContext& ctx) const - { - return std::format_to(ctx.out(), "{}", p_string.c_str()); - } -}; - -template<> -struct fmtquill::formatter -{ - constexpr auto parse(format_parse_context& ctx) - { - return ctx.begin(); - } - - auto format(const eastl::string& p_string, format_context& ctx) const - { - return fmtquill::format_to(ctx.out(), "{}", p_string.c_str()); - } -}; - -template<> -struct quill::Codec: quill::DeferredFormatCodec -{ -}; - -// STRING_VIEW - -template<> -struct std::formatter -{ - constexpr auto parse(std::format_parse_context& ctx) - { - return ctx.begin(); - } - - template - auto format(const eastl::string_view& p_stringView, FormatContext& ctx) const - { - return std::format_to(ctx.out(), "{}", p_stringView.data()); - } -}; - -template<> -struct fmtquill::formatter -{ - constexpr auto parse(format_parse_context& ctx) - { - return ctx.begin(); - } - - auto format(const eastl::string_view& p_stringView, format_context& ctx) const - { - return fmtquill::format_to(ctx.out(), "{}", p_stringView.data()); - } -}; - -template<> -struct quill::Codec: quill::DeferredFormatCodec -{ -}; -#endif diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/GeneratedTemplate.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/GeneratedTemplate.hpp new file mode 100644 index 0000000..2645f23 --- /dev/null +++ b/Bin2CPP/Sources/Bin2CPPLib/Include/GeneratedTemplate.hpp @@ -0,0 +1,36 @@ +/********************************************************************* + * \file GeneratedTemplate.hpp + * + * \author Romain BOULLARD + * \date March 2026 + *********************************************************************/ +#ifndef BIN2CPP_GENERATED_TEMPLATE_HPP +#define BIN2CPP_GENERATED_TEMPLATE_HPP +#include + +namespace Bin2CPP +{ +constexpr std::string_view g_generatedTemplate = R"(/** + * Auto-generated header from: {{FILENAME}} + * Generated by Bin2CPP + * + * DO NOT TOUCH + */ +#ifndef {{GUARD_NAME}} +#define {{GUARD_NAME}} +#include {{ARRAY_TYPE_INCLUDE}} +#include + +namespace {{NAMESPACE}} +{ + inline constexpr {{ARRAY_TYPE}} {{ARRAY_NAME}} = { + {{DATA}} + }; + +} // namespace {{NAMESPACE}} + +#endif // {{GUARD_NAME}} +)"; +} // namespace Bin2CPP + +#endif diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Generator.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Generator.hpp index 625f319..a18b646 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/Include/Generator.hpp +++ b/Bin2CPP/Sources/Bin2CPPLib/Include/Generator.hpp @@ -6,9 +6,152 @@ *********************************************************************/ #ifndef BIN2CPP_GENERATOR_HPP #define BIN2CPP_GENERATOR_HPP +#include + +#include +#include +#include namespace Bin2CPP { +enum class MappingKey +{ + FILENAME, + GUARD_NAME, + NAMESPACE, + ARRAY_TYPE_INCLUDE, + ARRAY_TYPE, + ARRAY_SIZE, + ARRAY_NAME, + DATA +}; +class Generator +{ + public: + /** + * Constructor + * + * \param p_inputFile the Input file + */ + Generator(const std::string_view p_inputFile); + + Generator(const Generator& p_generator) = default; + Generator(Generator&& p_generator) = default; + + /** + * Set a mapping + * + */ + void SetMapping(const MappingKey p_key, const std::string_view p_value); + + /** + * Generate + * + * \return True if successful, false otherwise + */ + [[nodiscard]] + bool Generate(); + + /** + * Get + * + */ + [[nodiscard]] + std::string_view Get() const; + + ~Generator() = default; + + Generator& operator=(const Generator& p_generator) = default; + Generator& operator=(Generator&& p_generator) = default; + + private: + /** + * Compute the mappings + * + * \return True if all mappings have valid values, false otherwise + */ + [[nodiscard]] + bool ComputeMappings(); + + /** + * Compute the filename mapping + * + * \return True if success, false otherwise + */ + [[nodiscard]] + bool ComputeFilename(); + + /** + * Compute the guardName mapping + * + * \return True if success, false otherwise + */ + [[nodiscard]] + bool ComputeGuardName(); + + /** + * Compute the arrayTypeInclude mapping + * + * \return True if success, false otherwise + */ + [[nodiscard]] + bool ComputeArrayTypeInclude(); + + /** + * Compute the arrayType mapping + * + * \return True if success, false otherwise + */ + [[nodiscard]] + bool ComputeArrayType(); + + /** + * Compute the arrayName mapping + * + * \return True if success, false otherwise + */ + [[nodiscard]] + bool ComputeArrayName(); + + /** + * Compute the arraySize mapping + * + * \return True if success, false otherwise + */ + [[nodiscard]] + bool ComputeArraySize(const std::span p_data); + + /** + * Compute the data mapping + * + * \return True if success, false otherwise + */ + [[nodiscard]] + bool ComputeData(const std::span p_data); + + /** + * Validate generated is correct (no remaining tags) + * + * \return True if valid, false otherwise + */ + [[nodiscard]] + bool Validate(); + + /** + * The mapping table + */ + std::array()> m_mappingTable; + + /** + * The input file + */ + std::string m_inputFile; + + /** + * The result + */ + std::string m_result; +}; } // namespace Bin2CPP #endif diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp index 16f2a57..519bb72 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp +++ b/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp @@ -6,10 +6,9 @@ *********************************************************************/ #ifndef BIN2CPP_LOG_HPP #define BIN2CPP_LOG_HPP -#include #include -#include +#include #ifdef BIN2CPP_WINDOWS #pragma warning(disable: 4702) @@ -56,7 +55,7 @@ class Log /* * The sinks */ - eastl::array, 1> m_sinks; + std::array, 1> m_sinks; }; } // namespace Bin2CPP diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Singleton.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Singleton.hpp index 4f1a037..6eb4780 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/Include/Singleton.hpp +++ b/Bin2CPP/Sources/Bin2CPPLib/Include/Singleton.hpp @@ -6,7 +6,7 @@ *********************************************************************/ #ifndef BIN2CPP_SINGLETON_HPP #define BIN2CPP_SINGLETON_HPP -#include +#include namespace Bin2CPP { @@ -98,7 +98,7 @@ class Singleton /** * The singleton. */ - inline static eastl::optional ms_instance; + inline static std::optional ms_instance; }; } // namespace Bin2CPP #endif diff --git a/Bin2CPP/Tests/Bin2CPPLib/Generator.cpp b/Bin2CPP/Tests/Bin2CPPLib/Generator.cpp index e7e7dec..9823fc3 100644 --- a/Bin2CPP/Tests/Bin2CPPLib/Generator.cpp +++ b/Bin2CPP/Tests/Bin2CPPLib/Generator.cpp @@ -17,4 +17,123 @@ class GeneratorFixture: public ::testing::Test protected: Singleton::Lifetime m_lifetime; }; + +/****************************************************************************************/ + +TEST_F(GeneratorFixture, GenerateDefault) +{ + Generator generator("Fixture/toto.txt"); + EXPECT_TRUE(generator.Generate()); + + constexpr std::string_view expectedResult = R"(/** + * Auto-generated header from: toto.txt + * Generated by Bin2CPP + * + * DO NOT TOUCH + */ +#ifndef TOTO_TXT_HPP +#define TOTO_TXT_HPP +#include +#include + +namespace +{ + inline constexpr std::array g_toto_txt = { + std::byte{0x48}, std::byte{0x65}, std::byte{0x6C}, std::byte{0x6C}, std::byte{0x6F}, + std::byte{0x20}, std::byte{0x57}, std::byte{0x6F}, std::byte{0x72}, std::byte{0x6C}, + std::byte{0x64} + }; + +} // namespace + +#endif // TOTO_TXT_HPP +)"; + EXPECT_STREQ(expectedResult.data(), generator.Get().data()); +} + +/****************************************************************************************/ + +TEST_F(GeneratorFixture, GenerateNamespace) +{ + Generator generator("Fixture/toto.txt"); + generator.SetMapping(MappingKey::NAMESPACE, "Test"); + EXPECT_TRUE(generator.Generate()); + + constexpr std::string_view expectedResult = R"(/** + * Auto-generated header from: toto.txt + * Generated by Bin2CPP + * + * DO NOT TOUCH + */ +#ifndef TOTO_TXT_HPP +#define TOTO_TXT_HPP +#include +#include + +namespace Test +{ + inline constexpr std::array g_toto_txt = { + std::byte{0x48}, std::byte{0x65}, std::byte{0x6C}, std::byte{0x6C}, std::byte{0x6F}, + std::byte{0x20}, std::byte{0x57}, std::byte{0x6F}, std::byte{0x72}, std::byte{0x6C}, + std::byte{0x64} + }; + +} // namespace Test + +#endif // TOTO_TXT_HPP +)"; + EXPECT_STREQ(expectedResult.data(), generator.Get().data()); +} + +/****************************************************************************************/ + +TEST_F(GeneratorFixture, GenerateCustomArray) +{ + Generator generator("Fixture/toto.txt"); + generator.SetMapping(MappingKey::ARRAY_TYPE, "eastl::array"); + generator.SetMapping(MappingKey::ARRAY_TYPE_INCLUDE, ""); + generator.SetMapping(MappingKey::ARRAY_NAME, "g_myArray"); + EXPECT_TRUE(generator.Generate()); + + constexpr std::string_view expectedResult = R"(/** + * Auto-generated header from: toto.txt + * Generated by Bin2CPP + * + * DO NOT TOUCH + */ +#ifndef TOTO_TXT_HPP +#define TOTO_TXT_HPP +#include +#include + +namespace +{ + inline constexpr eastl::array g_myArray = { + std::byte{0x48}, std::byte{0x65}, std::byte{0x6C}, std::byte{0x6C}, std::byte{0x6F}, + std::byte{0x20}, std::byte{0x57}, std::byte{0x6F}, std::byte{0x72}, std::byte{0x6C}, + std::byte{0x64} + }; + +} // namespace + +#endif // TOTO_TXT_HPP +)"; + EXPECT_STREQ(expectedResult.data(), generator.Get().data()); +} + +/****************************************************************************************/ + +TEST_F(GeneratorFixture, NonExistentFile) +{ + Generator generator("Fixture/tata.txt"); + EXPECT_FALSE(generator.Generate()); +} + +/****************************************************************************************/ + +TEST_F(GeneratorFixture, Directory) +{ + Generator generator("Fixture/"); + EXPECT_FALSE(generator.Generate()); +} } // namespace Bin2CPP diff --git a/CMake/FindDependencies.cmake b/CMake/FindDependencies.cmake index 9f40144..a153e29 100644 --- a/CMake/FindDependencies.cmake +++ b/CMake/FindDependencies.cmake @@ -5,7 +5,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") find_package(Threads REQUIRED) endif() -find_package(EASTL REQUIRED) +find_package(magic_enum REQUIRED) find_package(CLI11 REQUIRED) find_package(quill REQUIRED) diff --git a/ConanProfiles/msvc b/ConanProfiles/msvc index f462118..0aafee5 100644 --- a/ConanProfiles/msvc +++ b/ConanProfiles/msvc @@ -15,7 +15,7 @@ tools.build:exelinkflags=["/LTCG", "/INCREMENTAL:NO"] tools.build:sharedlinkflags=["/LTCG", "/INCREMENTAL:NO"] tools.build:cflags=["/Zc:preprocessor", "/Zc:__STDC__", "/D_CRT_DECLARE_NONSTDC_NAMES=1", "/GL"] -tools.build:cxxflags=["/Zc:preprocessor", "/Zc:__cplusplus", "/Zc:enumTypes", "/Zc:templateScope", "/Zc:strictStrings", "/Zc:rvalueCast", "/Zc:hiddenFriend", "/Zc:externConstexpr", "/Zc:ternary", "/GL"] +tools.build:cxxflags=["/Zc:preprocessor", "/permissive-", "/Zc:__cplusplus", "/Zc:enumTypes", "/Zc:templateScope", "/Zc:throwingNew"] [tool_requires] !cmake/*: cmake/[>=4.2] diff --git a/ConanProfiles/msvcd b/ConanProfiles/msvcd index 74ff47a..9bdcd07 100644 --- a/ConanProfiles/msvcd +++ b/ConanProfiles/msvcd @@ -12,8 +12,7 @@ build_type=Debug tools.cmake.cmaketoolchain:user_toolchain+={{profile_dir}}/msvc_ccache.cmake tools.build:cflags=["/Zc:preprocessor", "/Zc:__STDC__", "/D_CRT_DECLARE_NONSTDC_NAMES=1"] -tools.build:cxxflags=["/Zc:preprocessor", "/Zc:__cplusplus", "/Zc:enumTypes", "/Zc:templateScope", "/Zc:strictStrings", "/Zc:rvalueCast", "/Zc:hiddenFriend", "/Zc:externConstexpr", "/Zc:ternary"] - +tools.build:cxxflags=["/Zc:preprocessor", "/permissive-", "/Zc:__cplusplus", "/Zc:enumTypes", "/Zc:templateScope", "/Zc:throwingNew"] [tool_requires] !cmake/*: cmake/[>=4.2] diff --git a/ConanProfiles/msvcd_asan b/ConanProfiles/msvcd_asan index 13ad410..d9bb8af 100644 --- a/ConanProfiles/msvcd_asan +++ b/ConanProfiles/msvcd_asan @@ -15,7 +15,7 @@ tools.build:exelinkflags=["/INCREMENTAL:NO"] tools.build:sharedlinkflags=["/INCREMENTAL:NO"] tools.build:cflags=["/Zc:preprocessor", "/Zc:__STDC__", "/D_CRT_DECLARE_NONSTDC_NAMES=1"] -tools.build:cxxflags=["/Zc:preprocessor", "/Zc:__cplusplus", "/Zc:enumTypes", "/Zc:templateScope", "/Zc:strictStrings", "/Zc:rvalueCast", "/Zc:hiddenFriend", "/Zc:externConstexpr", "/Zc:ternary"] +tools.build:cxxflags=["/Zc:preprocessor", "/permissive-", "/Zc:__cplusplus", "/Zc:enumTypes", "/Zc:templateScope", "/Zc:throwingNew"] [tool_requires] !cmake/*: cmake/[>=4.2] diff --git a/conanfile.py b/conanfile.py index 6893e79..be7f89b 100644 --- a/conanfile.py +++ b/conanfile.py @@ -45,7 +45,7 @@ class Bin2CPP(ConanFile): def requirements(self): self.requires("quill/11.0.2", transitive_headers=True) - self.requires("eastl/3.27.01@bigfootdev/main", transitive_headers=True) + self.requires("magic_enum/0.9.7", transitive_headers=True) self.requires("mimalloc/3.2.8@bigfootdev/main", transitive_headers=True) self.requires("cli11/2.6.1@bigfootdev/main") From 0977669bd5f67eb7ce8dd0b5e3d6f2a241f971a7 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sat, 28 Mar 2026 23:46:05 +0100 Subject: [PATCH 30/33] Packaging --- .gitea/workflows/package.yml | 55 ++ .../{Bin2CPPExe => Bin2CPP}/CMakeLists.txt | 6 +- .../Sources/{Bin2CPPExe => Bin2CPP}/main.cpp | 0 Bin2CPP/Sources/CMakeLists.txt | 2 +- CMake/Bin2CPPTargets.cmake | 23 + CMake/FindDependencies.cmake | 6 +- CMakeLists.txt | 5 +- Vendor/NatVis/EASTL/EASTL.natvis | 761 ------------------ conanfile.py | 28 +- test_package/CMakeLists.txt | 7 + test_package/conanfile.py | 18 + 11 files changed, 135 insertions(+), 776 deletions(-) create mode 100644 .gitea/workflows/package.yml rename Bin2CPP/Sources/{Bin2CPPExe => Bin2CPP}/CMakeLists.txt (95%) rename Bin2CPP/Sources/{Bin2CPPExe => Bin2CPP}/main.cpp (100%) create mode 100644 CMake/Bin2CPPTargets.cmake delete mode 100644 Vendor/NatVis/EASTL/EASTL.natvis create mode 100644 test_package/CMakeLists.txt create mode 100644 test_package/conanfile.py diff --git a/.gitea/workflows/package.yml b/.gitea/workflows/package.yml new file mode 100644 index 0000000..b64f5c9 --- /dev/null +++ b/.gitea/workflows/package.yml @@ -0,0 +1,55 @@ +name: Conan Packaging + +on: + push: + branches: + - '**' + workflow_dispatch: + +env: + CCACHE_BASEDIR: ${{ github.workspace }} + +jobs: + conan-packages: + runs-on: ubuntu-latest + timeout-minutes: 120 + container: + image: git.romainboullard.com/bigfootdev/linuxcppbuilder:main + env: + ARTIFACTORY_USER: ${{ secrets.ARTIFACTORY_USER }} + ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} + name: "Package Bin2CPP/1.0.0" + steps: + - name: Set BRANCH_NAME + run: echo "BRANCH_NAME=$(echo $GITHUB_REF_NAME | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + + - name: Install Node.js + run: apt-get update && apt-get install -y nodejs + + - name: Checkout repository + uses: actions/checkout@v6 + with: + submodules: recursive + + - name: Show ccache stats before + run: ccache --zero-stats + + - name: Run Conan packaging + run: | + echo "Building Bin2CPP@$1.0.0" + CONAN_LOGIN_USERNAME=${ARTIFACTORY_USER} \ + CONAN_PASSWORD=${ARTIFACTORY_PASSWORD} \ + conan create . \ + --version=1.0.0 \ + --user=bigfootdev \ + --channel=${{ env.BRANCH_NAME }} \ + -pr:b=./ConanProfiles/clang -pr:h=./ConanProfiles/clang \ + --build=missing --remote=bigfootpackages + + CONAN_LOGIN_USERNAME=${ARTIFACTORY_USER} \ + CONAN_PASSWORD=${ARTIFACTORY_PASSWORD} \ + conan upload Bin2CPP/1.0.0@bigfootdev/${{ env.BRANCH_NAME }} \ + --only-recipe --remote=bigfootpackages + + - name: Show ccache stats after + run: ccache --show-stats diff --git a/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt b/Bin2CPP/Sources/Bin2CPP/CMakeLists.txt similarity index 95% rename from Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt rename to Bin2CPP/Sources/Bin2CPP/CMakeLists.txt index 6b8e2d4..c72f1be 100644 --- a/Bin2CPP/Sources/Bin2CPPExe/CMakeLists.txt +++ b/Bin2CPP/Sources/Bin2CPP/CMakeLists.txt @@ -49,4 +49,8 @@ if(${ASAN}) COMMAND ${CMAKE_COMMAND} -E copy_if_different "${ASAN_DLL}" "$" ) endif() -endif() \ No newline at end of file +endif() + +########INSTALL + +install(TARGETS ${PROJECT_NAME} DESTINATION bin) \ No newline at end of file diff --git a/Bin2CPP/Sources/Bin2CPPExe/main.cpp b/Bin2CPP/Sources/Bin2CPP/main.cpp similarity index 100% rename from Bin2CPP/Sources/Bin2CPPExe/main.cpp rename to Bin2CPP/Sources/Bin2CPP/main.cpp diff --git a/Bin2CPP/Sources/CMakeLists.txt b/Bin2CPP/Sources/CMakeLists.txt index 81727b5..96c48ae 100644 --- a/Bin2CPP/Sources/CMakeLists.txt +++ b/Bin2CPP/Sources/CMakeLists.txt @@ -1,2 +1,2 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Bin2CPPLib) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Bin2CPPExe) \ No newline at end of file +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Bin2CPP) \ No newline at end of file diff --git a/CMake/Bin2CPPTargets.cmake b/CMake/Bin2CPPTargets.cmake new file mode 100644 index 0000000..9dfd8e6 --- /dev/null +++ b/CMake/Bin2CPPTargets.cmake @@ -0,0 +1,23 @@ +if(NOT TARGET Bin2CPP) + if(CMAKE_CROSSCOMPILING) + find_program(BIN2CPP_EXECUTABLE + NAMES Bin2CPP + PATHS ENV PATH + NO_DEFAULT_PATH + ) + else() + find_program(BIN2CPP_EXECUTABLE + NAMES Bin2CPP + PATHS "${CMAKE_CURRENT_LIST_DIR}" + NO_DEFAULT_PATH + ) + endif() + + if(BIN2CPP_EXECUTABLE) + get_filename_component(BIN2CPP_EXECUTABLE "${BIN2CPP_EXECUTABLE}" ABSOLUTE) + add_executable(Bin2CPP IMPORTED) + set_property(TARGET Bin2CPP PROPERTY IMPORTED_LOCATION ${BIN2CPP_EXECUTABLE}) + else() + message(WARNING "Bin2CPP executable not found in ${CMAKE_CURRENT_LIST_DIR}") + endif() +endif() diff --git a/CMake/FindDependencies.cmake b/CMake/FindDependencies.cmake index a153e29..d4c47b6 100644 --- a/CMake/FindDependencies.cmake +++ b/CMake/FindDependencies.cmake @@ -15,11 +15,7 @@ else() find_package(mimalloc REQUIRED) endif() -if(${IS_MULTI_CONFIG}) - find_package(cpptrace REQUIRED) -elseif(${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") - find_package(cpptrace REQUIRED) -endif() +find_package(cpptrace REQUIRED) if(BUILD_TESTS) find_package(GTest REQUIRED) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6041a4f..0fd5e87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,4 @@ SET(CMAKE_INSTALL_RPATH "\${ORIGIN}") add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Bin2CPP/Sources) if(${BUILD_TESTS}) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Bin2CPP/Tests) -endif() - -add_custom_target(NatVis SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/Vendor/NatVis/EASTL/EASTL.natvis) \ No newline at end of file +endif() \ No newline at end of file diff --git a/Vendor/NatVis/EASTL/EASTL.natvis b/Vendor/NatVis/EASTL/EASTL.natvis deleted file mode 100644 index e1ec96d..0000000 --- a/Vendor/NatVis/EASTL/EASTL.natvis +++ /dev/null @@ -1,761 +0,0 @@ - - - - - - - - ({(void*)mPair.mFirst} = {*mPair.mFirst}) - ({nullptr}) - - (void*)mPair.mFirst - *mPair.mFirst - - - - - ({(void*)mpValue} = {*mpValue}) - ({nullptr}) - - (void*)mpValue - *mpValue - mpRefCount->mRefCount - mpRefCount->mWeakRefCount - - - - - {((mpRefCount && mpRefCount->mRefCount) ? mpValue : nullptr)} - - mpRefCount && mpRefCount->mRefCount ? mpValue : nullptr - - - - - [{$T2}] {{}} - [{$T2}] {{ {*mValue} }} - [{$T2}] {{ {*mValue}, {*(mValue+1)} }} - [{$T2}] {{ {*mValue}, {*(mValue+1)}, {*(mValue+2)} }} - [{$T2}] {{ {*mValue}, {*(mValue+1)}, {*(mValue+2)}, {*(mValue+3)} }} - [{$T2}] {{ {*mValue}, {*(mValue+1)}, {*(mValue+2)}, {*(mValue+3)}, {*(mValue+4)} }} - [{$T2}] {{ {*mValue}, {*(mValue+1)}, {*(mValue+2)}, {*(mValue+3)}, {*(mValue+4)}, {*(mValue+5)} }} - [{$T2}] {{ {*mValue}, {*(mValue+1)}, {*(mValue+2)}, {*(mValue+3)}, {*(mValue+4)}, {*(mValue+5)}, ... }} - - $T2 - - $T2 - mValue - - - - - - "{mPair.mFirst.heap.mpBegin,sb}" - "{mPair.mFirst.sso.mData,sb}" - - mPair.mFirst.heap.mnSize - (mPair.mFirst.heap.mnCapacity & ~kHeapMask) - mPair.mFirst.heap.mpBegin,sb - - (SSOLayout::SSO_CAPACITY - mPair.mFirst.sso.mRemainingSizeField.mnRemainingSize) - SSOLayout::SSO_CAPACITY - mPair.mFirst.sso.mData,sb - - !!(mPair.mFirst.sso.mRemainingSizeField.mnRemainingSize & kSSOMask) - - - - - - {mPair.mFirst.heap.mpBegin,su} - {mPair.mFirst.sso.mData,su} - - mPair.mFirst.heap.mnSize - (mPair.mFirst.heap.mnCapacity & ~kHeapMask) - mPair.mFirst.heap.mpBegin,su - - (SSOLayout::SSO_CAPACITY - mPair.mFirst.sso.mRemainingSizeField.mnRemainingSize) - SSOLayout::SSO_CAPACITY - mPair.mFirst.sso.mData,su - - !!(mPair.mFirst.sso.mRemainingSizeField.mnRemainingSize & kSSOMask) - - - - - ({first}, {second}) - - first - second - - - - - [{mnSize}] {{}} - [{mnSize}] {{ {*mpData} }} - [{mnSize}] {{ {*mpData}, {*(mpData+1)} }} - [{mnSize}] {{ {*mpData}, {*(mpData+1)}, {*(mpData+2)} }} - [{mnSize}] {{ {*mpData}, {*(mpData+1)}, {*(mpData+2)}, {*(mpData+3)} }} - [{mnSize}] {{ {*mpData}, {*(mpData+1)}, {*(mpData+2)}, {*(mpData+3)}, {*(mpData+4)} }} - [{mnSize}] {{ {*mpData}, {*(mpData+1)}, {*(mpData+2)}, {*(mpData+3)}, {*(mpData+4)}, {*(mpData+5)} }} - [{mnSize}] {{ {*mpData}, {*(mpData+1)}, {*(mpData+2)}, {*(mpData+3)}, {*(mpData+4)}, {*(mpData+5)}, ... }} - - mnSize - - mnSize - mpData - - - - - - [{mpEnd - mpBegin}] {{}} - [{mpEnd - mpBegin}] {{ {*mpBegin} }} - [{mpEnd - mpBegin}] {{ {*mpBegin}, {*(mpBegin+1)} }} - [{mpEnd - mpBegin}] {{ {*mpBegin}, {*(mpBegin+1)}, {*(mpBegin+2)} }} - [{mpEnd - mpBegin}] {{ {*mpBegin}, {*(mpBegin+1)}, {*(mpBegin+2)}, {*(mpBegin+3)} }} - [{mpEnd - mpBegin}] {{ {*mpBegin}, {*(mpBegin+1)}, {*(mpBegin+2)}, {*(mpBegin+3)}, {*(mpBegin+4)} }} - [{mpEnd - mpBegin}] {{ {*mpBegin}, {*(mpBegin+1)}, {*(mpBegin+2)}, {*(mpBegin+3)}, {*(mpBegin+4)}, {*(mpBegin+5)} }} - [{mpEnd - mpBegin}] {{ {*mpBegin}, {*(mpBegin+1)}, {*(mpBegin+2)}, {*(mpBegin+3)}, {*(mpBegin+4)}, {*(mpBegin+5)}, ... }} - - mpEnd - mpBegin - mCapacityAllocator.mFirst - mpBegin - - mpEnd - mpBegin - mpBegin - - - - - - - [0] {{}} - - - [1] {{ {*mItBegin.mpCurrent} }} - - - [{(mItEnd.mpCurrentArrayPtr - mItBegin.mpCurrentArrayPtr) * $T3 + (mItEnd.mpCurrent-mItEnd.mpBegin) - (mItBegin.mpCurrent-mItBegin.mpBegin)}] - {{ - {*mItBegin.mpCurrent}, - ... - }} - - - (mItEnd.mpCurrentArrayPtr - mItBegin.mpCurrentArrayPtr) * $T3 + (mItEnd.mpCurrent-mItEnd.mpBegin) - (mItBegin.mpCurrent-mItBegin.mpBegin) - - (mItEnd.mpCurrentArrayPtr - mItBegin.mpCurrentArrayPtr) * $T3 + (mItEnd.mpCurrent-mItEnd.mpBegin) - (mItBegin.mpCurrent-mItBegin.mpBegin) - mItBegin.mpCurrentArrayPtr[(mItBegin.mpCurrent-mItBegin.mpBegin + $i) / $T3][(mItBegin.mpCurrent-mItBegin.mpBegin + $i) % $T3] - - - - - - {*mpCurrent} - - *mpCurrent - *(*(mpCurrentArrayPtr-1) + (mpEnd-mpBegin) - 1) - *(mpCurrent-1) - **(mpCurrentArrayPtr+1) - *(mpCurrent+1) - mpCurrent == mpBegin - mpCurrent+1 == mpEnd - - - - - - - {c} - - c - - - - - - [0] {{}} - - - [1] {{ {((eastl::ListNode<$T1>*)mNodeAllocator.mFirst.mpNext)->mValue} }} - - - [2] - {{ - {((eastl::ListNode<$T1>*)mNodeAllocator.mFirst.mpNext)->mValue}, - {((eastl::ListNode<$T1>*)mNodeAllocator.mFirst.mpNext->mpNext)->mValue} - }} - - - [?] - {{ - {((eastl::ListNode<$T1>*)mNodeAllocator.mFirst.mpNext)->mValue}, - {((eastl::ListNode<$T1>*)mNodeAllocator.mFirst.mpNext->mpNext)->mValue}, - ... - }} - - - - Content of lists will repeat indefinitely. Keep that in mind! - - - mNodeAllocator.mFirst.mpNext - mpNext - ((eastl::ListNode<$T1>*)this)->mValue - - - - - - {mValue} - - mValue - *(eastl::ListNode<$T1>*)mpNext - *(eastl::ListNode<$T1>*)mpPrev - - Content of lists will repeat indefinitely. Keep that in mind! - - - The rest of the list follows: - - - (eastl::ListNode<$T1>*)mpNext->mpNext - (eastl::ListNode<$T1>*)mpNext - mValue - - - - - - {*mpNode} - - *(eastl::ListNode<$T1>*)mpNode - - - - - - [0] {{}} - - - [1] - {{ - {((eastl::SListNode<$T1>*)mNode.mpNext)->mValue} - }} - - - [2] - {{ - {((eastl::SListNode<$T1>*)mNode.mpNext)->mValue}, - {((eastl::SListNode<$T1>*)mNode.mpNext->mpNext)->mValue} - }} - - - [?] - {{ - {((eastl::SListNode<$T1>*)mNode.mpNext)->mValue}, - {((eastl::SListNode<$T1>*)mNode.mpNext->mpNext)->mValue}, - ... - }} - - - - mNode.mpNext - mpNext - ((eastl::SListNode<$T1>*)this)->mValue - - - - - - {mValue} - - mValue - *(eastl::SListNode<$T1>*)mpNext - - The rest of the list follows: - - - mpNext == nullptr ? nullptr : (eastl::SListNode<$T1>*)mpNext->mpNext - (eastl::SListNode<$T1>*)mpNext - mValue - - - - - - {*mpNode} - - *(eastl::SListNode<$T1>*)mpNode - - - - - [0] {{}} - [1] {{ {mAnchor.mpNext} }} - [?] {{ {mAnchor.mpNext}, ... }} - - - Content of intrusive lists will repeat indefinitely. Keep that in mind! - - - mAnchor.mpNext - mpNext - *this - - - - - - {*($T1*)mpNode} - - *($T1*)mpNode - - - - - - - [0] {{}} - - - [1] - {{ - {((eastl::rbtree_node<$T1>*)mAnchor.mpNodeLeft)->mValue} - }} - - - [{mnSize}] - {{ - {((eastl::rbtree_node<$T1>*)mAnchor.mpNodeLeft)->mValue}, - ... - }} - - - mnSize - - mnSize - mAnchor.mpNodeParent - mpNodeLeft - mpNodeRight - ((eastl::rbtree_node<$T1>*)this)->mValue - - - - - - - [0] {{}} - - - [1] - {{ - {((eastl::rbtree_node<$T2>*)mAnchor.mpNodeLeft)->mValue} - }} - - - [{mnSize}] - {{ - {((eastl::rbtree_node<$T2>*)mAnchor.mpNodeLeft)->mValue}, - ... - }} - - - mnSize - - mnSize - mAnchor.mpNodeParent - mpNodeLeft - mpNodeRight - ((eastl::rbtree_node<$T2>*)this)->mValue - - - - - - {mValue} - - mValue - - It is possible to expand parents that do not exist. - - *(eastl::rbtree_node<$T1>*)mpNodeParent - *(eastl::rbtree_node<$T1>*)mpNodeLeft - *(eastl::rbtree_node<$T1>*)mpNodeRight - - - - - {*(eastl::rbtree_node<$T1>*)mpNode} - - *(eastl::rbtree_node<$T1>*)mpNode - - - - - - [{mnElementCount}] {{}} - [{mnElementCount}] {{ ... }} - - - mnBucketCount - mpBucketArray - - - - - - entry->mValue - - entry = entry->mpNext - - - bucketIndex++ - - entry = mpBucketArray[bucketIndex] - - - - - - - - - [{mnElementCount}] {{}} - [{mnElementCount}] {{ ... }} - - - - - - entry->mValue.second - - entry = entry->mpNext - - - bucketIndex++ - - entry = mpBucketArray[bucketIndex] - - - - - - - - {mValue}, {*mpNext} - {mValue} - - - - this - mpNext - mValue - - - - - - {mpNode->mValue} - - mpNode->mValue - - - - - {*(mIterator-1)} - - mIterator-1 - - - - - {{count = {kSize}}} - - kSize - - - - - - kSize - - - bBitValue = ((mWord[iWord] >> iBitInWord) % 2) != 0 ? true : false - bBitValue - iBitInWord++ - - iWord++ - iBitInWord = 0 - - - - - - - - {c} - - c - - - - - {mpBegin,[mnCount]} - mpBegin,[mnCount] - - - - ({mFirst}, {mSecond}) - ({mSecond}) - ({mFirst}) - (empty) - (empty) - ({mFirst}, {mSecond}) - - - - - nullopt - {value()} - - value() - - - - - {$T1} to {$T2}} - - - - - {mRep} nanoseconds - - - - {mRep} microseconds - - - - {mRep} milliseconds - - - - {mRep} seconds - - - - {mRep} minutes - - - - {mRep} hours - - - - {mRep} duration with ratio = [{$T2} : {$T3}] - - - - - - empty - {mInvokeFuncPtr} - - - - - {*val} - - - - - empty - {m_storage.external_storage} - - - - - {mAtomic} - - mAtomic - - - - - {mFlag.mAtomic} - - - - - [valueless_by_exception] - {{ index=0, value={($T1*)mStorage.mBuffer.mCharData}} - {{ index=1, value={($T2*)mStorage.mBuffer.mCharData}} - {{ index=2, value={($T3*)mStorage.mBuffer.mCharData}} - {{ index=3, value={($T4*)mStorage.mBuffer.mCharData}} - {{ index=4, value={($T5*)mStorage.mBuffer.mCharData}} - {{ index=5, value={($T6*)mStorage.mBuffer.mCharData}} - {{ index=6, value={($T7*)mStorage.mBuffer.mCharData}} - {{ index=7, value={($T8*)mStorage.mBuffer.mCharData}} - {{ index=8, value={($T9*)mStorage.mBuffer.mCharData}} - {{ index=9, value={($T10*)mStorage.mBuffer.mCharData}} - {{ index=10, value={($T11*)mStorage.mBuffer.mCharData}} - {{ index=11, value={($T12*)mStorage.mBuffer.mCharData}} - {{ index=12, value={($T13*)mStorage.mBuffer.mCharData}} - {{ index=13, value={($T14*)mStorage.mBuffer.mCharData}} - {{ index=14, value={($T15*)mStorage.mBuffer.mCharData}} - {{ index=15, value={($T16*)mStorage.mBuffer.mCharData}} - {{ index=16, value={($T17*)mStorage.mBuffer.mCharData}} - {{ index=17, value={($T18*)mStorage.mBuffer.mCharData}} - {{ index=18, value={($T19*)mStorage.mBuffer.mCharData}} - {{ index=19, value={($T20*)mStorage.mBuffer.mCharData}} - {{ index=20, value={($T21*)mStorage.mBuffer.mCharData}} - {{ index=21, value={($T22*)mStorage.mBuffer.mCharData}} - {{ index=22, value={($T23*)mStorage.mBuffer.mCharData}} - {{ index=23, value={($T24*)mStorage.mBuffer.mCharData}} - {{ index=24, value={($T25*)mStorage.mBuffer.mCharData}} - {{ index=25, value={($T26*)mStorage.mBuffer.mCharData}} - {{ index=26, value={($T27*)mStorage.mBuffer.mCharData}} - {{ index=27, value={($T28*)mStorage.mBuffer.mCharData}} - {{ index=28, value={($T29*)mStorage.mBuffer.mCharData}} - {{ index=29, value={($T30*)mStorage.mBuffer.mCharData}} - {{ index=30, value={($T31*)mStorage.mBuffer.mCharData}} - - index() - ($T1*)mStorage.mBuffer.mCharData - ($T2*)mStorage.mBuffer.mCharData - ($T3*)mStorage.mBuffer.mCharData - ($T4*)mStorage.mBuffer.mCharData - ($T5*)mStorage.mBuffer.mCharData - ($T6*)mStorage.mBuffer.mCharData - ($T7*)mStorage.mBuffer.mCharData - ($T8*)mStorage.mBuffer.mCharData - ($T9*)mStorage.mBuffer.mCharData - ($T10*)mStorage.mBuffer.mCharData - ($T11*)mStorage.mBuffer.mCharData - ($T12*)mStorage.mBuffer.mCharData - ($T13*)mStorage.mBuffer.mCharData - ($T14*)mStorage.mBuffer.mCharData - ($T15*)mStorage.mBuffer.mCharData - ($T16*)mStorage.mBuffer.mCharData - ($T17*)mStorage.mBuffer.mCharData - ($T18*)mStorage.mBuffer.mCharData - ($T19*)mStorage.mBuffer.mCharData - ($T20*)mStorage.mBuffer.mCharData - ($T21*)mStorage.mBuffer.mCharData - ($T22*)mStorage.mBuffer.mCharData - ($T23*)mStorage.mBuffer.mCharData - ($T24*)mStorage.mBuffer.mCharData - ($T25*)mStorage.mBuffer.mCharData - ($T26*)mStorage.mBuffer.mCharData - ($T27*)mStorage.mBuffer.mCharData - ($T28*)mStorage.mBuffer.mCharData - ($T29*)mStorage.mBuffer.mCharData - ($T30*)mStorage.mBuffer.mCharData - ($T31*)mStorage.mBuffer.mCharData - - - - - - - ({*this,view(noparens)}) - - - - - {(*((eastl::Internal::TupleLeaf<0,$T1,0>*)&mImpl)).mValue} - ({*this,view(noparens)}) - - (*((eastl::Internal::TupleLeaf<0,$T1,0>*)&mImpl)).mValue - - - - - {(*((eastl::Internal::TupleLeaf<0,$T1,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<1,$T2,0>*)&mImpl)).mValue} - ({*this,view(noparens)}) - - (*((eastl::Internal::TupleLeaf<0,$T1,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<1,$T2,0>*)&mImpl)).mValue - - - - - {(*((eastl::Internal::TupleLeaf<0,$T1,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<1,$T2,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<2,$T3,0>*)&mImpl)).mValue} - ({*this,view(noparens)}) - - (*((eastl::Internal::TupleLeaf<0,$T1,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<1,$T2,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<2,$T3,0>*)&mImpl)).mValue - - - - - {(*((eastl::Internal::TupleLeaf<0,$T1,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<1,$T2,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<2,$T3,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<3,$T4,0>*)&mImpl)).mValue} - ({*this,view(noparens)}) - - (*((eastl::Internal::TupleLeaf<0,$T1,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<1,$T2,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<2,$T3,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<3,$T4,0>*)&mImpl)).mValue - - - - - {(*((eastl::Internal::TupleLeaf<0,$T1,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<1,$T2,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<2,$T3,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<3,$T4,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<4,$T5,0>*)&mImpl)).mValue} - ({*this,view(noparens)}) - - (*((eastl::Internal::TupleLeaf<0,$T1,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<1,$T2,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<2,$T3,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<3,$T4,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<4,$T5,0>*)&mImpl)).mValue - - - - - {(*((eastl::Internal::TupleLeaf<0,$T1,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<1,$T2,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<2,$T3,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<3,$T4,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<4,$T5,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<5,$T6,0>*)&mImpl)).mValue} - ({*this,view(noparens)}) - - (*((eastl::Internal::TupleLeaf<0,$T1,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<1,$T2,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<2,$T3,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<3,$T4,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<4,$T5,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<5,$T6,0>*)&mImpl)).mValue - - - - - {(*((eastl::Internal::TupleLeaf<0,$T1,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<1,$T2,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<2,$T3,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<3,$T4,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<4,$T5,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<5,$T6,0>*)&mImpl)).mValue}, {(*((eastl::Internal::TupleLeaf<6,$T7,0>*)&mImpl)).mValue} - ({*this,view(noparens)}) - - (*((eastl::Internal::TupleLeaf<0,$T1,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<1,$T2,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<2,$T3,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<3,$T4,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<4,$T5,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<5,$T6,0>*)&mImpl)).mValue - (*((eastl::Internal::TupleLeaf<6,$T7,0>*)&mImpl)).mValue - - - - - diff --git a/conanfile.py b/conanfile.py index be7f89b..84bc3a1 100644 --- a/conanfile.py +++ b/conanfile.py @@ -6,7 +6,7 @@ import os required_conan_version = ">=1.33.0" class Bin2CPP(ConanFile): - name = "Bin2CPP" + name = "bin2cpp" homepage = "https://git.romainboullard.com/rboullard/Bin2CPP" description = "A utility that converts files to CPP headers" topics = ("utility") @@ -33,6 +33,11 @@ class Bin2CPP(ConanFile): generators = "CMakeDeps" + def export_sources(self): + copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder) + copy(self, os.path.join("Bin2CPP", "*"), self.recipe_folder, self.export_sources_folder) + copy(self, os.path.join("CMake", "*"), self.recipe_folder, self.export_sources_folder) + def layout(self): cmake_layout(self) @@ -49,8 +54,7 @@ class Bin2CPP(ConanFile): self.requires("mimalloc/3.2.8@bigfootdev/main", transitive_headers=True) self.requires("cli11/2.6.1@bigfootdev/main") - if(self.settings.build_type == "RelWithDebInfo" or self.settings.build_type == "Debug"): - self.requires("cpptrace/1.0.4", transitive_headers=True) + self.requires("cpptrace/1.0.4", transitive_headers=True) if(self.options.build_tests): self.test_requires("gtest/1.17.0") @@ -67,4 +71,20 @@ class Bin2CPP(ConanFile): def build(self): cmake = CMake(self) cmake.configure() - cmake.build() \ No newline at end of file + cmake.build() + + def package(self): + copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + cmake = CMake(self) + cmake.install() + + copy(self, "Bin2CPPTargets.cmake", + src=os.path.join(self.source_folder, "CMake"), + dst=os.path.join(self.package_folder, "bin")) + + @property + def _module_path(self): + return os.path.join("bin", "Bin2CPPTargets.cmake") + + def package_info(self): + self.cpp_info.set_property("cmake_build_modules", [self._module_path]) \ No newline at end of file diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt new file mode 100644 index 0000000..20ef5be --- /dev/null +++ b/test_package/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES C) + +find_package(Bin2CPP REQUIRED CONFIG) + +find_program(BIN2CPP_EXECUTABLE NAMES Bin2CPP) +execute_process(COMMAND ${BIN2CPP_EXECUTABLE} -h) diff --git a/test_package/conanfile.py b/test_package/conanfile.py new file mode 100644 index 0000000..c1dcff9 --- /dev/null +++ b/test_package/conanfile.py @@ -0,0 +1,18 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) + + def test(self): + self.run("Bin2CPP --help", env="conanrun") From ea533926459f3f4fff82318f4ff334536e2e0c4d Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sat, 28 Mar 2026 23:57:44 +0100 Subject: [PATCH 31/33] fix packaging --- .gitea/workflows/package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/package.yml b/.gitea/workflows/package.yml index b64f5c9..338b163 100644 --- a/.gitea/workflows/package.yml +++ b/.gitea/workflows/package.yml @@ -48,7 +48,7 @@ jobs: CONAN_LOGIN_USERNAME=${ARTIFACTORY_USER} \ CONAN_PASSWORD=${ARTIFACTORY_PASSWORD} \ - conan upload Bin2CPP/1.0.0@bigfootdev/${{ env.BRANCH_NAME }} \ + conan upload bin2cpp/1.0.0@bigfootdev/${{ env.BRANCH_NAME }} \ --only-recipe --remote=bigfootpackages - name: Show ccache stats after From b769357bd0edc902e280456dd6bbefc2647c436b Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 29 Mar 2026 01:57:48 +0100 Subject: [PATCH 32/33] logging disable by default --- Bin2CPP/Sources/Bin2CPP/main.cpp | 11 +++++---- Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp | 28 +++++++++++++++------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Bin2CPP/Sources/Bin2CPP/main.cpp b/Bin2CPP/Sources/Bin2CPP/main.cpp index f5bc1c9..add0981 100644 --- a/Bin2CPP/Sources/Bin2CPP/main.cpp +++ b/Bin2CPP/Sources/Bin2CPP/main.cpp @@ -5,15 +5,13 @@ int main(int argc, char** argv) { - Bin2CPP::Singleton::Lifetime loggerLifetime; - CLI::App app {"Bin2CPP allows you to generate a C++ header containing the binary content of an input file"}; argv = app.ensure_utf8(argv); std::string input; - app.add_option("-f,--input", input, "The input file")->required(); + app.add_option("-f,--input", input, "The input file"); std::string output; - app.add_option("-o,--output", output, "The output file")->required(); + app.add_option("-o,--output", output, "The output file"); std::optional arrayType; app.add_option("--arrayType", arrayType, "The type of the array"); std::optional arrayInclude; @@ -22,9 +20,14 @@ int main(int argc, char** argv) app.add_option("--arrayName", arrayName, "The array name"); std::optional customNamespace; app.add_option("--namespace", customNamespace, "The namespace"); + bool verbose = false; + app.add_option("--verbose", verbose, "Activate logging"); CLI11_PARSE(app, argc, argv); + std::unique_ptr::Lifetime> loggerLifetime = + verbose ? std::make_unique::Lifetime>() : nullptr; + Bin2CPP::Generator generator(input); if (arrayType) { diff --git a/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp b/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp index 519bb72..d9a3ab2 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp +++ b/Bin2CPP/Sources/Bin2CPPLib/Include/Log.hpp @@ -80,36 +80,48 @@ class Log #define BIN2CPP_LOG_INFO(fmt, ...) \ do \ { \ - if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + if (Bin2CPP::Singleton::HasInstance()) \ { \ - QUILL_LOG_INFO(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + { \ + QUILL_LOG_INFO(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ } \ } while (0) #define BIN2CPP_LOG_WARN(fmt, ...) \ do \ { \ - if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + if (Bin2CPP::Singleton::HasInstance()) \ { \ - QUILL_LOG_WARNING(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + { \ + QUILL_LOG_WARNING(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ } \ } while (0) #define BIN2CPP_LOG_ERROR(fmt, ...) \ do \ { \ - if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + if (Bin2CPP::Singleton::HasInstance()) \ { \ - QUILL_LOG_ERROR(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + { \ + QUILL_LOG_ERROR(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ } \ } while (0) #define BIN2CPP_LOG_FATAL(fmt, ...) \ do \ { \ - if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + if (Bin2CPP::Singleton::HasInstance()) \ { \ - QUILL_LOG_CRITICAL(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + if (quill::Logger* logger = Bin2CPP::Singleton::Instance().GetLogger()) \ + { \ + QUILL_LOG_CRITICAL(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \ + } \ } \ } while (0) #endif From f322ce365552a858fca7a8ef7774ee641d2a2ab7 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 29 Mar 2026 03:12:16 +0200 Subject: [PATCH 33/33] Fix no error message on fail --- Bin2CPP/Sources/Bin2CPP/main.cpp | 27 +++++++++++++----------- Bin2CPP/Sources/Bin2CPPLib/Generator.cpp | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Bin2CPP/Sources/Bin2CPP/main.cpp b/Bin2CPP/Sources/Bin2CPP/main.cpp index add0981..d948838 100644 --- a/Bin2CPP/Sources/Bin2CPP/main.cpp +++ b/Bin2CPP/Sources/Bin2CPP/main.cpp @@ -9,9 +9,9 @@ int main(int argc, char** argv) argv = app.ensure_utf8(argv); std::string input; - app.add_option("-f,--input", input, "The input file"); + app.add_option("-f,--input", input, "The input file")->required(); std::string output; - app.add_option("-o,--output", output, "The output file"); + app.add_option("-o,--output", output, "The output file")->required(); std::optional arrayType; app.add_option("--arrayType", arrayType, "The type of the array"); std::optional arrayInclude; @@ -46,19 +46,22 @@ int main(int argc, char** argv) generator.SetMapping(Bin2CPP::MappingKey::NAMESPACE, customNamespace.value()); } - if (generator.Generate()) + if (!generator.Generate()) { - std::ofstream out(output); - if (!out) - { - BIN2CPP_LOG_ERROR("Failed to open '{}'", output); - return 1; - } - - out << generator.Get(); - out.close(); + BIN2CPP_LOG_ERROR("Failed to generate '{}'", input); + return 1; } + std::ofstream out(output); + if (!out) + { + BIN2CPP_LOG_ERROR("Failed to open '{}'", output); + return 1; + } + + out << generator.Get(); + out.close(); + BIN2CPP_LOG_INFO("'{}' Generated !", output); return 0; diff --git a/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp b/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp index 547cef6..1b7e190 100644 --- a/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp +++ b/Bin2CPP/Sources/Bin2CPPLib/Generator.cpp @@ -240,7 +240,7 @@ bool Generator::ComputeData(const std::span p_data) std::string& value = m_mappingTable[magic_enum::enum_index(MappingKey::DATA).value()]; value.clear(); - constexpr std::size_t bytesPerLine = 5; + constexpr std::size_t bytesPerLine = 16; constexpr std::string_view linePrefix = "\n "; for (std::size_t i = 0; i < p_data.size(); ++i)