From 1f40fef9711a9f5365412411bb9f2a37c86f1330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaim=20=28Jo=C3=ABl=20Lamotte=29?= <142265+Klaim@users.noreply.github.com> Date: Wed, 23 Jul 2025 12:42:22 +0200 Subject: [PATCH] homebrew workaround attempt --- .../include/mamba/util/synchronized_value.hpp | 7 +--- libmamba/src/core/logging.cpp | 32 +++++++++++++++++-- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/libmamba/include/mamba/util/synchronized_value.hpp b/libmamba/include/mamba/util/synchronized_value.hpp index ef3c98706..8f99ca319 100644 --- a/libmamba/include/mamba/util/synchronized_value.hpp +++ b/libmamba/include/mamba/util/synchronized_value.hpp @@ -546,12 +546,7 @@ namespace mamba::util /////////////////////////////////////////////////////////////////////////////////////////// template - constexpr synchronized_value::synchronized_value( - ) noexcept(std::is_nothrow_default_constructible_v) - { - // NOTE: non-defaulted because of homebrew/clang compiler not liking the defaulted version - // for some reason - } + constexpr synchronized_value::synchronized_value() noexcept(std::is_nothrow_default_constructible_v) = default; template synchronized_value::synchronized_value(T value) noexcept diff --git a/libmamba/src/core/logging.cpp b/libmamba/src/core/logging.cpp index 71624a4ec..9d2b1dc4a 100644 --- a/libmamba/src/core/logging.cpp +++ b/libmamba/src/core/logging.cpp @@ -128,7 +128,33 @@ namespace mamba::logging { constinit std::atomic message_logger_use_buffer; - using MessageLoggerBuffer = std::vector; + // NOTE: this looks complicated because it's a workaround `std::vector` implementations + // which are not `constexpr` (required by c++20), we defer the vector creation to the moment it's needed. + // Constexpr constructor is required for a type which is usable in a `constinit` declaration, + // which is required to avoid the static-initialization-fiasco (at least for initialization). + struct MessageLoggerBuffer + { + using buffer = std::vector; + + constexpr MessageLoggerBuffer() = default; + + template + auto push_back(T&& record) + { + return ready_records().push_back(std::forward(record)); + } + + auto ready_records() -> buffer& + { + if (not records) + { + records = buffer{}; + } + return *records; + } + + std::optional records; + }; constinit util::synchronized_value message_logger_buffer; auto @@ -193,8 +219,8 @@ namespace mamba::logging void MessageLogger::print_buffer(std::ostream& /*ostream*/) { - MessageLoggerBuffer tmp; - message_logger_buffer->swap(tmp); + MessageLoggerBuffer::buffer tmp; + message_logger_buffer->ready_records().swap(tmp); for (auto& log_record : tmp) {