diff --git a/packages/biu/CMakeLists.txt b/packages/biu/CMakeLists.txt index caf5108f..f4ac4728 100644 --- a/packages/biu/CMakeLists.txt +++ b/packages/biu/CMakeLists.txt @@ -13,8 +13,7 @@ endif() find_package(magic_enum REQUIRED) find_package(fmt REQUIRED) -find_package(Boost REQUIRED COMPONENTS headers iostreams filesystem system process stacktrace_from_exception - stacktrace_backtrace) +find_package(Boost REQUIRED COMPONENTS headers iostreams filesystem system process) find_package(range-v3 REQUIRED) find_path(NAMEOF_INCLUDE_DIR nameof.hpp REQUIRED) find_package(Eigen3 REQUIRED) @@ -22,13 +21,12 @@ set(HIGHFIVE_FIND_HDF5 Off) find_package(HighFive REQUIRED) find_path(ZPP_BITS_INCLUDE_DIR zpp_bits.h REQUIRED) find_package(TgBot REQUIRED) -find_path(LIBBACKTRACE_INCLUDE_DIR backtrace.h REQUIRED) -find_library(LIBBACKTRACE_LIBRARY NAMES backtrace REQUIRED) find_package(HDF5 REQUIRED) find_package(concurrencpp REQUIRED) find_path(POCKETFFT_INCLUDE_DIR pocketfft.h REQUIRED) find_package(yaml-cpp REQUIRED) find_package(glaze REQUIRED) +find_package(cpptrace REQUIRED) add_library(biu src/common.cpp src/hdf5.cpp src/string.cpp) target_include_directories(biu PUBLIC $ @@ -36,7 +34,7 @@ target_include_directories(biu PUBLIC $ -# define BOOST_STACKTRACE_USE_BACKTRACE -# include # include namespace biu @@ -85,12 +83,6 @@ namespace biu public: [[gnu::always_inline]] inline void error(const std::string& message) const; public: [[gnu::always_inline]] inline void info(const std::string& message) const; public: [[gnu::always_inline]] inline void debug(const std::string& message) const; - - public: [[gnu::always_inline]] inline void print_exception - ( - std::optional> type_and_message, - const boost::stacktrace::stacktrace& stacktrace - ) const; }; friend class Guard; diff --git a/packages/biu/include/biu/logger.tpp b/packages/biu/include/biu/logger.tpp index aa9830f0..e8dfacd5 100644 --- a/packages/biu/include/biu/logger.tpp +++ b/packages/biu/include/biu/logger.tpp @@ -5,6 +5,8 @@ # include # include # include +# include +# include namespace biu { @@ -70,8 +72,12 @@ namespace biu catch (...) { log.error(boost::current_exception_diagnostic_information()); - log.print_exception - (std::nullopt, boost::stacktrace::stacktrace::from_current_exception()); + if (auto&& lock = LoggerConfig_.lock(); lock->Level >= Logger::Level::Error) + { + static_assert(std::same_as); + cpptrace::from_current_exception().print(*lock->Stream); + *lock->Stream << std::flush; + } } } @@ -117,13 +123,13 @@ namespace biu { static_assert(std::same_as); auto time = std::chrono::time_point_cast(std::chrono::system_clock::now()); - boost::stacktrace::stacktrace stack; + auto frame = cpptrace::stacktrace::current(0, 1).frames[0]; # ifdef BIU_LOGGER_SOURCE_ROOT auto source_root = std::string_view(BIU_LOGGER_SOURCE_ROOT "/"); - auto source_file = stack[0].source_file().starts_with(source_root) ? - stack[0].source_file().substr(source_root.size()) : stack[0].source_file(); + auto source_file = frame.filename.starts_with(source_root) ? + frame.filename.substr(source_root.size()) : frame.filename; # else - auto source_file = stack[0].source_file(); + auto source_file = frame.filename; # endif *lock->Stream << "[ {:%T} {:02x} {:02} ] {} (at {}:{} {} )\n"_f ( @@ -132,8 +138,8 @@ namespace biu Indent_, message, source_file.empty() ? "??"s : source_file, - stack[0].source_line() == 0 ? "??"s : "{}"_f(stack[0].source_line()), - stack[0].name() + frame.line.has_value() ? "{}"_f(frame.line.value()) : "??"s, + frame.symbol ) << std::flush; } } @@ -147,26 +153,5 @@ namespace biu return std::forward(value); } - inline void Logger::Guard::print_exception - ( - std::optional> type_and_message, - const boost::stacktrace::stacktrace& stacktrace - ) const - { - if (type_and_message) log("{}: {}"_f(type_and_message->first, type_and_message->second)); - if (auto&& lock = LoggerConfig_.lock(); lock->Level >= Logger::Level::Error) - { - static_assert(std::same_as); - for (auto frame : stacktrace) - *lock->Stream << "\tfrom {}:{} {}\n"_f - ( - frame.source_file().empty() ? "??"s : frame.source_file(), - frame.source_line() == 0 ? "??"s : "{}"_f(frame.source_line()), - frame.name() - ); - *lock->Stream << std::flush; - } - } - inline Atomic> Logger::Threads_; } diff --git a/packages/default.nix b/packages/default.nix index f57a45cb..aa8af521 100644 --- a/packages/default.nix +++ b/packages/default.nix @@ -68,8 +68,7 @@ inputs: rec # TODO: report glaze bug to upstream inherit (inputs.pkgs.pkgs-2411) glaze; stdenv = inputs.pkgs.clang18Stdenv; - boost = (inputs.pkgs.boost188.override { extraB2Args = [ "boost.stacktrace.backtrace=on" ]; }).overrideAttrs - (prev: { buildInputs = prev.buildInputs ++ [(inputs.pkgs.libbacktrace.override { enableStatic = true; })]; }); + boost = inputs.pkgs.boost188; fmt = inputs.pkgs.fmt_11.overrideAttrs (prev: { patches = prev.patches or [] ++ [ ./biu/fmt.patch ]; }); }; hpcstat = inputs.pkgs.callPackage ./hpcstat