Skip to content
Open
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
20 changes: 19 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,28 @@ jobs:
make -j"$(nproc)"
make install

- name: Run modules tests
if: ${{matrix.toolset == 'clang-19'}}
run: |
cd ../boost-root/libs/$LIBRARY
cmake -S test/cmake_subdir_test \
-B build_module \
-GNinja \
-DBOOST_USE_MODULES=1 \
-DBUILD_TESTING=1 \
-DCMAKE_CXX_STANDARD=23 \
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} \
-DCMAKE_CXX_FLAGS="-stdlib=libc++ -I$HOME/.local/include" \
-DCMAKE_EXE_LINKER_FLAGS="-L$HOME/.local" \
-DCMAKE_CXX_MODULE_STD=ON \
-DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508
cmake --build build_module
ctest --test-dir build_module -VV
rm -rf build_module

- name: Run modules tests without 'import std;'
if: ${{matrix.toolset == 'clang-19'}}
run: |
pwd
cd ../boost-root/libs/$LIBRARY
cmake -S test/cmake_subdir_test \
-B build_module \
Expand Down
48 changes: 34 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ cmake_minimum_required(VERSION 3.8...4.20)

project(boost_stacktrace VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)

function(stacktrace_add_module name)
function(stacktrace_add_module name import_std)
target_sources(${name}
PUBLIC
FILE_SET CXX_MODULES
BASE_DIRS "${CMAKE_CURRENT_LIST_DIR}/modules"
FILES "${CMAKE_CURRENT_LIST_DIR}/modules/${name}.cppm"
)
target_compile_features(${name} PUBLIC cxx_std_20)
target_compile_definitions(${name} PUBLIC BOOST_USE_MODULES)

if(${import_std})
target_compile_features(${name} PUBLIC cxx_std_23)
target_compile_definitions(${name} PRIVATE BOOST_STACKTRACE_USE_STD_MODULE)
else()
target_compile_features(${name} PUBLIC cxx_std_20)
endif()
endfunction()

function(stacktrace_add_library suffix opt public_libs libs defs add_module)
function(stacktrace_add_library suffix opt public_libs libs defs add_module import_std)

if(NOT opt)
return()
Expand Down Expand Up @@ -50,7 +56,7 @@ function(stacktrace_add_library suffix opt public_libs libs defs add_module)
)

