diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d098f17a..8e512106 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,6 +105,23 @@ jobs: ./b2 -d0 headers ./b2 -j4 variant=debug tools/inspect + - name: Run modules tests without 'import std;' + if: ${{matrix.toolset == 'clang-19'}} + run: | + cd ../boost-root/libs/$LIBRARY + cmake -S test/cmake_subdir_test -B __build \ + -GNinja \ + -DBUILD_TESTING=1 \ + -DBOOST_DLL_USE_STD_FS=1 \ + -DBOOST_USE_MODULES=1 \ + -DCMAKE_CXX_COMPILER=${{matrix.compiler}} \ + -DCMAKE_CXX_FLAGS="-stdlib=libc++" \ + -DCMAKE_CXX_STANDARD=20 + + cmake --build __build + ctest --test-dir __build --output-on-failure --no-tests=error -VV + rm -rf __build + - name: Run CMake subdir tests if: ${{matrix.toolset == 'gcc-14' || matrix.toolset == 'clang-19'}} run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 89b81847..0540476f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,11 @@ # Copyright 2020 Peter Dimov # Copyright Antony Polukhin, 2021-2026 +# Copyright Fedor Osetrov, 2025-2026 # # 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...4.20) project(boost_dll VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) @@ -48,16 +49,32 @@ target_link_libraries(boost_dll_boost_fs Boost::filesystem ) -# Detault library +# Default library + +if (BOOST_USE_MODULES) + add_library(boost_dll) + target_compile_definitions(boost_dll PUBLIC BOOST_USE_MODULES) + target_compile_features(boost_dll PUBLIC cxx_std_20) + target_sources(boost_dll + PUBLIC + FILE_SET CXX_MODULES + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/modules + FILES ${CMAKE_CURRENT_SOURCE_DIR}/modules/boost_dll.cppm + ) + set(__scope PUBLIC) +else() + add_library(boost_dll INTERFACE) + set(__scope INTERFACE) +endif() -add_library(boost_dll INTERFACE) add_library(Boost::dll ALIAS boost_dll) -target_include_directories(boost_dll INTERFACE include) +target_include_directories(boost_dll ${__scope} include) if (BOOST_DLL_USE_STD_FS) - target_link_libraries(boost_dll INTERFACE Boost::dll_std_fs) + target_link_libraries(boost_dll ${__scope} Boost::dll_std_fs) else() - target_link_libraries(boost_dll INTERFACE Boost::dll_boost_fs) + target_link_libraries(boost_dll ${__scope} Boost::dll_boost_fs) endif() +unset(__scope) if (BOOST_SUPERPROJECT_VERSION AND NOT CMAKE_VERSION VERSION_LESS 3.13) boost_install( diff --git a/example/b2_workarounds.hpp b/example/b2_workarounds.hpp index 2a5fdfe0..bd37c95d 100644 --- a/example/b2_workarounds.hpp +++ b/example/b2_workarounds.hpp @@ -8,12 +8,13 @@ #ifndef BOOST_DLL_EXAMPLE_COMMON_B2_WORKAROUNDS_HPP #define BOOST_DLL_EXAMPLE_COMMON_B2_WORKAROUNDS_HPP -#include #include #include #include #include +#include + namespace b2_workarounds { diff --git a/example/getting_started_library.cpp b/example/getting_started_library.cpp index 33a4268c..e287331c 100644 --- a/example/getting_started_library.cpp +++ b/example/getting_started_library.cpp @@ -8,8 +8,8 @@ // MinGW related workaround #define BOOST_DLL_FORCE_ALIAS_INSTANTIATION -#include #include +#include #define API extern "C" BOOST_SYMBOL_EXPORT diff --git a/example/tutorial4/load_self.cpp b/example/tutorial4/load_self.cpp index bb8f36c4..dfb011fe 100644 --- a/example/tutorial4/load_self.cpp +++ b/example/tutorial4/load_self.cpp @@ -9,11 +9,11 @@ #define BOOST_DLL_FORCE_ALIAS_INSTANTIATION //[plugcpp_my_plugin_load_self -#include // for shared_library -#include // for program_location() #include "static_plugin.hpp" // without this headers some compilers may optimize out the `create_plugin` symbol #include #include +#include // for shared_library +#include // for program_location() namespace dll = boost::dll; diff --git a/example/tutorial4/static_plugin.hpp b/example/tutorial4/static_plugin.hpp index ed78a540..e3977161 100644 --- a/example/tutorial4/static_plugin.hpp +++ b/example/tutorial4/static_plugin.hpp @@ -6,9 +6,9 @@ // or copy at http://www.boost.org/LICENSE_1_0.txt) //[plugcpp_my_plugin_static -#include // for BOOST_DLL_ALIAS #include #include "../tutorial_common/my_plugin_api.hpp" +#include // for BOOST_DLL_ALIAS namespace my_namespace { std::shared_ptr create_plugin(); // Forward declaration diff --git a/example/tutorial6/on_unload_lib.cpp b/example/tutorial6/on_unload_lib.cpp index 4320de7f..326e3570 100644 --- a/example/tutorial6/on_unload_lib.cpp +++ b/example/tutorial6/on_unload_lib.cpp @@ -9,9 +9,9 @@ #define BOOST_DLL_FORCE_ALIAS_INSTANTIATION //[plugcpp_on_unload -#include // for BOOST_DLL_ALIAS #include #include +#include // for BOOST_DLL_ALIAS namespace my_namespace { diff --git a/example/tutorial7/library1.cpp b/example/tutorial7/library1.cpp index 668a8107..de0c4595 100644 --- a/example/tutorial7/library1.cpp +++ b/example/tutorial7/library1.cpp @@ -9,9 +9,9 @@ #define BOOST_DLL_FORCE_ALIAS_INSTANTIATION //[plugcpp_tutorial7_library1 -#include // for BOOST_DLL_ALIAS_SECTIONED #include #include +#include // for BOOST_DLL_ALIAS_SECTIONED void print(const std::string& s) { std::cout << "Hello, " << s << '!' << std::endl; diff --git a/example/tutorial7/library2.cpp b/example/tutorial7/library2.cpp index 326c0356..8c5bd95c 100644 --- a/example/tutorial7/library2.cpp +++ b/example/tutorial7/library2.cpp @@ -9,9 +9,9 @@ #define BOOST_DLL_FORCE_ALIAS_INSTANTIATION //[plugcpp_tutorial7_library2 -#include // for BOOST_DLL_ALIAS_SECTIONED #include #include +#include // for BOOST_DLL_ALIAS_SECTIONED void print_howdy(const std::string& s) { std::cout << "How're you doing, " << s << '?' << std::endl; diff --git a/example/tutorial8/refcounting_api.hpp b/example/tutorial8/refcounting_api.hpp index a5062070..94417ee7 100644 --- a/example/tutorial8/refcounting_api.hpp +++ b/example/tutorial8/refcounting_api.hpp @@ -7,6 +7,7 @@ //[plugcpp_my_plugin_refcounting_api #include "../tutorial_common/my_plugin_api.hpp" +#include #include class my_refcounting_api: public my_plugin_api { @@ -19,7 +20,6 @@ class my_refcounting_api: public my_plugin_api { //[plugcpp_library_holding_deleter_api_bind -#include #include struct library_holding_deleter { diff --git a/example/tutorial8/tutorial8_static.cpp b/example/tutorial8/tutorial8_static.cpp index 9cc03a41..3405e1d2 100644 --- a/example/tutorial8/tutorial8_static.cpp +++ b/example/tutorial8/tutorial8_static.cpp @@ -6,9 +6,9 @@ // or copy at http://www.boost.org/LICENSE_1_0.txt) //[callplugcpp_tutorial8_static -#include // program_location() #include #include "refcounting_plugin.hpp" +#include // program_location() int main() { std::shared_ptr plugin = get_plugin( diff --git a/include/boost/dll.hpp b/include/boost/dll.hpp index 37a8f9f7..0f7c3e2b 100644 --- a/include/boost/dll.hpp +++ b/include/boost/dll.hpp @@ -12,16 +12,23 @@ /// \file boost/dll.hpp /// \brief Includes all the non-experimental headers of the Boost.DLL library. +#include + +#if !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + +#ifdef BOOST_HAS_PRAGMA_ONCE +# pragma once +#endif + #include #include -#include #include #include #include -#ifdef BOOST_HAS_PRAGMA_ONCE -# pragma once -#endif +#endif // !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + +#include #endif // BOOST_DLL_DLL_HPP diff --git a/include/boost/dll/alias.hpp b/include/boost/dll/alias.hpp index 646e0d0f..569a0b7a 100644 --- a/include/boost/dll/alias.hpp +++ b/include/boost/dll/alias.hpp @@ -5,26 +5,36 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) +/// \file boost/dll/alias.hpp +/// \brief Includes alias methods and macro. You can include this header or +/// boost/dll/shared_library.hpp to reduce dependencies +/// in case you do not use the refcountable functions. + #ifndef BOOST_DLL_ALIAS_HPP #define BOOST_DLL_ALIAS_HPP +#include + +#if !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + #include + +#ifdef BOOST_HAS_PRAGMA_ONCE +# pragma once +#endif + +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include -#include #if BOOST_COMP_GNUC // MSVC does not have and defines it in some other header, MinGW requires that header. #include // intptr_t #endif +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) -#ifdef BOOST_HAS_PRAGMA_ONCE -# pragma once -#endif +#include -/// \file boost/dll/alias.hpp -/// \brief Includes alias methods and macro. You can include this header or -/// boost/dll/shared_library.hpp to reduce dependencies -/// in case you do not use the refcountable functions. +#endif // !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) namespace boost { namespace dll { @@ -284,6 +294,5 @@ namespace boost { namespace dll { }} // namespace boost::dll - #endif // BOOST_DLL_ALIAS_HPP diff --git a/include/boost/dll/config.hpp b/include/boost/dll/config.hpp index 664320ff..a55a464f 100644 --- a/include/boost/dll/config.hpp +++ b/include/boost/dll/config.hpp @@ -7,10 +7,11 @@ /// \file boost/dll/config.hpp /// \brief Imports filesystem, error_code, errc, system_error, make_error_code from Boost or C++17 into `boost::dll::fs` namespace. -#ifndef BOOST_DLL_DETAIL_CONFIG_HPP -#define BOOST_DLL_DETAIL_CONFIG_HPP +#ifndef BOOST_DLL_CONFIG_HPP +#define BOOST_DLL_CONFIG_HPP + +#include -#include #ifdef BOOST_HAS_PRAGMA_ONCE # pragma once #endif @@ -44,9 +45,11 @@ using system_error = std::conditional_t +#if !defined(BOOST_DLL_INTERFACE_UNIT) +#include #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) namespace boost { namespace dll { namespace fs { @@ -58,10 +61,12 @@ using std::system_error; #else // BOOST_DLL_USE_STD_FS +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include #include #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) namespace boost { namespace dll { namespace fs { @@ -76,7 +81,9 @@ using boost::system::system_error; #ifdef BOOST_DLL_USE_BOOST_SHARED_PTR +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) namespace boost { namespace dll { namespace detail { template @@ -86,7 +93,9 @@ namespace boost { namespace dll { namespace detail { #else // BOOST_DLL_USE_STD_FS +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) namespace boost { namespace dll { namespace detail { template @@ -96,5 +105,5 @@ namespace boost { namespace dll { namespace detail { #endif // BOOST_DLL_USE_STD_FS -#endif // BOOST_DLL_DETAIL_PUSH_OPTIONS_HPP +#endif // BOOST_DLL_CONFIG_HPP diff --git a/include/boost/dll/detail/aggressive_ptr_cast.hpp b/include/boost/dll/detail/aggressive_ptr_cast.hpp index 81bdf11b..e50cc8da 100644 --- a/include/boost/dll/detail/aggressive_ptr_cast.hpp +++ b/include/boost/dll/detail/aggressive_ptr_cast.hpp @@ -13,9 +13,11 @@ # pragma once #endif +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include // std::memcpy #include #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) #if defined(__GNUC__) && defined(__GNUC_MINOR__) && (__GNUC__ * 100 + __GNUC_MINOR__ > 301) # pragma GCC system_header diff --git a/include/boost/dll/detail/config.hpp b/include/boost/dll/detail/config.hpp new file mode 100644 index 00000000..f9c44f23 --- /dev/null +++ b/include/boost/dll/detail/config.hpp @@ -0,0 +1,29 @@ +// Copyright Fedor Osetrov, 2025-2026. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_DLL_DETAIL_CONFIG_HPP +#define BOOST_DLL_DETAIL_CONFIG_HPP + +#if !defined(BOOST_DLL_INTERFACE_UNIT) +# include +# ifdef BOOST_HAS_PRAGMA_ONCE +# pragma once +# endif +#endif + +#ifdef BOOST_DLL_INTERFACE_UNIT +# define BOOST_DLL_BEGIN_MODULE_EXPORT export { +# define BOOST_DLL_END_MODULE_EXPORT } +#else +# define BOOST_DLL_BEGIN_MODULE_EXPORT +# define BOOST_DLL_END_MODULE_EXPORT +#endif + +#if defined(BOOST_USE_MODULES) && !defined(BOOST_DLL_INTERFACE_UNIT) +import boost.dll; +#endif + +#endif // BOOST_DLL_DETAIL_CONFIG_HPP diff --git a/include/boost/dll/detail/demangling/demangle_symbol.hpp b/include/boost/dll/detail/demangling/demangle_symbol.hpp index 57e82877..5a1599af 100644 --- a/include/boost/dll/detail/demangling/demangle_symbol.hpp +++ b/include/boost/dll/detail/demangling/demangle_symbol.hpp @@ -9,9 +9,12 @@ #define BOOST_DLL_DEMANGLE_SYMBOL_HPP_ #include + +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) #if defined(_MSC_VER) // MSVC, Clang-cl, and ICC on Windows @@ -61,7 +64,9 @@ inline std::string demangle_symbol(const std::string& mangled_name) }}} #else +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) namespace boost { diff --git a/include/boost/dll/detail/demangling/itanium.hpp b/include/boost/dll/detail/demangling/itanium.hpp index 8fe148b9..b08ed38d 100644 --- a/include/boost/dll/detail/demangling/itanium.hpp +++ b/include/boost/dll/detail/demangling/itanium.hpp @@ -7,15 +7,16 @@ #ifndef BOOST_DLL_DETAIL_DEMANGLING_ITANIUM_HPP_ #define BOOST_DLL_DETAIL_DEMANGLING_ITANIUM_HPP_ -#include - +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) +#include -namespace boost { namespace dll { namespace detail { +namespace boost { namespace dll { namespace detail { class mangled_storage_impl : public mangled_storage_base { @@ -80,8 +81,6 @@ class mangled_storage_impl : public mangled_storage_base }; - - namespace parser { //! declare @@ -284,8 +283,6 @@ namespace parser } } - - template std::string mangled_storage_impl::get_variable(const std::string &name) const { auto found = std::find_if(storage_.begin(), storage_.end(), diff --git a/include/boost/dll/detail/demangling/mangled_storage_base.hpp b/include/boost/dll/detail/demangling/mangled_storage_base.hpp index 32d0a7cc..b072a9b2 100644 --- a/include/boost/dll/detail/demangling/mangled_storage_base.hpp +++ b/include/boost/dll/detail/demangling/mangled_storage_base.hpp @@ -7,15 +7,17 @@ #ifndef BOOST_DLL_DETAIL_MANGLE_STORAGE_BASE_HPP_ #define BOOST_DLL_DETAIL_MANGLE_STORAGE_BASE_HPP_ +#if !defined(BOOST_DLL_INTERFACE_UNIT) +#include + #include #include #include #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) #include #include -#include - namespace boost { namespace dll { namespace detail { diff --git a/include/boost/dll/detail/demangling/msvc.hpp b/include/boost/dll/detail/demangling/msvc.hpp index 13437659..47740a12 100644 --- a/include/boost/dll/detail/demangling/msvc.hpp +++ b/include/boost/dll/detail/demangling/msvc.hpp @@ -7,13 +7,15 @@ #ifndef BOOST_DLL_DETAIL_DEMANGLING_MSVC_HPP_ #define BOOST_DLL_DETAIL_DEMANGLING_MSVC_HPP_ -#include - +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include #include #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) + +#include namespace boost { namespace dll { namespace detail { diff --git a/include/boost/dll/detail/elf_info.hpp b/include/boost/dll/detail/elf_info.hpp index 1b90d548..363ce55b 100644 --- a/include/boost/dll/detail/elf_info.hpp +++ b/include/boost/dll/detail/elf_info.hpp @@ -14,12 +14,14 @@ # pragma once #endif +#if !defined(BOOST_DLL_INTERFACE_UNIT) +#include + #include #include #include #include - -#include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) namespace boost { namespace dll { namespace detail { diff --git a/include/boost/dll/detail/import_mangled_helpers.hpp b/include/boost/dll/detail/import_mangled_helpers.hpp index c1c77813..b7f7353e 100644 --- a/include/boost/dll/detail/import_mangled_helpers.hpp +++ b/include/boost/dll/detail/import_mangled_helpers.hpp @@ -7,14 +7,15 @@ #ifndef BOOST_DLL_DETAIL_IMPORT_MANGLED_HELPERS_HPP_ #define BOOST_DLL_DETAIL_IMPORT_MANGLED_HELPERS_HPP_ - -#include - - +#include #ifdef BOOST_HAS_PRAGMA_ONCE # pragma once #endif +#if !defined(BOOST_DLL_INTERFACE_UNIT) +#include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) + namespace boost { namespace dll { namespace experimental { namespace detail { //the following could be done by fusion, though it's simple enough to just declare it here. diff --git a/include/boost/dll/detail/macho_info.hpp b/include/boost/dll/detail/macho_info.hpp index aadcb2ec..bb9bd715 100644 --- a/include/boost/dll/detail/macho_info.hpp +++ b/include/boost/dll/detail/macho_info.hpp @@ -14,11 +14,13 @@ # pragma once #endif +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include #include #include // for std::getline #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) namespace boost { namespace dll { namespace detail { diff --git a/include/boost/dll/detail/pe_info.hpp b/include/boost/dll/detail/pe_info.hpp index eabf6e0a..acbb9c08 100644 --- a/include/boost/dll/detail/pe_info.hpp +++ b/include/boost/dll/detail/pe_info.hpp @@ -14,11 +14,13 @@ # pragma once #endif +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include #include #include // for std::getline #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) namespace boost { namespace dll { namespace detail { diff --git a/include/boost/dll/detail/posix/path_from_handle.hpp b/include/boost/dll/detail/posix/path_from_handle.hpp index d34413c8..cce67c69 100644 --- a/include/boost/dll/detail/posix/path_from_handle.hpp +++ b/include/boost/dll/detail/posix/path_from_handle.hpp @@ -9,19 +9,25 @@ #define BOOST_DLL_DETAIL_POSIX_PATH_FROM_HANDLE_HPP #include -#include -#include -#include #ifdef BOOST_HAS_PRAGMA_ONCE # pragma once #endif +#if !defined(BOOST_DLL_INTERFACE_UNIT) +#include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) + +#include +#include + #if BOOST_OS_MACOS || BOOST_OS_IOS +#if !defined(BOOST_DLL_INTERFACE_UNIT) # include # include # include // for std::ptrdiff_t +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) namespace boost { namespace dll { namespace detail { inline void* strip_handle(void* handle) noexcept { @@ -64,7 +70,9 @@ namespace boost { namespace dll { namespace detail { #elif BOOST_OS_ANDROID +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) namespace boost { namespace dll { namespace detail { @@ -99,11 +107,15 @@ namespace boost { namespace dll { namespace detail { #else // #if BOOST_OS_MACOS || BOOST_OS_IOS || BOOST_OS_ANDROID // for dlinfo +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) #if BOOST_OS_QNX // QNX's copy of and reside in sys folder +# if !defined(BOOST_DLL_INTERFACE_UNIT) # include +# endif // !defined(BOOST_DLL_INTERFACE_UNIT) #elif BOOST_OS_CYGWIN // Cygwin returns the opaque pointer-sized handle of type `HMODULE` on the invoke of `dlopen`, // which cannot be interpreted. As GCC on Cygwin always links to KERNEL32.DLL, we can use the @@ -114,7 +126,9 @@ extern "C" void GetModuleFileNameW(void*, wchar_t*, unsigned long long); // Introduce the Win32 API `GetLastError` here extern "C" unsigned long long GetLastError(); #else +# if !defined(BOOST_DLL_INTERFACE_UNIT) # include // struct link_map +# endif // !defined(BOOST_DLL_INTERFACE_UNIT) #endif namespace boost { namespace dll { namespace detail { diff --git a/include/boost/dll/detail/posix/program_location_impl.hpp b/include/boost/dll/detail/posix/program_location_impl.hpp index 5e491cf5..b0034524 100644 --- a/include/boost/dll/detail/posix/program_location_impl.hpp +++ b/include/boost/dll/detail/posix/program_location_impl.hpp @@ -9,17 +9,23 @@ #define BOOST_DLL_DETAIL_POSIX_PROGRAM_LOCATION_IMPL_HPP #include -#include -#include #ifdef BOOST_HAS_PRAGMA_ONCE # pragma once #endif +#if !defined(BOOST_DLL_INTERFACE_UNIT) +#include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) + +#include + #if BOOST_OS_MACOS || BOOST_OS_IOS +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) namespace boost { namespace dll { namespace detail { inline boost::dll::fs::path program_location_impl(std::error_code &ec) { @@ -44,7 +50,10 @@ namespace boost { namespace dll { namespace detail { #elif BOOST_OS_SOLARIS +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) + namespace boost { namespace dll { namespace detail { inline boost::dll::fs::path program_location_impl(std::error_code& ec) { ec.clear(); @@ -55,10 +64,12 @@ namespace boost { namespace dll { namespace detail { #elif BOOST_OS_BSD_FREE +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include #include #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) namespace boost { namespace dll { namespace detail { inline boost::dll::fs::path program_location_impl(std::error_code& ec) { @@ -121,8 +132,11 @@ namespace boost { namespace dll { namespace detail { #elif BOOST_OS_QNX +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include // for std::getline +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) + namespace boost { namespace dll { namespace detail { inline boost::dll::fs::path program_location_impl(std::error_code &ec) { ec.clear(); diff --git a/include/boost/dll/detail/posix/shared_library_impl.hpp b/include/boost/dll/detail/posix/shared_library_impl.hpp index b3879a77..e7e5568e 100644 --- a/include/boost/dll/detail/posix/shared_library_impl.hpp +++ b/include/boost/dll/detail/posix/shared_library_impl.hpp @@ -9,10 +9,12 @@ #define BOOST_DLL_SHARED_LIBRARY_IMPL_HPP #include -#include -#include -#include +#ifdef BOOST_HAS_PRAGMA_ONCE +# pragma once +#endif + +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include @@ -26,10 +28,11 @@ // QNX's copy of and reside in sys folder # include #endif +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) -#ifdef BOOST_HAS_PRAGMA_ONCE -# pragma once -#endif +#include +#include +#include namespace boost { namespace dll { namespace detail { diff --git a/include/boost/dll/detail/system_error.hpp b/include/boost/dll/detail/system_error.hpp index 87fbedda..ba7418d5 100644 --- a/include/boost/dll/detail/system_error.hpp +++ b/include/boost/dll/detail/system_error.hpp @@ -8,7 +8,17 @@ #ifndef BOOST_DLL_SYSTEM_ERROR_HPP #define BOOST_DLL_SYSTEM_ERROR_HPP +#include + +#if !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + +#ifdef BOOST_HAS_PRAGMA_ONCE +# pragma once +#endif + #include + +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include @@ -16,9 +26,11 @@ # include #endif -#ifdef BOOST_HAS_PRAGMA_ONCE -# pragma once -#endif +#include + +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) + +BOOST_DLL_BEGIN_MODULE_EXPORT namespace boost { namespace dll { namespace detail { @@ -51,5 +63,9 @@ namespace boost { namespace dll { namespace detail { }}} // boost::dll::detail +BOOST_DLL_END_MODULE_EXPORT + +#endif // !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + #endif // BOOST_DLL_SYSTEM_ERROR_HPP diff --git a/include/boost/dll/detail/type_info.hpp b/include/boost/dll/detail/type_info.hpp index c9ba6832..4754294e 100644 --- a/include/boost/dll/detail/type_info.hpp +++ b/include/boost/dll/detail/type_info.hpp @@ -9,12 +9,16 @@ #ifndef BOOST_DLL_DETAIL_TYPE_INFO_HPP_ #define BOOST_DLL_DETAIL_TYPE_INFO_HPP_ +#include + +#if !defined(BOOST_DLL_INTERFACE_UNIT) +# if defined(_MSC_VER) // MSVC, Clang-cl, and ICC on Windows +# include +# endif + #include #include -#include -#if defined(_MSC_VER) // MSVC, Clang-cl, and ICC on Windows -#include -#endif +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) namespace boost { namespace dll { namespace detail { diff --git a/include/boost/dll/detail/windows/path_from_handle.hpp b/include/boost/dll/detail/windows/path_from_handle.hpp index 42649994..4ad561d1 100644 --- a/include/boost/dll/detail/windows/path_from_handle.hpp +++ b/include/boost/dll/detail/windows/path_from_handle.hpp @@ -9,14 +9,18 @@ #define BOOST_DLL_DETAIL_WINDOWS_PATH_FROM_HANDLE_HPP #include -#include -#include -#include #ifdef BOOST_HAS_PRAGMA_ONCE # pragma once #endif +#if !defined(BOOST_DLL_INTERFACE_UNIT) +#include +#include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) + +#include + namespace boost { namespace dll { namespace detail { inline std::error_code last_error_code() noexcept { diff --git a/include/boost/dll/detail/windows/shared_library_impl.hpp b/include/boost/dll/detail/windows/shared_library_impl.hpp index 4af244dd..a9ee2ab3 100644 --- a/include/boost/dll/detail/windows/shared_library_impl.hpp +++ b/include/boost/dll/detail/windows/shared_library_impl.hpp @@ -9,20 +9,23 @@ #define BOOST_DLL_SHARED_LIBRARY_IMPL_HPP #include -#include -#include -#include -#include +#ifdef BOOST_HAS_PRAGMA_ONCE +# pragma once +#endif + +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include #include // std::move +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) -#ifdef BOOST_HAS_PRAGMA_ONCE -# pragma once -#endif +#include +#include +#include +#include namespace boost { namespace dll { namespace detail { diff --git a/include/boost/dll/import.hpp b/include/boost/dll/import.hpp index 9429fac2..b98dfcce 100644 --- a/include/boost/dll/import.hpp +++ b/include/boost/dll/import.hpp @@ -5,23 +5,29 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) +/// \file boost/dll/import.hpp +/// \brief Contains all the boost::dll::import* reference counting +/// functions that hold a shared pointer to the instance of +/// boost::dll::shared_library. + #ifndef BOOST_DLL_IMPORT_HPP #define BOOST_DLL_IMPORT_HPP -#include -#include +#include -#include // std::addressof -#include +#if !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) #ifdef BOOST_HAS_PRAGMA_ONCE # pragma once #endif -/// \file boost/dll/import.hpp -/// \brief Contains all the boost::dll::import* reference counting -/// functions that hold a shared pointer to the instance of -/// boost::dll::shared_library. +#if !defined(BOOST_DLL_INTERFACE_UNIT) +#include // std::addressof +#include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) + +#include +#include namespace boost { namespace dll { @@ -67,6 +73,7 @@ namespace detail { # define BOOST_DLL_IMPORT_RESULT_TYPE inline boost::dll::detail::import_type #endif +BOOST_DLL_BEGIN_MODULE_EXPORT /*! * Returns callable object or std::shared_ptr (boost::shared_ptr if @@ -251,10 +258,13 @@ BOOST_DLL_IMPORT_RESULT_TYPE import_alias(shared_library&& lib, const std::strin return dll::import_alias(std::move(lib), name.c_str()); } -#undef BOOST_DLL_IMPORT_RESULT_TYPE +BOOST_DLL_END_MODULE_EXPORT +#undef BOOST_DLL_IMPORT_RESULT_TYPE }} // boost::dll +#endif // !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + #endif // BOOST_DLL_IMPORT_HPP diff --git a/include/boost/dll/import_class.hpp b/include/boost/dll/import_class.hpp index de974d7c..09fbf835 100644 --- a/include/boost/dll/import_class.hpp +++ b/include/boost/dll/import_class.hpp @@ -5,28 +5,35 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) -#ifndef BOOST_DLL_IMPORT_CLASS_HPP_ -#define BOOST_DLL_IMPORT_CLASS_HPP_ - /// \file boost/dll/import_class.hpp /// \warning Experimental feature that relies on an incomplete implementation of platform specific C++ /// mangling. In case of an issue provide a PR with a fix and tests to https://github.com/boostorg/dll . /// boost/dll/import_class.hpp is not included in boost/dll.hpp /// \brief Contains the boost::dll::experimental::import_class function for importing classes. -#include -#include +#ifndef BOOST_DLL_IMPORT_CLASS_HPP_ +#define BOOST_DLL_IMPORT_CLASS_HPP_ + +#include + +#if !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + +#ifdef BOOST_HAS_PRAGMA_ONCE +# pragma once +#endif + +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include // std::move +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) + +#include +#include #if (__cplusplus < 201103L) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201103L) # error This file requires C++11 at least! #endif -#ifdef BOOST_HAS_PRAGMA_ONCE -# pragma once -#endif - namespace boost { namespace dll { namespace experimental { namespace detail @@ -99,6 +106,8 @@ struct mem_fn_call_proxy } +BOOST_DLL_BEGIN_MODULE_EXPORT + template class imported_class; @@ -250,6 +259,7 @@ class imported_class } }; +BOOST_DLL_END_MODULE_EXPORT //helper function, uses the allocating @@ -512,6 +522,6 @@ import_class(smart_library & lib, const std::string & alias_name, std::size_t si } } - +#endif // !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) #endif /* BOOST_DLL_IMPORT_CLASS_HPP_ */ diff --git a/include/boost/dll/import_mangled.hpp b/include/boost/dll/import_mangled.hpp index 301a954e..1607a99e 100644 --- a/include/boost/dll/import_mangled.hpp +++ b/include/boost/dll/import_mangled.hpp @@ -5,31 +5,36 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) -#ifndef BOOST_DLL_IMPORT_MANGLED_HPP_ -#define BOOST_DLL_IMPORT_MANGLED_HPP_ - /// \file boost/dll/import_mangled.hpp /// \warning Experimental feature that relies on an incomplete implementation of platform specific C++ /// mangling. In case of an issue provide a PR with a fix and tests to https://github.com/boostorg/dll . /// boost/dll/import_mangled.hpp is not included in boost/dll.hpp /// \brief Contains the boost::dll::experimental::import_mangled function for importing mangled symbols. +#ifndef BOOST_DLL_IMPORT_MANGLED_HPP_ +#define BOOST_DLL_IMPORT_MANGLED_HPP_ + +#include + +#if !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + +#ifdef BOOST_HAS_PRAGMA_ONCE +# pragma once +#endif + #include #if (__cplusplus < 201103L) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201103L) # error This file requires C++11 at least! #endif -#include -#include -#include - +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include // std::addressof #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) - -#ifdef BOOST_HAS_PRAGMA_ONCE -# pragma once -#endif +#include +#include +#include namespace boost { namespace dll { namespace experimental { @@ -226,6 +231,7 @@ struct mangled_import_type, false, false, true> //is variable * Overload that accepts path also throws std::bad_alloc in case of insufficient memory. */ +BOOST_DLL_BEGIN_MODULE_EXPORT template BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(const boost::dll::fs::path& lib, const char* name, @@ -306,9 +312,12 @@ BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(shared_library&& lib, const return boost::dll::experimental::import_mangled(std::move(lib), name.c_str()); } +BOOST_DLL_END_MODULE_EXPORT + #undef BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE }}} +#endif // !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) #endif /* BOOST_DLL_IMPORT_MANGLED_HPP_ */ diff --git a/include/boost/dll/library_info.hpp b/include/boost/dll/library_info.hpp index b9441000..352fe8ed 100644 --- a/include/boost/dll/library_info.hpp +++ b/include/boost/dll/library_info.hpp @@ -5,10 +5,24 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) +/// \file boost/dll/library_info.hpp +/// \brief Contains only the boost::dll::library_info class that is capable of +/// extracting different information from binaries. + #ifndef BOOST_DLL_LIBRARY_INFO_HPP #define BOOST_DLL_LIBRARY_INFO_HPP +#include + +#if !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + +#ifdef BOOST_HAS_PRAGMA_ONCE +# pragma once +#endif + #include + +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include #include @@ -17,18 +31,13 @@ #include #include +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) #include #include #include -#ifdef BOOST_HAS_PRAGMA_ONCE -# pragma once -#endif - -/// \file boost/dll/library_info.hpp -/// \brief Contains only the boost::dll::library_info class that is capable of -/// extracting different information from binaries. +BOOST_DLL_BEGIN_MODULE_EXPORT namespace boost { namespace dll { @@ -210,4 +219,9 @@ class library_info: private boost::noncopyable { }; }} // namespace boost::dll + +BOOST_DLL_END_MODULE_EXPORT + +#endif // !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + #endif // BOOST_DLL_LIBRARY_INFO_HPP diff --git a/include/boost/dll/runtime_symbol_info.hpp b/include/boost/dll/runtime_symbol_info.hpp index e2a46926..74e17947 100644 --- a/include/boost/dll/runtime_symbol_info.hpp +++ b/include/boost/dll/runtime_symbol_info.hpp @@ -5,19 +5,37 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) +/// \file boost/dll/runtime_symbol_info.hpp +/// \brief Provides methods for getting acceptable by boost::dll::shared_library location of symbol, source line or program. + #ifndef BOOST_DLL_RUNTIME_SYMBOL_INFO_HPP #define BOOST_DLL_RUNTIME_SYMBOL_INFO_HPP +#include + +#if !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + #include + +#ifdef BOOST_HAS_PRAGMA_ONCE +# pragma once +#endif + +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include -#include + +#include // std::addressof +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) #if BOOST_OS_WINDOWS +# if !defined(BOOST_DLL_INTERFACE_UNIT) # include # include +# endif // !defined(BOOST_DLL_INTERFACE_UNIT) #else -#if BOOST_OS_CYGWIN + +# if BOOST_OS_CYGWIN // `Dl_info` & `dladdr` is hidden by `__GNU_VISIBLE` typedef struct Dl_info Dl_info; @@ -30,19 +48,16 @@ struct Dl_info }; extern "C" int dladdr (const void *addr, Dl_info *info); -#endif +# endif // BOOST_OS_CYGWIN + +# if !defined(BOOST_DLL_INTERFACE_UNIT) # include # include +# endif // !defined(BOOST_DLL_INTERFACE_UNIT) #endif -#include // std::addressof - -#ifdef BOOST_HAS_PRAGMA_ONCE -# pragma once -#endif +#include -/// \file boost/dll/runtime_symbol_info.hpp -/// \brief Provides methods for getting acceptable by boost::dll::shared_library location of symbol, source line or program. namespace boost { namespace dll { #if BOOST_OS_WINDOWS @@ -53,6 +68,8 @@ namespace detail { } // namespace detail #endif +BOOST_DLL_BEGIN_MODULE_EXPORT + /*! * On success returns full path and name to the binary object that holds symbol pointed by ptr_to_symbol. * @@ -182,43 +199,6 @@ namespace detail { return ret; } - /// @cond - // We have anonymous namespace here to make sure that `this_line_location()` method is instantiated in - // current translation unit and is not shadowed by instantiations from other units. - // - // boost-no-inspect - namespace { - /// @endcond - - /*! - * On success returns full path and name of the binary object that holds the current line of code - * (the line in which the `this_line_location()` method was called). - * - * \param ec Variable that will be set to the result of the operation. - * \throws std::bad_alloc in case of insufficient memory. Overload that does not accept \forcedlinkfs{error_code} also throws \forcedlinkfs{system_error}. - */ - static inline boost::dll::fs::path this_line_location(std::error_code& ec) { - typedef boost::dll::fs::path(func_t)(std::error_code& ); - func_t& f = this_line_location; - return boost::dll::symbol_location(f, ec); - } - - //! \overload this_line_location(std::error_code& ec) - static inline boost::dll::fs::path this_line_location() { - boost::dll::fs::path ret; - std::error_code ec; - ret = this_line_location(ec); - - if (ec) { - boost::dll::detail::report_error(ec, "boost::dll::this_line_location() failed"); - } - - return ret; - } - - /// @cond - } // anonymous namespace - /// @endcond /*! * On success returns full path and name of the currently running program (the one which contains the `main()` function). @@ -248,7 +228,60 @@ namespace detail { return ret; } +BOOST_DLL_END_MODULE_EXPORT + +}} // namespace boost::dll + +#endif // !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + +#if !defined(BOOST_DLL_INTERFACE_UNIT) + +#include +#include + +namespace boost { namespace dll { + +/// @cond +// We have anonymous namespace here to make sure that `this_line_location()` method is instantiated in +// current translation unit and is not shadowed by instantiations from other units. +// +// boost-no-inspect +namespace { +/// @endcond + +/*! +* On success returns full path and name of the binary object that holds the current line of code +* (the line in which the `this_line_location()` method was called). +* +* \param ec Variable that will be set to the result of the operation. +* \throws std::bad_alloc in case of insufficient memory. Overload that does not accept \forcedlinkfs{error_code} also throws \forcedlinkfs{system_error}. +*/ +static inline boost::dll::fs::path this_line_location(std::error_code& ec) { + typedef boost::dll::fs::path(func_t)(std::error_code& ); + func_t& f = this_line_location; + return boost::dll::symbol_location(f, ec); +} + +//! \overload this_line_location(std::error_code& ec) +static inline boost::dll::fs::path this_line_location() { + boost::dll::fs::path ret; + std::error_code ec; + ret = this_line_location(ec); + + if (ec) { + boost::dll::detail::report_error(ec, "boost::dll::this_line_location() failed"); + } + + return ret; +} + +/// @cond +} // anonymous namespace +/// @endcond + }} // namespace boost::dll +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) + #endif // BOOST_DLL_RUNTIME_SYMBOL_INFO_HPP diff --git a/include/boost/dll/shared_library.hpp b/include/boost/dll/shared_library.hpp index da9ee290..3e037f7a 100644 --- a/include/boost/dll/shared_library.hpp +++ b/include/boost/dll/shared_library.hpp @@ -5,17 +5,32 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) -#ifndef BOOST_DLL_SHARED_LIBRARY_HPP -#define BOOST_DLL_SHARED_LIBRARY_HPP - /// \file boost/dll/shared_library.hpp /// \brief Contains the boost::dll::shared_library class, core class for all the /// DLL/DSO operations. +#ifndef BOOST_DLL_SHARED_LIBRARY_HPP +#define BOOST_DLL_SHARED_LIBRARY_HPP + +#include + +#if !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + +#ifdef BOOST_HAS_PRAGMA_ONCE +# pragma once +#endif + #include + +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include #include + +#include +#include // std::move +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) + #include #include @@ -25,12 +40,7 @@ # include #endif -#include -#include // std::move - -#ifdef BOOST_HAS_PRAGMA_ONCE -# pragma once -#endif +BOOST_DLL_BEGIN_MODULE_EXPORT namespace boost { namespace dll { @@ -568,4 +578,8 @@ inline void swap(shared_library& lhs, shared_library& rhs) noexcept { }} // boost::dll +BOOST_DLL_END_MODULE_EXPORT + +#endif // !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + #endif // BOOST_DLL_SHARED_LIBRARY_HPP diff --git a/include/boost/dll/shared_library_load_mode.hpp b/include/boost/dll/shared_library_load_mode.hpp index b02999e5..6bf93410 100644 --- a/include/boost/dll/shared_library_load_mode.hpp +++ b/include/boost/dll/shared_library_load_mode.hpp @@ -5,10 +5,23 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) +/// \file boost/dll/shared_library_load_mode.hpp +/// \brief Contains only the boost::dll::load_mode::type enum and operators related to it. + #ifndef BOOST_DLL_SHARED_LIBRARY_MODE_HPP #define BOOST_DLL_SHARED_LIBRARY_MODE_HPP +#include + +#if !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + +#ifdef BOOST_HAS_PRAGMA_ONCE +# pragma once +#endif + #include + +#if !defined(BOOST_DLL_INTERFACE_UNIT) #include #include @@ -17,13 +30,9 @@ #else # include #endif +#endif // !defiend(BOOST_DLL_INTERFACE_UNIT) -#ifdef BOOST_HAS_PRAGMA_ONCE -# pragma once -#endif - -/// \file boost/dll/shared_library_load_mode.hpp -/// \brief Contains only the boost::dll::load_mode::type enum and operators related to it. +BOOST_DLL_BEGIN_MODULE_EXPORT namespace boost { namespace dll { namespace load_mode { @@ -245,4 +254,8 @@ BOOST_CONSTEXPR inline type operator~(type left) noexcept { }}} // boost::dll::load_mode +BOOST_DLL_END_MODULE_EXPORT + +#endif // !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + #endif // BOOST_DLL_SHARED_LIBRARY_MODE_HPP diff --git a/include/boost/dll/smart_library.hpp b/include/boost/dll/smart_library.hpp index 28b19660..0e047bee 100644 --- a/include/boost/dll/smart_library.hpp +++ b/include/boost/dll/smart_library.hpp @@ -5,33 +5,45 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) -#ifndef BOOST_DLL_SMART_LIBRARY_HPP_ -#define BOOST_DLL_SMART_LIBRARY_HPP_ - /// \file boost/dll/smart_library.hpp /// \warning Experimental feature that relies on an incomplete implementation of platform specific C++ /// mangling. In case of an issue provide a PR with a fix and tests to https://github.com/boostorg/dll . /// boost/dll/smart_library.hpp is not included in boost/dll.hpp /// \brief Contains the boost::dll::experimental::smart_library class for loading mangled symbols. +#ifndef BOOST_DLL_SMART_LIBRARY_HPP_ +#define BOOST_DLL_SMART_LIBRARY_HPP_ + +#include + +#if !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + +#ifdef BOOST_HAS_PRAGMA_ONCE +# pragma once +#endif + #include + +#if !defined(BOOST_DLL_INTERFACE_UNIT) +#include +#include // std::move +#endif // !defined(BOOST_DLL_INTERFACE_UNIT) + +#if (__cplusplus < 201103L) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201103L) +# error This file requires C++11 at least! +#endif + #if defined(_MSC_VER) // MSVC, Clang-cl, and ICC on Windows # include #else # include #endif -#if (__cplusplus < 201103L) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201103L) -# error This file requires C++11 at least! -#endif - #include #include #include #include -#include -#include // std::move namespace boost { namespace dll { @@ -40,6 +52,8 @@ namespace experimental { using boost::dll::detail::constructor; using boost::dll::detail::destructor; +BOOST_DLL_BEGIN_MODULE_EXPORT + /*! * \brief This class is an extension of \ref shared_library, which allows to load C++ symbols. * @@ -451,9 +465,13 @@ auto get(const smart_library& sm, const std::string &name) -> typename detail::g return sm.get_mem_fn(name); } +BOOST_DLL_END_MODULE_EXPORT + } /* namespace experimental */ } /* namespace dll */ } /* namespace boost */ +#endif // !defined(BOOST_USE_MODULES) || defined(BOOST_DLL_INTERFACE_UNIT) + #endif /* BOOST_DLL_SMART_LIBRARY_HPP_ */ diff --git a/modules/boost_dll.cppm b/modules/boost_dll.cppm new file mode 100644 index 00000000..d77d022b --- /dev/null +++ b/modules/boost_dll.cppm @@ -0,0 +1,57 @@ +// Copyright Antony Polukhin, 2025-2026. +// Copyright Fedor Osetrov, 2025-2026. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + +module; + +#include +#include +#include +#include +#include +#include +#include + +#ifdef BOOST_DLL_USE_STD_FS +# include +# include +#else +# include +# include +# include +# include +#endif + +#if !BOOST_OS_WINDOWS +# include +# include +#endif + +#include +#include +#include +#include +#include +#include + +#ifndef _MSC_VER +#include +#endif + +#define BOOST_DLL_INTERFACE_UNIT + +export module boost.dll; + +#ifdef __clang__ +# pragma clang diagnostic ignored "-Winclude-angled-in-module-purview" +#endif + +#include + +// Experimental features +#include +#include +#include diff --git a/modules/sample_plugin.cpp b/modules/sample_plugin.cpp new file mode 100644 index 00000000..4829ee13 --- /dev/null +++ b/modules/sample_plugin.cpp @@ -0,0 +1,43 @@ +// Copyright Antony Polukhin, 2025-2026. +// Copyright Fedor Osetrov, 2025-2026. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + +module; + +#include +#include +#include + +#include + +module sample_plugin; + +namespace my_namespace { + +class my_module_plugin final : public my_plugin_api { +public: + my_module_plugin() { + std::cout << "Constructing my_module_plugin" << std::endl; + } + + std::string name() const override { + return "module_plugin"; + } + + float calculate(float x, float y) override { + return x - y; + } + + ~my_module_plugin() { + std::cout << "Destructing my_module_plugin" << std::endl; + } +}; + +std::shared_ptr create_plugin() { + return std::make_shared(); +} + +} // namespace my_namespace diff --git a/modules/sample_plugin.cppm b/modules/sample_plugin.cppm new file mode 100644 index 00000000..78073a33 --- /dev/null +++ b/modules/sample_plugin.cppm @@ -0,0 +1,16 @@ +// Copyright Antony Polukhin, 2025-2026. +// Copyright Fedor Osetrov, 2025-2026. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + +module; + +#include + +export module sample_plugin; + +namespace my_namespace { + export std::shared_ptr create_plugin(); +} // namespace my_namespace diff --git a/modules/usage_sample.cpp b/modules/usage_sample.cpp new file mode 100644 index 00000000..5ec605ae --- /dev/null +++ b/modules/usage_sample.cpp @@ -0,0 +1,25 @@ +// Copyright Antony Polukhin, 2025-2026. +// Copyright Fedor Osetrov, 2025-2026. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include + +#include "../example/tutorial_common/my_plugin_api.hpp" + +import boost.dll; + +int main(int argc, const char* const argv[]) { + namespace dll = boost::dll::experimental; + + dll::smart_library module_library(argv[1]); + + auto creator = module_library.get_function()>("my_namespace::create_plugin@sample_plugin"); + + const float res = creator()->calculate(10, 8.5); + std::cout << "Result: " << res << '\n'; + + return 0; +} diff --git a/test/broken_library_info_test.cpp b/test/broken_library_info_test.cpp index b42cacd6..ac59321f 100644 --- a/test/broken_library_info_test.cpp +++ b/test/broken_library_info_test.cpp @@ -6,13 +6,13 @@ // For more information, see http://www.boost.org -#include - #include #include #include +#include + int main(int argc, char* argv[]) { BOOST_TEST(argc >= 1); const auto self_binary = boost::filesystem::path(argv[0]); diff --git a/test/cmake_subdir_test/CMakeLists.txt b/test/cmake_subdir_test/CMakeLists.txt index 24ed058d..086a4f80 100644 --- a/test/cmake_subdir_test/CMakeLists.txt +++ b/test/cmake_subdir_test/CMakeLists.txt @@ -35,11 +35,9 @@ preprocessor mpl tuple type_traits -static_assert utility io typeof -functional function bind filesystem @@ -48,6 +46,7 @@ concept_check optional smart_ptr scope +unordered ) @@ -59,3 +58,26 @@ endforeach() enable_testing() add_subdirectory(../.. boostorg/dll) + +if(BOOST_USE_MODULES) + add_library(dll_sample_plugin_module SHARED) + target_link_libraries(dll_sample_plugin_module PRIVATE Boost::config) + target_sources(dll_sample_plugin_module + PUBLIC + FILE_SET CXX_MODULES + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../modules + FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../modules/sample_plugin.cppm + PUBLIC + FILE_SET HEADERS + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../example/tutorial_common + FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../example/tutorial_common/my_plugin_api.hpp + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/../../modules/sample_plugin.cpp + ) + + add_executable(boost_dll_module_usage ../../modules/usage_sample.cpp) + target_link_libraries(boost_dll_module_usage PRIVATE Boost::dll) + add_test(NAME boost_dll_module_usage COMMAND boost_dll_module_usage "$") + add_dependencies(boost_dll_module_usage dll_sample_plugin_module) + +endif() diff --git a/test/cpp_ctti_type_name_parser_lib.cpp b/test/cpp_ctti_type_name_parser_lib.cpp index eac7f4b2..9a5903bc 100644 --- a/test/cpp_ctti_type_name_parser_lib.cpp +++ b/test/cpp_ctti_type_name_parser_lib.cpp @@ -8,9 +8,10 @@ #include -#include #include +#include + namespace space { template class test_template_class diff --git a/test/cpp_load_test.cpp b/test/cpp_load_test.cpp index f325649b..15078a31 100644 --- a/test/cpp_load_test.cpp +++ b/test/cpp_load_test.cpp @@ -10,8 +10,6 @@ #include #include -# include - #include "../example/b2_workarounds.hpp" #include @@ -20,6 +18,8 @@ #include +#include + struct override_class { int arr[32]; diff --git a/test/cpp_mangle_test.cpp b/test/cpp_mangle_test.cpp index c7eb6142..f9bd1c34 100644 --- a/test/cpp_mangle_test.cpp +++ b/test/cpp_mangle_test.cpp @@ -10,13 +10,13 @@ #include "../example/b2_workarounds.hpp" -#include #include #include #include #include +#include struct override_class {}; @@ -24,7 +24,7 @@ struct override_class {}; int main(int argc, char* argv[]) { using namespace boost::dll; - using mangled_storage = detail::mangled_storage_impl; + using mangled_storage = boost::dll::experimental::smart_library::mangled_storage; boost::dll::fs::path pt = b2_workarounds::first_lib_from_argv(argc, argv); diff --git a/test/cpp_test_library.cpp b/test/cpp_test_library.cpp index 3a694465..346de5ea 100644 --- a/test/cpp_test_library.cpp +++ b/test/cpp_test_library.cpp @@ -9,6 +9,9 @@ #include +#ifdef BOOST_USE_MODULES +#include +#endif #include BOOST_SYMBOL_EXPORT extern int unscoped_var; diff --git a/test/shared_library_load_test.cpp b/test/shared_library_load_test.cpp index 5bbad70d..e48bb155 100644 --- a/test/shared_library_load_test.cpp +++ b/test/shared_library_load_test.cpp @@ -8,13 +8,14 @@ // For more information, see http://www.boost.org #include "../example/b2_workarounds.hpp" -#include #include #include #include #include + +#include // Unit Tests namespace boost { namespace dll { namespace fs { diff --git a/test/structures_tests.cpp b/test/structures_tests.cpp index ca499bee..6a0638ca 100644 --- a/test/structures_tests.cpp +++ b/test/structures_tests.cpp @@ -7,9 +7,6 @@ // For more information, see http://www.boost.org -#include -#include -#include #include #include @@ -25,6 +22,10 @@ #include #endif +#include +#include +#include + namespace dd = boost::dll::detail; template diff --git a/test/template_method_linux_test.cpp b/test/template_method_linux_test.cpp index d72522cb..e02f12cd 100644 --- a/test/template_method_linux_test.cpp +++ b/test/template_method_linux_test.cpp @@ -7,16 +7,16 @@ #include -#include -#include -#include - #include #include #include "../example/b2_workarounds.hpp" #include +#include +#include +#include + namespace space { class BOOST_SYMBOL_EXPORT my_plugin { diff --git a/test/test_library.cpp b/test/test_library.cpp index 459dd93a..a0f71c30 100644 --- a/test/test_library.cpp +++ b/test/test_library.cpp @@ -11,14 +11,15 @@ // MinGW related workaround #define BOOST_DLL_FORCE_ALIAS_INSTANTIATION -#include -#include #include #include #include #include +#include +#include + #define LIBRARY_API BOOST_SYMBOL_EXPORT extern "C" void LIBRARY_API say_hello(void);