revert: remove stacktrace feature for rust panic.

- remove stacktrace feature for rust panic function due to not all STL are ready for this.
- add more os type in CMake file.
- add lost header in fopen.
This commit is contained in:
2025-08-19 21:47:21 +08:00
parent d52630ac5c
commit 244e39c4d1
3 changed files with 10 additions and 13 deletions

View File

@ -100,7 +100,9 @@ PUBLIC
# OS macro
$<$<PLATFORM_ID:Windows>:YYCC_OS_WINDOWS>
$<$<PLATFORM_ID:Linux>:YYCC_OS_LINUX>
$<$<PLATFORM_ID:Android>:YYCC_OS_LINUX> # We brutally think Android as Linux.
$<$<PLATFORM_ID:Darwin>:YYCC_OS_MACOS>
$<$<PLATFORM_ID:iOS>:YYCC_OS_MACOS> # We brutally think iOS as macOS.
# Compiler macro
$<$<CXX_COMPILER_ID:GNU>:YYCC_CC_GCC>
$<$<CXX_COMPILER_ID:Clang>:YYCC_CC_CLANG>
@ -133,15 +135,6 @@ PUBLIC
$<$<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(TARGETS YYCCommonplace
EXPORT YYCCommonplaceTargets

View File

@ -1,5 +1,6 @@
#pragma once
#include <memory>
#include <cstdio>
namespace yycc::patch::fopen {

View File

@ -4,13 +4,19 @@
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <stacktrace>
#define TERMCOLOR ::yycc::carton::termcolor
#define REINTERPRET ::yycc::string::reinterpret
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::string_view& msg) {
// Output message in stderr.
auto& dst = std::cerr;
@ -22,9 +28,6 @@ namespace yycc::rust::panic {
dst << "program paniked at " << std::quoted(file) << ":Ln" << line << std::endl;
// User custom message
dst << "note: " << msg << std::endl;
// Stacktrace message if we support it.
dst << "stacktrace: " << std::endl;
dst << std::stacktrace::current() << std::endl;
// Restore color
dst << REINTERPRET::as_ordinary_view(TERMCOLOR::reset());;