if (add_module)
stacktrace_add_module(boost_stacktrace_${suffix})
stacktrace_add_module(boost_stacktrace_${suffix} ${import_std})
else()
target_sources(boost_stacktrace_${suffix}
PRIVATE
Expand Down Expand Up @@ -129,23 +135,36 @@ else()
set(_enable_non_noop_backend FALSE)
endif()

if(NOT BOOST_USE_MODULES)
if(BOOST_USE_MODULES)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
endif()
if ((CMAKE_CXX_STANDARD IN_LIST CMAKE_CXX_COMPILER_IMPORT_STD) AND CMAKE_CXX_MODULE_STD)
message(STATUS "Using `import std;`")
set(__import_std ON)
else()
message(STATUS "`import std;` is not available")
set(__import_std OFF)
endif()
unset(__standard)
else()
set(BOOST_USE_MODULES OFF)
set(__import_std OFF)
endif()

stacktrace_add_library(dump ${_enable_non_noop_backend} "" "" "" ${BOOST_USE_MODULES})
stacktrace_add_library(noop ${BOOST_STACKTRACE_ENABLE_NOOP} "" "" "" ${BOOST_USE_MODULES})
stacktrace_add_library(backtrace ${BOOST_STACKTRACE_ENABLE_BACKTRACE} Boost::stacktrace_dump "backtrace;${CMAKE_DL_LIBS}" "" ${BOOST_USE_MODULES})
stacktrace_add_library(addr2line ${BOOST_STACKTRACE_ENABLE_ADDR2LINE} Boost::stacktrace_dump "${CMAKE_DL_LIBS}" "" ${BOOST_USE_MODULES})
stacktrace_add_library(basic ${BOOST_STACKTRACE_ENABLE_BASIC} Boost::stacktrace_dump "${CMAKE_DL_LIBS}" "" ${BOOST_USE_MODULES})
stacktrace_add_library(windbg ${BOOST_STACKTRACE_ENABLE_WINDBG} Boost::stacktrace_dump "dbgeng;ole32" "_GNU_SOURCE=1" ${BOOST_USE_MODULES})
stacktrace_add_library(windbg_cached ${BOOST_STACKTRACE_ENABLE_WINDBG_CACHED} Boost::stacktrace_dump "dbgeng;ole32" "_GNU_SOURCE=1" ${BOOST_USE_MODULES})
stacktrace_add_library(dump ${_enable_non_noop_backend} "" "" "" ${BOOST_USE_MODULES} ${__import_std})
stacktrace_add_library(noop ${BOOST_STACKTRACE_ENABLE_NOOP} "" "" "" ${BOOST_USE_MODULES} ${__import_std})
stacktrace_add_library(backtrace ${BOOST_STACKTRACE_ENABLE_BACKTRACE} Boost::stacktrace_dump "backtrace;${CMAKE_DL_LIBS}" "" ${BOOST_USE_MODULES} ${__import_std})
stacktrace_add_library(addr2line ${BOOST_STACKTRACE_ENABLE_ADDR2LINE} Boost::stacktrace_dump "${CMAKE_DL_LIBS}" "" ${BOOST_USE_MODULES} ${__import_std})
stacktrace_add_library(basic ${BOOST_STACKTRACE_ENABLE_BASIC} Boost::stacktrace_dump "${CMAKE_DL_LIBS}" "" ${BOOST_USE_MODULES} ${__import_std})
stacktrace_add_library(windbg ${BOOST_STACKTRACE_ENABLE_WINDBG} Boost::stacktrace_dump "dbgeng;ole32" "_GNU_SOURCE=1" ${BOOST_USE_MODULES} ${__import_std})
stacktrace_add_library(windbg_cached ${BOOST_STACKTRACE_ENABLE_WINDBG_CACHED} Boost::stacktrace_dump "dbgeng;ole32" "_GNU_SOURCE=1" ${BOOST_USE_MODULES} ${__import_std})

# boost_stacktrace, default library

if(BOOST_USE_MODULES)
add_library(boost_stacktrace)
stacktrace_add_module(boost_stacktrace boost_stacktrace)
stacktrace_add_module(boost_stacktrace ${__import_std})
set(__scope PUBLIC)

foreach(backend noop backtrace addr2line basic windbg windbg_cached)
Expand All @@ -157,6 +176,7 @@ else()
add_library(boost_stacktrace INTERFACE)
set(__scope INTERFACE)
endif()
unset(__import_std)

target_include_directories(boost_stacktrace ${__scope} "${CMAKE_CURRENT_LIST_DIR}/include")
add_library(Boost::stacktrace ALIAS boost_stacktrace)
Expand All @@ -182,7 +202,7 @@ target_link_libraries(boost_stacktrace ${__scope} Boost::stacktrace_${__default_

# Boost::stacktrace_from_exception is never the default
if(_enable_non_noop_backend)
stacktrace_add_library(from_exception ${BOOST_STACKTRACE_ENABLE_FROM_EXCEPTION} Boost::stacktrace_dump "${CMAKE_DL_LIBS}" "" FALSE)
stacktrace_add_library(from_exception ${BOOST_STACKTRACE_ENABLE_FROM_EXCEPTION} Boost::stacktrace_dump "${CMAKE_DL_LIBS}" "" FALSE FALSE)
endif()
unset(_enable_non_noop_backend)

Expand Down
4 changes: 2 additions & 2 deletions include/boost/stacktrace/detail/addr_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
# pragma once
#endif

#if !defined(BOOST_STACKTRACE_INTERFACE_UNIT)
#if !defined(BOOST_STACKTRACE_INTERFACE_UNIT) && !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#include <fstream>
#include <sstream>
#include <cstdint>
#include <cstdlib>
#endif // !defined(BOOST_STACKTRACE_INTERFACE_UNIT)
#endif // !defined(BOOST_STACKTRACE_INTERFACE_UNIT) && !defined(BOOST_STACKTRACE_USE_STD_MODULE)

namespace boost { namespace stacktrace { namespace detail {

Expand Down
4 changes: 2 additions & 2 deletions include/boost/stacktrace/detail/frame_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
# pragma once
#endif

#if !defined(BOOST_STACKTRACE_INTERFACE_UNIT)
#if !defined(BOOST_STACKTRACE_INTERFACE_UNIT) && !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#include <string>
#endif // !defined(BOOST_STACKTRACE_INTERFACE_UNIT)
#endif // !defined(BOOST_STACKTRACE_INTERFACE_UNIT) && !defined(BOOST_STACKTRACE_USE_STD_MODULE)

#if !defined(BOOST_USE_MODULES)
#include <boost/stacktrace/safe_dump_to.hpp>
Expand Down
2 changes: 2 additions & 0 deletions include/boost/stacktrace/detail/frame_unwind.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#if !defined(BOOST_STACKTRACE_INTERFACE_UNIT)
#include <boost/core/demangle.hpp>

#if !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#include <cstdio>
#endif // !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#endif // !defined(BOOST_STACKTRACE_INTERFACE_UNIT)

#include <boost/stacktrace/frame.hpp>
Expand Down
4 changes: 2 additions & 2 deletions include/boost/stacktrace/detail/to_dec_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# pragma once
#endif

#if !defined(BOOST_STACKTRACE_INTERFACE_UNIT)
#if !defined(BOOST_STACKTRACE_INTERFACE_UNIT) && !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#include <array>
#include <cstddef> // std::size_t
#endif // !defined(BOOST_STACKTRACE_INTERFACE_UNIT)
#endif // !defined(BOOST_STACKTRACE_INTERFACE_UNIT) && !defined(BOOST_STACKTRACE_USE_STD_MODULE)

namespace boost { namespace stacktrace { namespace detail {

Expand Down
4 changes: 2 additions & 2 deletions include/boost/stacktrace/detail/to_hex_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# pragma once
#endif

#if !defined(BOOST_STACKTRACE_INTERFACE_UNIT)
#if !defined(BOOST_STACKTRACE_INTERFACE_UNIT) && !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#include <array>
#include <type_traits>
#endif // !defined(BOOST_STACKTRACE_INTERFACE_UNIT)
#endif // !defined(BOOST_STACKTRACE_INTERFACE_UNIT) && !defined(BOOST_STACKTRACE_USE_STD_MODULE)

namespace boost { namespace stacktrace { namespace detail {

Expand Down
4 changes: 2 additions & 2 deletions include/boost/stacktrace/detail/void_ptr_cast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# pragma once
#endif

#if !defined(BOOST_STACKTRACE_INTERFACE_UNIT)
#if !defined(BOOST_STACKTRACE_INTERFACE_UNIT) && !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#include <type_traits>
#endif // !defined(BOOST_STACKTRACE_INTERFACE_UNIT)
#endif // !defined(BOOST_STACKTRACE_INTERFACE_UNIT) && !defined(BOOST_STACKTRACE_USE_STD_MODULE)

#if defined(__GNUC__) && defined(__GNUC_MINOR__) && (__GNUC__ * 100 + __GNUC_MINOR__ > 301)
# pragma GCC system_header
Expand Down
4 changes: 2 additions & 2 deletions include/boost/stacktrace/frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# pragma once
#endif

#if !defined(BOOST_STACKTRACE_INTERFACE_UNIT)
#if !defined(BOOST_STACKTRACE_INTERFACE_UNIT) && !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#include <iosfwd>
#include <string>
#endif // !defined(BOOST_STACKTRACE_INTERFACE_UNIT)
#endif // !defined(BOOST_STACKTRACE_INTERFACE_UNIT) && !defined(BOOST_STACKTRACE_USE_STD_MODULE)

#include <boost/stacktrace/detail/frame_decl.hpp>
#include <boost/stacktrace/detail/push_options.h>
Expand Down
3 changes: 3 additions & 0 deletions include/boost/stacktrace/safe_dump_to.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
#endif

#if !defined(BOOST_STACKTRACE_INTERFACE_UNIT)

#if !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#include <cstddef>
#endif // !defined(BOOST_STACKTRACE_USE_STD_MODULE)

#if defined(BOOST_WINDOWS)
#include <boost/winapi/config.hpp>
Expand Down
2 changes: 2 additions & 0 deletions include/boost/stacktrace/stacktrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
#include <boost/core/no_exceptions_support.hpp>
#include <boost/container_hash/hash_fwd.hpp>

#if !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#include <iosfwd>
#include <string>
#include <vector>

#ifndef BOOST_NO_CXX11_HDR_TYPE_TRAITS
# include <type_traits>
#endif
#endif // !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#endif // !defined(BOOST_STACKTRACE_INTERFACE_UNIT)

#include <boost/stacktrace/stacktrace_fwd.hpp>
Expand Down
4 changes: 2 additions & 2 deletions include/boost/stacktrace/stacktrace_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

#if !defined(BOOST_USE_MODULES) || defined(BOOST_STACKTRACE_INTERFACE_UNIT)

#if !defined(BOOST_STACKTRACE_INTERFACE_UNIT)
#if !defined(BOOST_STACKTRACE_INTERFACE_UNIT) && !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#include <cstddef>
#include <memory>
#endif // !defined(BOOST_STACKTRACE_INTERFACE_UNIT)
#endif // !defined(BOOST_STACKTRACE_INTERFACE_UNIT) && !defined(BOOST_STACKTRACE_USE_STD_MODULE)

/// @file stacktrace_fwd.hpp This header contains only forward declarations of
/// boost::stacktrace::frame, boost::stacktrace::basic_stacktrace, boost::stacktrace::stacktrace
Expand Down
6 changes: 6 additions & 0 deletions modules/boost_stacktrace_addr2line.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ module;
#include <boost/container_hash/hash_fwd.hpp>
#include <boost/predef.h>

#if !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#include <vector>
#include <fstream>
#include <sstream>
#include <cxxabi.h>
#endif

#include <sys/types.h>
#include <sys/wait.h>
Expand All @@ -34,6 +36,10 @@ module;

export module boost.stacktrace.addr2line;

#if defined(BOOST_STACKTRACE_USE_STD_MODULE)
import std;
#endif

import boost.stacktrace.dump;

#ifdef __clang__
Expand Down
6 changes: 6 additions & 0 deletions modules/boost_stacktrace_backtrace.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ module;

#include <backtrace.h>

#if !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#include <vector>
#include <fstream>
#include <sstream>
#include <cxxabi.h>
#endif

#include <dlfcn.h>

Expand All @@ -32,6 +34,10 @@ module;

export module boost.stacktrace.backtrace;

#if defined(BOOST_STACKTRACE_USE_STD_MODULE)
import std;
#endif

import boost.stacktrace.dump;

#ifdef __clang__
Expand Down
6 changes: 6 additions & 0 deletions modules/boost_stacktrace_basic.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ module;
#include <boost/container_hash/hash_fwd.hpp>
#include <boost/predef.h>

#if !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#include <vector>
#include <fstream>
#include <sstream>
#include <cxxabi.h>
#endif

#include <dlfcn.h>

Expand All @@ -30,6 +32,10 @@ module;

export module boost.stacktrace.basic;

#if defined(BOOST_STACKTRACE_USE_STD_MODULE)
import std;
#endif

import boost.stacktrace.dump;

#ifdef __clang__
Expand Down
9 changes: 8 additions & 1 deletion modules/boost_stacktrace_dump.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,23 @@ module;
#include <boost/config.hpp>
#include <boost/predef.h>

#if !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#include <stdio.h>
#endif

#include <fcntl.h>
#include <unwind.h>
#include <stdio.h>
#include <sys/stat.h>

#define BOOST_STACKTRACE_INTERFACE_UNIT
#define BOOST_STACKTRACE_LINK

export module boost.stacktrace.dump;

#if defined(BOOST_STACKTRACE_USE_STD_MODULE)
import std;
#endif

#ifdef __clang__
# pragma clang diagnostic ignored "-Winclude-angled-in-module-purview"
#endif
Expand Down
6 changes: 6 additions & 0 deletions modules/boost_stacktrace_noop.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ module;
#include <boost/core/no_exceptions_support.hpp>
#include <boost/container_hash/hash_fwd.hpp>

#if !defined(BOOST_STACKTRACE_USE_STD_MODULE)
#include <vector>
#include <memory>
#endif

#define BOOST_STACKTRACE_INTERFACE_UNIT
#define BOOST_STACKTRACE_LINK

export module boost.stacktrace.noop;

#if defined(BOOST_STACKTRACE_USE_STD_MODULE)
import std;
#endif

#ifdef __clang__
# pragma clang diagnostic ignored "-Winclude-angled-in-module-purview"
#endif
Expand Down
5 changes: 3 additions & 2 deletions modules/samples/usage_sample_from_exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// http://www.boost.org/LICENSE_1_0.txt)

#include <iostream>
#include <stdexcept>
#include <map>

#include <boost/config.hpp>

Expand All @@ -15,7 +15,8 @@
namespace {

BOOST_NOINLINE void foo() {
throw std::logic_error{"Foo"};
std::map<int, int> m;
std::ignore = m.at(1);
}

BOOST_NOINLINE void bar() {
Expand Down
Loading