Skip to content

Commit ffa847e

Browse files
Add C++20 module support
1 parent 67106eb commit ffa847e

3 files changed

Lines changed: 310 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ if (BOOST_BEAST_IS_ROOT)
3737
endif ()
3838
option(BOOST_BEAST_BUILD_TESTS "Build boost::beast tests" ${BUILD_TESTING})
3939
option(BOOST_BEAST_BUILD_FUZZERS "Build boost::beast fuzzers" OFF)
40+
option(BOOST_BEAST_BUILD_MODULES "Build boost::beast modules (requires C++20)" OFF)
4041
option(BOOST_BEAST_BUILD_EXAMPLES "Build boost::beast examples" ${BOOST_BEAST_IS_ROOT})
4142
option(BOOST_BEAST_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
4243

@@ -163,6 +164,15 @@ if (BOOST_BEAST_BUILD_TESTS)
163164
add_subdirectory(test)
164165
endif ()
165166

167+
#-------------------------------------------------
168+
#
169+
# Modules
170+
#
171+
#-------------------------------------------------
172+
if (BOOST_BEAST_BUILD_MODULES)
173+
add_subdirectory(module)
174+
endif ()
175+
166176
#-------------------------------------------------
167177
#
168178
# Examples

module/CMakeLists.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
cmake_minimum_required(VERSION 3.28)
2+
3+
add_library(boost_beast_module)
4+
5+
target_sources(boost_beast_module
6+
PUBLIC
7+
FILE_SET CXX_MODULES FILES
8+
beast.cppm
9+
)
10+
11+
target_compile_features(boost_beast_module PUBLIC cxx_std_20)
12+
13+
target_include_directories(boost_beast_module PUBLIC
14+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
15+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/config/include>
16+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/asio/include>
17+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/assert/include>
18+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/bind/include>
19+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/container/include>
20+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/container_hash/include>
21+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/core/include>
22+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/describe/include>
23+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/endian/include>
24+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/intrusive/include>
25+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/io/include>
26+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/logic/include>
27+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/move/include>
28+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/mp11/include>
29+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/optional/include>
30+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/smart_ptr/include>
31+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/static_string/include>
32+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/system/include>
33+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/throw_exception/include>
34+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/type_index/include>
35+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/type_traits/include>
36+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/utility/include>
37+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../boost/winapi/include>
38+
$<INSTALL_INTERFACE:include>
39+
)
40+
41+
add_library(Boost::beast::module ALIAS boost_beast_module)
42+
43+
# Installation
44+
install(TARGETS boost_beast_module
45+
EXPORT ${PROJECT_NAME}Targets
46+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
47+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
48+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
49+
FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/module
50+
)

module/beast.cppm

Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
//
2+
// Copyright (c) 2016-2026 Vinnie Falco (vinnie dot falco at gmail dot com)
3+
//
4+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
// Official repository: https://github.com/boostorg/beast
8+
//
9+
10+
module;
11+
12+
#include <boost/beast.hpp>
13+
#include <boost/beast/core/buffer_traits.hpp>
14+
#include <boost/beast/_experimental/http/icy_stream.hpp>
15+
#include <boost/beast/_experimental/test/error.hpp>
16+
#include <boost/beast/_experimental/test/fail_count.hpp>
17+
#include <boost/beast/_experimental/test/handler.hpp>
18+
#include <boost/beast/_experimental/test/stream.hpp>
19+
20+
export module boost.beast;
21+
22+
export namespace boost::beast {
23+
using boost::beast::async_base;
24+
using boost::beast::basic_stream;
25+
using boost::beast::file;
26+
using boost::beast::file_mode;
27+
#if BOOST_BEAST_USE_POSIX_FILE
28+
using boost::beast::file_posix;
29+
#endif
30+
using boost::beast::file_stdio;
31+
#if BOOST_BEAST_USE_WIN32_FILE
32+
using boost::beast::file_win32;
33+
#endif
34+
using boost::beast::flat_stream;
35+
using boost::beast::iequal;
36+
using boost::beast::iless;
37+
using boost::beast::rate_policy_access;
38+
using boost::beast::saved_handler;
39+
using boost::beast::simple_rate_policy;
40+
using boost::beast::static_string;
41+
using boost::beast::stable_async_base;
42+
using boost::beast::string_view;
43+
using boost::beast::tcp_stream;
44+
using boost::beast::unlimited_rate_policy;
45+
46+
using boost::beast::condition;
47+
using boost::beast::error;
48+
using boost::beast::file_mode;
49+
using boost::beast::role_type;
50+
51+
using boost::beast::allocate_stable;
52+
using boost::beast::async_detect_ssl;
53+
using boost::beast::beast_close_socket;
54+
using boost::beast::bind_front_handler;
55+
using boost::beast::bind_handler;
56+
57+
template <class Socket>
58+
inline void close_socket(Socket& sock) {
59+
boost::beast::close_socket(sock);
60+
}
61+
62+
using boost::beast::detect_ssl;
63+
using boost::beast::generic_category;
64+
using boost::beast::get_lowest_layer;
65+
using boost::beast::iequals;
66+
using boost::beast::to_static_string;
67+
68+
using boost::beast::executor_type;
69+
using boost::beast::has_get_executor;
70+
using boost::beast::is_async_read_stream;
71+
using boost::beast::is_async_stream;
72+
using boost::beast::is_async_write_stream;
73+
74+
using boost::beast::is_file;
75+
using boost::beast::is_sync_read_stream;
76+
using boost::beast::is_sync_stream;
77+
using boost::beast::is_sync_write_stream;
78+
// using boost::beast::lowest_layer_type;
79+
80+
// using boost::beast::ssl_stream;
81+
82+
namespace errc = boost::beast::errc;
83+
using boost::beast::error_category;
84+
using boost::beast::error_code;
85+
using boost::beast::error_condition;
86+
using boost::beast::system_category;
87+
using boost::beast::system_error;
88+
89+
using boost::beast::basic_flat_buffer;
90+
using boost::beast::basic_multi_buffer;
91+
// using boost::beast::buffer_ref;
92+
using boost::beast::buffered_read_stream;
93+
using boost::beast::buffers_adaptor;
94+
using boost::beast::buffers_cat_view;
95+
using boost::beast::buffers_prefix_view;
96+
using boost::beast::buffers_prefix_view;
97+
using boost::beast::buffers_suffix;
98+
using boost::beast::flat_buffer;
99+
using boost::beast::flat_static_buffer;
100+
using boost::beast::flat_static_buffer_base;
101+
using boost::beast::multi_buffer;
102+
using boost::beast::static_buffer;
103+
using boost::beast::static_buffer_base;
104+
105+
using boost::beast::async_write;
106+
107+
template <class BufferSequence>
108+
[[nodiscard]]
109+
inline std::size_t buffer_bytes(BufferSequence const& buffers) {
110+
return boost::beast::buffer_bytes(buffers);
111+
}
112+
113+
using boost::beast::buffers_cat;
114+
using boost::beast::buffers_front;
115+
using boost::beast::buffers_prefix;
116+
using boost::beast::buffers_range;
117+
using boost::beast::buffers_range_ref;
118+
using boost::beast::buffers_to_string;
119+
using boost::beast::make_printable;
120+
using boost::beast::ostream;
121+
using boost::beast::read_size;
122+
using boost::beast::read_size_or_throw;
123+
// using boost::beast::ref;
124+
using boost::beast::write;
125+
126+
using boost::beast::buffers_iterator_type;
127+
// using boost::beast::buffers_type;
128+
using boost::beast::is_buffers_generator;
129+
// using boost::beast::is_const_buffer_sequence;
130+
// using boost::beast::is_mutable_buffer_sequence;
131+
132+
namespace http {
133+
using boost::beast::http::basic_chunk_extensions;
134+
using boost::beast::http::basic_dynamic_body;
135+
using boost::beast::http::basic_fields;
136+
using boost::beast::http::basic_file_body;
137+
using boost::beast::http::basic_parser;
138+
using boost::beast::http::basic_string_body;
139+
using boost::beast::http::buffer_body;
140+
using boost::beast::http::chunk_body;
141+
using boost::beast::http::chunk_crlf;
142+
using boost::beast::http::chunk_extensions;
143+
using boost::beast::http::chunk_header;
144+
using boost::beast::http::chunk_last;
145+
using boost::beast::http::dynamic_body;
146+
using boost::beast::http::empty_body;
147+
using boost::beast::http::fields;
148+
using boost::beast::http::file_body;
149+
using boost::beast::http::header;
150+
using boost::beast::http::message;
151+
using boost::beast::http::message_generator;
152+
using boost::beast::http::parser;
153+
using boost::beast::http::request;
154+
using boost::beast::http::request_header;
155+
using boost::beast::http::request_serializer;
156+
using boost::beast::http::response;
157+
using boost::beast::http::response_header;
158+
using boost::beast::http::response_parser;
159+
using boost::beast::http::response_serializer;
160+
using boost::beast::http::serializer;
161+
using boost::beast::http::span_body;
162+
using string_body = boost::beast::http::basic_string_body<char>;
163+
using boost::beast::http::vector_body;
164+
165+
using boost::beast::http::async_read;
166+
using boost::beast::http::async_read_header;
167+
using boost::beast::http::async_read_some;
168+
using boost::beast::http::async_write;
169+
using boost::beast::http::async_write_header;
170+
using boost::beast::http::async_write_some;
171+
using boost::beast::http::int_to_status;
172+
using boost::beast::http::make_chunk;
173+
using boost::beast::http::make_chunk_last;
174+
using boost::beast::http::obsolete_reason;
175+
using boost::beast::http::operator<<;
176+
using boost::beast::http::read;
177+
using boost::beast::http::read_header;
178+
using boost::beast::http::read_some;
179+
using boost::beast::http::string_to_field;
180+
using boost::beast::http::string_to_verb;
181+
using boost::beast::http::swap;
182+
using boost::beast::http::to_string;
183+
using boost::beast::http::to_status_class;
184+
using boost::beast::http::write;
185+
using boost::beast::http::write_header;
186+
using boost::beast::http::write_some;
187+
188+
using boost::beast::http::error;
189+
using boost::beast::http::field;
190+
using boost::beast::http::status;
191+
using boost::beast::http::status_class;
192+
using boost::beast::http::verb;
193+
194+
// using boost::beast::http::is_body;
195+
using boost::beast::http::is_body_reader;
196+
using boost::beast::http::is_body_writer;
197+
using boost::beast::http::is_fields;
198+
using boost::beast::http::is_mutable_body_writer;
199+
200+
using boost::beast::http::ext_list;
201+
using boost::beast::http::opt_token_list;
202+
using boost::beast::http::param_list;
203+
using boost::beast::http::token_list;
204+
}
205+
206+
namespace websocket {
207+
using boost::beast::websocket::close_reason;
208+
using ping_data = boost::beast::static_string<125, char>;
209+
using boost::beast::websocket::stream;
210+
using boost::beast::websocket::stream_base;
211+
using reason_string = boost::beast::static_string<123, char>;
212+
213+
using boost::beast::websocket::async_teardown;
214+
using boost::beast::websocket::is_upgrade;
215+
using boost::beast::websocket::seed_prng;
216+
using boost::beast::websocket::teardown;
217+
218+
using boost::beast::websocket::permessage_deflate;
219+
220+
using boost::beast::websocket::close_code;
221+
using boost::beast::websocket::condition;
222+
using boost::beast::websocket::error;
223+
using boost::beast::websocket::frame_type;
224+
}
225+
226+
namespace zlib {
227+
using boost::beast::zlib::deflate_stream;
228+
using boost::beast::zlib::inflate_stream;
229+
using boost::beast::zlib::z_params;
230+
using boost::beast::zlib::deflate_upper_bound;
231+
using boost::beast::zlib::error;
232+
using boost::beast::zlib::Flush;
233+
using boost::beast::zlib::Strategy;
234+
}
235+
236+
namespace http {
237+
using boost::beast::http::icy_stream;
238+
}
239+
240+
namespace test {
241+
using boost::beast::test::fail_count;
242+
using boost::beast::test::handler;
243+
// using boost::beast::test::stream;
244+
using boost::beast::test::connect;
245+
using boost::beast::test::any_handler;
246+
using boost::beast::test::fail_handler;
247+
using boost::beast::test::success_handler;
248+
using boost::beast::test::error;
249+
}
250+
}

0 commit comments

Comments
 (0)