1
0

revert: revert the delete of std::stacktrace in rust panic.

- i revert previous changes because currently code have not been compiled in clang.
This commit is contained in:
2025-09-28 22:02:54 +08:00
parent 6ecf6935d8
commit 31c624797f
2 changed files with 13 additions and 7 deletions

View File

@ -157,6 +157,15 @@ PUBLIC
$<$<CXX_COMPILER_ID:MSVC>:/Zc:__cplusplus> $<$<CXX_COMPILER_ID:MSVC>:/Zc:__cplusplus>
) )
# Fix GCC std::stacktrace link error
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14)
target_link_libraries(YYCCommonplace PRIVATE stdc++exp)
else ()
target_link_libraries(YYCCommonplace PRIVATE stdc++_libbacktrace)
endif ()
endif ()
# Install binary and headers # Install binary and headers
install(TARGETS YYCCommonplace install(TARGETS YYCCommonplace
EXPORT YYCCommonplaceTargets EXPORT YYCCommonplaceTargets

View File

@ -4,6 +4,7 @@
#include <cstdlib> #include <cstdlib>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <stacktrace>
#define TERMCOLOR ::yycc::carton::termcolor #define TERMCOLOR ::yycc::carton::termcolor
@ -11,13 +12,6 @@ using namespace yycc::patch::stream;
namespace yycc::rust::panic { namespace yycc::rust::panic {
// TODO:
// I sadly remove the stacktrace feature for panic function.
// Because in GCC, it has link error (can be fixed by extra link option).
// In Clang, it even lack the whole header file.
// It seems that STL providers are not ready for this feature. So I decide remove it entirely.
// Once every STL probiders have ready for this, I will add it back.
void panic(const char* file, int line, const std::u8string_view& msg) { void panic(const char* file, int line, const std::u8string_view& msg) {
// Output message in stderr. // Output message in stderr.
auto& dst = std::cerr; auto& dst = std::cerr;
@ -29,6 +23,9 @@ namespace yycc::rust::panic {
dst << "program paniked at " << std::quoted(file) << ":Ln" << line << std::endl; dst << "program paniked at " << std::quoted(file) << ":Ln" << line << std::endl;
// User custom message // User custom message
dst << "note: " << msg << std::endl; dst << "note: " << msg << std::endl;
// Stacktrace message if we support it.
dst << "stacktrace: " << std::endl;
dst << std::stacktrace::current() << std::endl;
// Restore color // Restore color
dst << TERMCOLOR::reset(); dst << TERMCOLOR::reset();