Skip to content

Commit 0535c24

Browse files
lgritzscott-wilson
authored andcommitted
build: Remove boost::stacktrace (AcademySoftwareFoundation#4222)
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. We can also add it back if somebody has an alternate suggestion for a 3rd party solution that is a simply drop-in replacement, portable, lightweight dependency, with compatible license. A good compromise might be this one: https://github.com/jeremy-rifkin/cpptrace But I think what I'm proposing is that we accept this PR first, get rid of boost, then we can come back to looking at cpptrace as potentially a way to restore the functionality prior to C++23. Signed-off-by: Larry Gritz <lg@larrygritz.com> Signed-off-by: Scott Wilson <scott@propersquid.com>
1 parent 216c68e commit 0535c24

File tree

5 files changed

+33
-25
lines changed

5 files changed

+33
-25
lines changed

src/build-scripts/gh-win-installdeps.bash

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ echo "---------------"
5151
time vcpkg install boost-container:x64-windows
5252
time vcpkg install boost-filesystem:x64-windows
5353
time vcpkg install boost-math:x64-windows
54-
time vcpkg install boost-stacktrace:x64-windows
5554
time vcpkg install boost-system:x64-windows
5655
time vcpkg install boost-thread:x64-windows
5756

src/cmake/externalpackages.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ endif ()
7878
include_directories (SYSTEM "${Boost_INCLUDE_DIRS}")
7979
link_directories ("${Boost_LIBRARY_DIRS}")
8080

81-
option (OIIO_DISABLE_BOOST_STACKTRACE "Disable use of Boost stacktrace." OFF)
82-
8381
# end Boost setup
8482
###########################################################################
8583

src/include/OpenImageIO/sysutil.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,17 @@ OIIO_API size_t
110110
max_open_files();
111111

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

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

src/libutil/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ function (setup_oiio_util_library targetname)
6161
# ${CMAKE_DL_LIBS}
6262
)
6363

64+
if (GCC_VERSION VERSION_GREATER_EQUAL 12.0
65+
AND CMAKE_CXX_STANDARD VERSION_GREATER_EQUAL 23)
66+
target_link_libraries (${targetname}
67+
PRIVATE stdc++_libbacktrace)
68+
endif ()
69+
6470
if (INTERNALIZE_FMT OR OIIO_USING_FMT_LOCAL)
6571
add_dependencies(${targetname} fmt_internal_target)
6672
else ()

src/libutil/sysutil.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,14 @@
6161
#endif
6262

6363
#include <OpenImageIO/dassert.h>
64+
#include <OpenImageIO/filesystem.h>
6465
#include <OpenImageIO/strutil.h>
6566
#include <OpenImageIO/sysutil.h>
6667
#include <OpenImageIO/ustring.h>
6768

68-
#include <boost/version.hpp>
69-
#if BOOST_VERSION >= 106500
70-
# ifndef _GNU_SOURCE
71-
# define _GNU_SOURCE
72-
# endif
73-
# if !defined(OIIO_DISABLE_BOOST_STACKTRACE)
74-
# include <boost/stacktrace.hpp>
75-
# endif
69+
#if __has_include(<stacktrace>) && __cpp_lib_stacktrace >= 202011L
70+
# include <stacktrace>
71+
# define HAVE_STACKTRACE 1
7672
#endif
7773

7874
OIIO_INTEL_PRAGMA(warning disable 2196)
@@ -646,12 +642,21 @@ aligned_free(void* ptr)
646642

647643

648644

645+
// Notes on stacktrace:
646+
//
647+
// To shed the boost dependency, we are disabling stacktrace for now. It's not
648+
// vital and probably not worth keeping boost just for that.
649+
//
650+
// C++23 has std::stacktrace, so as compilers add support for this, we will
651+
// phase it back in.
652+
653+
649654
std::string
650655
Sysutil::stacktrace()
651656
{
652-
#if BOOST_VERSION >= 106500 && !defined(OIIO_DISABLE_BOOST_STACKTRACE)
657+
#ifdef HAVE_STACKTRACE
653658
std::stringstream out;
654-
out << boost::stacktrace::stacktrace();
659+
out << std::stacktrace::current();
655660
return out.str();
656661
#else
657662
return "";
@@ -660,8 +665,7 @@ Sysutil::stacktrace()
660665

661666

662667

663-
#if BOOST_VERSION >= 106500 && !defined(OIIO_DISABLE_BOOST_STACKTRACE)
664-
668+
#ifdef HAVE_STACKTRACE
665669
static std::string stacktrace_filename;
666670
static std::mutex stacktrace_filename_mutex;
667671

@@ -675,29 +679,28 @@ stacktrace_signal_handler(int signum)
675679
else if (stacktrace_filename == "stderr")
676680
std::cerr << Sysutil::stacktrace();
677681
else {
678-
# if BOOST_VERSION >= 106500 && !defined(OIIO_DISABLE_BOOST_STACKTRACE)
679-
boost::stacktrace::safe_dump_to(stacktrace_filename.c_str());
680-
# endif
682+
Filesystem::write_text_file(stacktrace_filename,
683+
Sysutil::stacktrace());
681684
}
682685
}
683686
::raise(SIGABRT);
684687
}
685-
686688
#endif
687689

688690

689691

690692
bool
691693
Sysutil::setup_crash_stacktrace(string_view filename)
692694
{
693-
#if BOOST_VERSION >= 106500 && !defined(OIIO_DISABLE_BOOST_STACKTRACE)
695+
#ifdef HAVE_STACKTRACE
694696
std::lock_guard<std::mutex> lock(stacktrace_filename_mutex);
695697
stacktrace_filename = filename;
696698
::signal(SIGSEGV, &stacktrace_signal_handler);
697699
::signal(SIGABRT, &stacktrace_signal_handler);
698700
return true;
699-
#endif
701+
#else
700702
return false;
703+
#endif
701704
}
702705

703706

0 commit comments

Comments
 (0)