Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Remove boost::stacktrace #4222

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/build-scripts/gh-win-installdeps.bash
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ echo "---------------"
time vcpkg install boost-container:x64-windows
time vcpkg install boost-filesystem:x64-windows
time vcpkg install boost-math:x64-windows
time vcpkg install boost-stacktrace:x64-windows
time vcpkg install boost-system:x64-windows
time vcpkg install boost-thread:x64-windows

Expand Down
2 changes: 0 additions & 2 deletions src/cmake/externalpackages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ endif ()
include_directories (SYSTEM "${Boost_INCLUDE_DIRS}")
link_directories ("${Boost_LIBRARY_DIRS}")

option (OIIO_DISABLE_BOOST_STACKTRACE "Disable use of Boost stacktrace." OFF)

# end Boost setup
###########################################################################

Expand Down
10 changes: 6 additions & 4 deletions src/include/OpenImageIO/sysutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,17 @@ OIIO_API size_t
max_open_files();

/// Return a string containing a readable stack trace from the point where
/// it was called. Return an empty string if not supported on this platform.
/// it was called. Return an empty string if not supported on this platform
/// or this build of OpenImageIO.
OIIO_API std::string
stacktrace();

/// Turn on automatic stacktrace dump to the named file if the program
/// crashes. Return true if this is properly set up, false if it is not
/// possible on this platform. The name may be "stdout" or "stderr" to
/// merely print the trace to stdout or stderr, respectively. If the name
/// is "", it will disable the auto-stacktrace printing.
/// possible on this platform or with this build of OpenImageIO. The name may
/// be "stdout" or "stderr" to merely print the trace to stdout or stderr,
/// respectively. If the name is "", it will disable the auto-stacktrace
/// printing.
OIIO_API bool
setup_crash_stacktrace(string_view filename);

Expand Down
6 changes: 6 additions & 0 deletions src/libutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ function (setup_oiio_util_library targetname)
# ${CMAKE_DL_LIBS}
)

if (GCC_VERSION VERSION_GREATER_EQUAL 12.0
AND CMAKE_CXX_STANDARD VERSION_GREATER_EQUAL 23)
target_link_libraries (${targetname}
PRIVATE stdc++_libbacktrace)
endif ()

if (INTERNALIZE_FMT OR OIIO_USING_FMT_LOCAL)
add_dependencies(${targetname} fmt_internal_target)
else ()
Expand Down
39 changes: 21 additions & 18 deletions src/libutil/sysutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,14 @@
#endif

#include <OpenImageIO/dassert.h>
#include <OpenImageIO/filesystem.h>
#include <OpenImageIO/strutil.h>
#include <OpenImageIO/sysutil.h>
#include <OpenImageIO/ustring.h>

#include <boost/version.hpp>
#if BOOST_VERSION >= 106500
# ifndef _GNU_SOURCE
# define _GNU_SOURCE
# endif
# if !defined(OIIO_DISABLE_BOOST_STACKTRACE)
# include <boost/stacktrace.hpp>
# endif
#if __has_include(<stacktrace>) && __cpp_lib_stacktrace >= 202011L
# include <stacktrace>
# define HAVE_STACKTRACE 1
#endif

OIIO_INTEL_PRAGMA(warning disable 2196)
Expand Down Expand Up @@ -646,12 +642,21 @@ aligned_free(void* ptr)



// Notes on stacktrace:
//
// To shed the boost dependency, we are disabling stacktrace for now. It's not
// vital and probably not worth keeping boost just for that.
//
// C++23 has std::stacktrace, so as compilers add support for this, we will
// phase it back in.


std::string
Sysutil::stacktrace()
{
#if BOOST_VERSION >= 106500 && !defined(OIIO_DISABLE_BOOST_STACKTRACE)
#ifdef HAVE_STACKTRACE
std::stringstream out;
out << boost::stacktrace::stacktrace();
out << std::stacktrace::current();
return out.str();
#else
return "";
Expand All @@ -660,8 +665,7 @@ Sysutil::stacktrace()



#if BOOST_VERSION >= 106500 && !defined(OIIO_DISABLE_BOOST_STACKTRACE)

#ifdef HAVE_STACKTRACE
static std::string stacktrace_filename;
static std::mutex stacktrace_filename_mutex;

Expand All @@ -675,29 +679,28 @@ stacktrace_signal_handler(int signum)
else if (stacktrace_filename == "stderr")
std::cerr << Sysutil::stacktrace();
else {
# if BOOST_VERSION >= 106500 && !defined(OIIO_DISABLE_BOOST_STACKTRACE)
boost::stacktrace::safe_dump_to(stacktrace_filename.c_str());
# endif
Filesystem::write_text_file(stacktrace_filename,
Sysutil::stacktrace());
}
}
::raise(SIGABRT);
}

#endif



bool
Sysutil::setup_crash_stacktrace(string_view filename)
{
#if BOOST_VERSION >= 106500 && !defined(OIIO_DISABLE_BOOST_STACKTRACE)
#ifdef HAVE_STACKTRACE
std::lock_guard<std::mutex> lock(stacktrace_filename_mutex);
stacktrace_filename = filename;
::signal(SIGSEGV, &stacktrace_signal_handler);
::signal(SIGABRT, &stacktrace_signal_handler);
return true;
#endif
#else
return false;
#endif
}


Expand Down
Loading