Skip to content

Commit 898c212

Browse files
authored
Run all the tests in CMake, add CMake runs into CI. Drop dependency on Boost.Core (#17)
1 parent d13ba26 commit 898c212

File tree

6 files changed

+175
-12
lines changed

6 files changed

+175
-12
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
include:
20+
- toolset: gcc-14 # Do not remove! It is the only toolset that tests CMake tests down below
21+
cxxstd: "03,11,14,17,20"
22+
os: ubuntu-24.04
2023
- toolset: gcc-12
2124
cxxstd: "03,11,14,17,2a"
2225
os: ubuntu-22.04
@@ -85,9 +88,20 @@ jobs:
8588
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
8689
python tools/boostdep/depinst/depinst.py --include benchmark --include example --include examples --include tools --git_args "--depth 10 --jobs 3" $LIBRARY
8790
./bootstrap.sh
88-
./b2 -d0 headers
8991
./b2 -j4 variant=debug tools/inspect
9092
93+
- name: Run CMake tests
94+
if: ${{matrix.toolset == 'gcc-14'}}
95+
run: |
96+
cd ../boost-root/
97+
mkdir __build
98+
cd __build
99+
cmake -DBUILD_TESTING=1 -DBOOST_INCLUDE_LIBRARIES=type_index -DCMAKE_CXX_COMPILER=g++-14 -DCMAKE_C_COMPILER=gcc-14 ..
100+
cmake --build . --target tests
101+
ctest --output-on-failure --no-tests=error
102+
cd ..
103+
rm -rf __build
104+
91105
- name: Run modules tests wihtout 'import std;'
92106
if: ${{matrix.toolset == 'clang-19'}}
93107
run: |
@@ -194,7 +208,21 @@ jobs:
194208
git submodule update --init tools/boostdep
195209
python tools/boostdep/depinst/depinst.py --include benchmark --include example --include examples --include tools --git_args "--jobs 3" %LIBRARY%
196210
cmd /c bootstrap
197-
b2 -d0 headers
211+
212+
- name: Run CMake tests
213+
if: ${{matrix.toolset == 'msvc-14.3'}}
214+
shell: cmd
215+
run: |
216+
choco install --no-progress ninja
217+
call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsall.bat" x64
218+
cd ../boost-root/
219+
mkdir __build
220+
cd __build
221+
cmake -DBUILD_TESTING=1 -DBOOST_INCLUDE_LIBRARIES=type_index ..
222+
cmake --build . --target tests --config Debug
223+
ctest --output-on-failure --no-tests=error -C Debug
224+
cd ..
225+
rm -rf __build
198226
199227
- name: Run modules tests
200228
if: ${{matrix.toolset == 'msvc-14.3'}}

CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ target_link_libraries(boost_type_index
3434
${__scope}
3535
Boost::config
3636
Boost::container_hash
37-
Boost::core
3837
Boost::throw_exception
3938
)
4039

41-
if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
42-
40+
if(BUILD_TESTING)
4341
add_subdirectory(test)
44-
4542
endif()

build.jam

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ require-b2 5.2 ;
88
constant boost_dependencies :
99
/boost/config//boost_config
1010
/boost/container_hash//boost_container_hash
11-
/boost/core//boost_core
1211
/boost/throw_exception//boost_throw_exception ;
1312

1413
project /boost/type_index

include/boost/type_index/stl_type_index.hpp

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,38 @@
3030
#error "File boost/type_index/stl_type_index.ipp is not usable when typeid() is not available."
3131
#endif
3232

33+
#if defined(__has_include)
34+
# if __has_include(<cxxabi.h>)
35+
# define BOOST_TYPE_INDEX_IMPL_HAS_CXXABI
36+
# endif
37+
#endif
38+
3339
#if !defined(BOOST_TYPE_INDEX_INTERFACE_UNIT)
3440
#include <typeinfo>
3541
#include <cstring> // std::strcmp, std::strlen, std::strstr
42+
#include <memory>
3643
#include <stdexcept>
44+
#include <string>
3745
#include <type_traits>
3846

3947
#include <boost/throw_exception.hpp>
40-
#include <boost/core/demangle.hpp>
48+
49+
#ifdef BOOST_TYPE_INDEX_IMPL_HAS_CXXABI
50+
# include <cxxabi.h>
51+
# include <cstdlib>
52+
# include <cstddef>
53+
#endif
54+
55+
#endif
56+
57+
// Copied from boost/core/demangle.hpp
58+
#ifdef BOOST_TYPE_INDEX_IMPL_HAS_CXXABI
59+
// For some architectures (mips, mips64, x86, x86_64) cxxabi.h in Android NDK is implemented by gabi++ library
60+
// (https://android.googlesource.com/platform/ndk/+/master/sources/cxx-stl/gabi++/), which does not implement
61+
// abi::__cxa_demangle(). We detect this implementation by checking the include guard here.
62+
# ifdef __GABIXX_CXXABI_H__
63+
# undef BOOST_TYPE_INDEX_IMPL_HAS_CXXABI
64+
# endif
4165
#endif
4266

4367
#ifdef BOOST_HAS_PRAGMA_ONCE
@@ -46,6 +70,34 @@
4670

4771
namespace boost { namespace typeindex {
4872

73+
namespace impl {
74+
75+
#ifdef BOOST_TYPE_INDEX_IMPL_HAS_CXXABI
76+
77+
inline const char* demangle_alloc(const char* name) noexcept {
78+
int status = 0;
79+
std::size_t size = 0;
80+
return abi::__cxa_demangle(name, NULL, &size, &status);
81+
}
82+
83+
inline void demangle_free(const void* name) noexcept {
84+
std::free(const_cast<void*>(name));
85+
}
86+
87+
#else
88+
89+
inline const char* demangle_alloc(const char* name) noexcept {
90+
return name;
91+
}
92+
93+
inline void demangle_free(const void* ) noexcept {}
94+
95+
#endif
96+
97+
#undef BOOST_TYPE_INDEX_IMPL_HAS_CXXABI
98+
99+
} // namespace impl
100+
49101
BOOST_TYPE_INDEX_BEGIN_MODULE_EXPORT
50102

51103
/// \class stl_type_index
@@ -127,7 +179,9 @@ inline std::string stl_type_index::pretty_name() const {
127179

128180
// In case of MSVC demangle() is a no-op, and name() already returns demangled name.
129181
// In case of GCC and Clang (on non-Windows systems) name() returns mangled name and demangle() undecorates it.
130-
const boost::core::scoped_demangled_name demangled_name(data_->name());
182+
const std::unique_ptr<const char, void(*)(const void*)> demangled_name(
183+
impl::demangle_alloc(data_->name()), &impl::demangle_free
184+
);
131185

132186
const char* begin = demangled_name.get();
133187
if (!begin) {
@@ -142,7 +196,7 @@ inline std::string stl_type_index::pretty_name() const {
142196
if (b) {
143197
b += cvr_saver_name_len;
144198

145-
// Trim everuthing till '<'. In modules the name could be boost::typeindex::detail::cvr_saver@boost.type_index<
199+
// Trim everything till '<'. In modules the name could be boost::typeindex::detail::cvr_saver@boost.type_index<
146200
while (*b != '<') { // the string is zero terminated, we won't exceed the buffer size
147201
++ b;
148202
}

modules/boost_type_index.cppm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@
44
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
55

66
// To compile manually use a command like the folowing:
7-
// clang++ -I ../include -std=c++20 --precompile -x c++-module pfr.cppm
7+
// clang++ -I ../include -std=c++20 --precompile -x c++-module boost_type_index.cppm
88

99
module;
1010

1111
#include <version>
1212
#include <cstddef>
1313
#include <cstdint>
1414

15+
#if __has_include(<cxxabi.h>)
16+
# include <cxxabi.h>
17+
#endif
18+
1519
#include <boost/config.hpp>
1620
#include <boost/container_hash/hash_fwd.hpp>
1721
#include <boost/container_hash/hash.hpp>
18-
#include <boost/core/demangle.hpp>
1922
#include <boost/throw_exception.hpp>
2023

2124
#ifndef BOOST_TYPE_INDEX_USE_STD_MODULE
2225
#include <cstring>
26+
#include <cstdlib>
2327
#include <iosfwd>
2428
#include <memory>
2529
#include <stdexcept>

test/CMakeLists.txt

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Copyright (c) 2016-2025 Antony Polukhin
2+
# Distributed under the Boost Software License, Version 1.0.
3+
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
4+
5+
include(BoostTest OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)
6+
7+
if(NOT HAVE_BOOST_TEST)
8+
return()
9+
endif()
10+
11+
if(MSVC)
12+
set(BOOST_TYPEINDEX_DETAIL_NO_RTTI "/GR-")
13+
set(BOOST_TYPEINDEX_DETAIL_RTTI "/GR")
14+
else()
15+
set(BOOST_TYPEINDEX_DETAIL_NO_RTTI "-fno-rtti")
16+
set(BOOST_TYPEINDEX_DETAIL_RTTI "-frtti")
17+
endif()
18+
19+
# Making libraries that CANNOT work between rtti-on/rtti-off modules
20+
add_library(boost_type_index_test_lib_nortti SHARED test_lib.cpp)
21+
target_compile_options(boost_type_index_test_lib_nortti PRIVATE ${BOOST_TYPEINDEX_DETAIL_NO_RTTI})
22+
target_link_libraries(boost_type_index_test_lib_nortti PRIVATE Boost::type_index)
23+
24+
add_library(boost_type_index_test_lib_anonymous_nortti SHARED test_lib_anonymous.cpp)
25+
target_compile_options(boost_type_index_test_lib_anonymous_nortti PRIVATE ${BOOST_TYPEINDEX_DETAIL_NO_RTTI})
26+
target_link_libraries(boost_type_index_test_lib_anonymous_nortti PRIVATE Boost::type_index)
27+
28+
add_library(boost_type_index_test_lib_rtti SHARED test_lib.cpp)
29+
target_compile_options(boost_type_index_test_lib_rtti PRIVATE ${BOOST_TYPEINDEX_DETAIL_RTTI})
30+
target_link_libraries(boost_type_index_test_lib_rtti PRIVATE Boost::type_index)
31+
32+
add_library(boost_type_index_test_lib_anonymous_rtti SHARED test_lib_anonymous.cpp)
33+
target_compile_options(boost_type_index_test_lib_anonymous_rtti PRIVATE ${BOOST_TYPEINDEX_DETAIL_RTTI})
34+
target_link_libraries(boost_type_index_test_lib_anonymous_rtti PRIVATE Boost::type_index)
35+
36+
# Making libraries that can work between rtti-on/rtti-off modules
37+
add_library(boost_type_index_test_lib_nortti_compat SHARED test_lib.cpp)
38+
target_compile_options(boost_type_index_test_lib_nortti_compat PRIVATE ${BOOST_TYPEINDEX_DETAIL_NO_RTTI})
39+
target_compile_definitions(boost_type_index_test_lib_nortti_compat PUBLIC BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY)
40+
target_link_libraries(boost_type_index_test_lib_nortti_compat PRIVATE Boost::type_index)
41+
42+
add_library(boost_type_index_test_lib_rtti_compat SHARED test_lib.cpp)
43+
target_compile_options(boost_type_index_test_lib_rtti_compat PRIVATE ${BOOST_TYPEINDEX_DETAIL_RTTI})
44+
target_compile_definitions(boost_type_index_test_lib_rtti_compat PUBLIC BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY)
45+
target_link_libraries(boost_type_index_test_lib_rtti_compat PRIVATE Boost::type_index)
46+
47+
set(BOOST_TEST_LINK_LIBRARIES Boost::type_index Boost::core)
48+
49+
boost_test(TYPE run SOURCES type_index_test.cpp)
50+
boost_test(TYPE run SOURCES type_index_runtime_cast_test.cpp LINK_LIBRARIES Boost::smart_ptr)
51+
boost_test(TYPE run SOURCES type_index_constexpr_test.cpp)
52+
boost_test(TYPE run SOURCES type_index_test.cpp COMPILE_OPTIONS -fno-rtti NAME type_index_test_no_rtti)
53+
boost_test(TYPE run SOURCES ctti_print_name.cpp)
54+
55+
boost_test(TYPE run SOURCES testing_crossmodule.cpp LINK_LIBRARIES boost_type_index_test_lib_rtti)
56+
boost_test(TYPE run SOURCES testing_crossmodule.cpp LINK_LIBRARIES boost_type_index_test_lib_nortti COMPILE_OPTIONS -fno-rtti NAME testing_crossmodule_no_rtti)
57+
boost_test(TYPE run SOURCES testing_crossmodule_anonymous.cpp LINK_LIBRARIES boost_type_index_test_lib_anonymous_rtti)
58+
59+
boost_test(TYPE run SOURCES compare_ctti_stl.cpp)
60+
boost_test(TYPE run SOURCES track_13621.cpp)
61+
62+
boost_test(TYPE compile-fail SOURCES type_index_test_ctti_copy_fail.cpp)
63+
boost_test(TYPE compile-fail SOURCES type_index_test_ctti_construct_fail.cpp)
64+
boost_test(TYPE compile SOURCES type_index_test_ctti_alignment.cpp)
65+
66+
# Mixing RTTI on and off
67+
boost_test(TYPE link-fail SOURCES testing_crossmodule.cpp LINK_LIBRARIES boost_type_index_test_lib_rtti COMPILE_OPTIONS -fno-rtti NAME link_fail_nortti_rtti)
68+
boost_test(TYPE link-fail SOURCES testing_crossmodule.cpp LINK_LIBRARIES boost_type_index_test_lib_nortti NAME link_fail_rtti_nortti)
69+
70+
boost_test(TYPE run SOURCES testing_crossmodule.cpp LINK_LIBRARIES boost_type_index_test_lib_rtti_compat COMPILE_OPTIONS -fno-rtti NAME testing_crossmodule_nortti_rtti_compat)
71+
boost_test(TYPE run SOURCES testing_crossmodule.cpp LINK_LIBRARIES boost_type_index_test_lib_nortti_compat NAME testing_crossmodule_rtti_nortti_compat)
72+
73+
file(GLOB EXAMPLE_FILES "../examples/*.cpp")
74+
foreach (testsourcefile ${EXAMPLE_FILES})
75+
boost_test(TYPE run SOURCES ${testsourcefile} INCLUDE_DIRECTORIES ../examples LINK_LIBRARIES Boost::unordered)
76+
77+
get_filename_component(testname ${testsourcefile} NAME_WE)
78+
if(NOT testname STREQUAL "table_of_names")
79+
boost_test(TYPE run SOURCES ${testsourcefile} NAME ${testname}_no_rtti COMPILE_OPTIONS -fno-rtti INCLUDE_DIRECTORIES ../examples LINK_LIBRARIES Boost::unordered)
80+
endif()
81+
endforeach()

0 commit comments

Comments
 (0)