-
Notifications
You must be signed in to change notification settings - Fork 171
Rewrite modules following the new recommended Boost practice #196
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
Changes from 8 commits
5ec603c
3792637
56a0f2d
709a25d
6be268d
8971c38
0c8d6e4
282f645
b120be8
d3b3904
34a9890
622e4c9
9e43d26
5182bda
bb1bc0a
1a996e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,10 @@ jobs: | |
| - toolset: clang-15 | ||
| cxxstd: "03,11,14,17,20" | ||
| os: ubuntu-22.04 | ||
| - toolset: clang-19 | ||
| cxxstd: "20,23" | ||
| os: ubuntu-24.04 | ||
| install: clang-19 clang-tools-19 | ||
| # - toolset: clang | ||
| # cxxstd: "03,11,14,17,2a" | ||
| # os: macos-10.15 | ||
|
|
@@ -87,6 +91,17 @@ jobs: | |
| ./b2 -d0 headers | ||
| ./b2 variant=debug tools/inspect/build | ||
|
|
||
| - name: Run modules tests | ||
| if: ${{matrix.toolset == 'clang-19'}} | ||
| run: | | ||
| cd ../boost-root/libs/pfr | ||
| mkdir build_module | ||
| cd build_module | ||
| cmake -DBOOST_USE_MODULES=1 -DBUILD_TESTING=1 -GNinja -DCMAKE_CXX_COMPILER=clang++-19 -DCMAKE_CXX_FLAGS=-I../../../ .. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're going to support building with and without import std, you need to add a CI build for each config/compiler pair. I think you're missing an include in the import std configuration. |
||
| cmake --build . && ctest -V | ||
| cd .. | ||
| rm -rf build_module | ||
|
|
||
| - name: Run tests | ||
| run: | | ||
| cd ../boost-root | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,20 +4,44 @@ | |
| # Distributed under the Boost Software License, Version 1.0. | ||
| # https://www.boost.org/LICENSE_1_0.txt | ||
|
|
||
| cmake_minimum_required(VERSION 3.5...3.16) | ||
| cmake_minimum_required(VERSION 3.5...3.31) | ||
|
|
||
| project(boost_pfr VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) | ||
|
|
||
| add_library(boost_pfr INTERFACE) | ||
| add_library(Boost::pfr ALIAS boost_pfr) | ||
|
|
||
| target_include_directories(boost_pfr INTERFACE include) | ||
| if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28.0" AND BOOST_USE_MODULES) | ||
| add_library(boost_pfr) | ||
| target_compile_features(boost_pfr PUBLIC cxx_std_20) | ||
| target_sources(boost_pfr PUBLIC | ||
| FILE_SET modules_public TYPE CXX_MODULES FILES | ||
| ${CMAKE_CURRENT_LIST_DIR}/modules/pfr.cppm | ||
| ) | ||
| if (CXX_MODULE_STD) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this works like this. If I understood To match the rest of Boost, I'd make You need to test these workflows to avoid this kind of errors. We commonly test installing the project and consuming it with
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, I have to check the |
||
| target_compile_definitions(boost_pfr PUBLIC BOOST_USE_STD_MODULE) | ||
| target_compile_features(boost_pfr PUBLIC cxx_std_23) | ||
| endif() | ||
|
|
||
| if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28.0" AND BUILD_MODULE) | ||
| add_subdirectory(module) | ||
| target_compile_definitions(boost_pfr PUBLIC BOOST_USE_MODULES) | ||
| target_include_directories(boost_pfr PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be just |
||
| else() | ||
| add_library(boost_pfr INTERFACE) | ||
| target_include_directories(boost_pfr INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) | ||
| endif() | ||
|
|
||
| add_library(Boost::pfr ALIAS boost_pfr) | ||
|
|
||
| enable_testing() | ||
| if (BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") | ||
| add_subdirectory(test) | ||
| add_subdirectory(test) | ||
| endif() | ||
|
|
||
| if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28.0" AND BOOST_USE_MODULES AND BUILD_TESTING) | ||
| add_executable(boost_pfr_module_usage modules/usage_sample.cpp) | ||
| target_link_libraries(boost_pfr_module_usage PRIVATE Boost::pfr) | ||
| add_test(NAME boost_pfr_module_usage COMMAND boost_pfr_module_usage) | ||
|
|
||
| # Make sure that mixing includes and imports is fine for different TU | ||
| add_executable(boost_pfr_module_usage_mu modules/usage_test_mu1.cpp modules/usage_test_mu2.cpp) | ||
| target_link_libraries(boost_pfr_module_usage_mu PRIVATE Boost::pfr) | ||
| add_test(NAME boost_pfr_module_usage_mu COMMAND boost_pfr_module_usage_mu) | ||
| endif() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |
| #define BOOST_PFR_CONFIG_HPP | ||
| #pragma once | ||
|
|
||
| #if __cplusplus >= 201402L || (defined(_MSC_VER) && defined(_MSVC_LANG) && _MSC_VER > 1900) | ||
| #if !defined(BOOST_USE_MODULES) && (__cplusplus >= 201402L || (defined(_MSC_VER) && defined(_MSVC_LANG) && _MSC_VER > 1900)) | ||
| #include <type_traits> // to get non standard platform macro definitions (__GLIBCXX__ for example) | ||
| #endif | ||
|
|
||
|
|
@@ -70,8 +70,10 @@ | |
| #endif | ||
|
|
||
| #ifndef BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE | ||
| # if defined(BOOST_USE_MODULES) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you can attempt to include |
||
| # define BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE 1 | ||
| // Assume that libstdc++ since GCC-7.3 does not have linear instantiation depth in std::make_integral_sequence | ||
| # if defined( __GLIBCXX__) && __GLIBCXX__ >= 20180101 | ||
| # elif defined( __GLIBCXX__) && __GLIBCXX__ >= 20180101 | ||
| # define BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE 1 | ||
| # elif defined(_MSC_VER) | ||
| # define BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE 1 | ||
|
|
@@ -145,12 +147,4 @@ | |
|
|
||
| #undef BOOST_PFR_NOT_SUPPORTED | ||
|
|
||
| #ifndef BOOST_PFR_BEGIN_MODULE_EXPORT | ||
| # define BOOST_PFR_BEGIN_MODULE_EXPORT | ||
| #endif | ||
|
|
||
| #ifndef BOOST_PFR_END_MODULE_EXPORT | ||
| # define BOOST_PFR_END_MODULE_EXPORT | ||
| #endif | ||
|
|
||
| #endif // BOOST_PFR_CONFIG_HPP | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,10 @@ | |
|
|
||
| #include <boost/pfr/detail/config.hpp> | ||
|
|
||
| #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) | ||
| import boost.pfr; | ||
| #else | ||
|
|
||
| #include <boost/pfr/detail/core.hpp> | ||
|
|
||
| #include <boost/pfr/detail/sequence_tuple.hpp> | ||
|
|
@@ -17,10 +21,14 @@ | |
| #include <boost/pfr/detail/make_integer_sequence.hpp> | ||
| #include <boost/pfr/detail/tie_from_structure_tuple.hpp> | ||
|
|
||
| #include <boost/pfr/tuple_size.hpp> | ||
|
|
||
| #if defined(BOOST_USE_STD_MODULE) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since PFR is the only library supporting this atm, I'd consider renaming the macro to BOOST_PFR_USE_STD_MODULE |
||
| import std; | ||
| #else | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd consider replacing this ifdef + includes by either a file like this: https://github.com/anarthal/mp11/blob/feature/cxx20-modules/include/boost/mp11/detail/std/tuple.hpp or follow this approach: boostorg/charconv#255 (comment)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather leave it as is for now. Maybe I'll change it in the next PR |
||
| #include <type_traits> | ||
| #include <utility> // metaprogramming stuff | ||
|
|
||
| #include <boost/pfr/tuple_size.hpp> | ||
| #endif | ||
|
|
||
| /// \file boost/pfr/core.hpp | ||
| /// Contains all the basic tuple-like interfaces \forcedlink{get}, \forcedlink{tuple_size}, \forcedlink{tuple_element_t}, and others. | ||
|
|
@@ -29,8 +37,6 @@ | |
|
|
||
| namespace boost { namespace pfr { | ||
|
|
||
| BOOST_PFR_BEGIN_MODULE_EXPORT | ||
|
|
||
| /// \brief Returns reference or const reference to a field with index `I` in \aggregate `val`. | ||
| /// Overload taking the type `U` returns reference or const reference to a field | ||
| /// with provided type `U` in \aggregate `val` if there's only one field of such type in `val`. | ||
|
|
@@ -245,8 +251,8 @@ constexpr detail::tie_from_structure_tuple<Elements...> tie_from_structure(Eleme | |
| return detail::tie_from_structure_tuple<Elements...>(args...); | ||
| } | ||
|
|
||
| BOOST_PFR_END_MODULE_EXPORT | ||
|
|
||
| }} // namespace boost::pfr | ||
|
|
||
| #endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) | ||
|
|
||
| #endif // BOOST_PFR_CORE_HPP | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |
| #include <boost/pfr/detail/size_t_.hpp> | ||
| #include <boost/pfr/detail/unsafe_declval.hpp> | ||
|
|
||
| #ifdef BOOST_PFR_HAS_STD_MODULE | ||
| #if defined(BOOST_USE_STD_MODULE) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you will get macro definitions like Same applies for |
||
| import std; | ||
| #else | ||
| #include <climits> // CHAR_BIT | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You won't get
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll just use |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,15 +9,15 @@ | |
|
|
||
| #include <boost/pfr/detail/config.hpp> | ||
|
|
||
| #ifdef BOOST_PFR_HAS_STD_MODULE | ||
| #include <boost/pfr/detail/sequence_tuple.hpp> | ||
|
|
||
| #if defined(BOOST_USE_STD_MODULE) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same with |
||
| import std; | ||
| #else | ||
| #include <functional> | ||
| #include <cstdint> | ||
| #endif | ||
|
|
||
| #include <boost/pfr/detail/sequence_tuple.hpp> | ||
|
|
||
| namespace boost { namespace pfr { namespace detail { | ||
| template <std::size_t I, std::size_t N> | ||
| struct equal_impl { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd strongly advise to add a job covering modules under MSVC, since it's much more restrictive than clang. You can have a look at my mp11/charconv proposal for some inspiration.