Skip to content

Commit 5982688

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

3 files changed

Lines changed: 291 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(modules)
174+
endif ()
175+
166176
#-------------------------------------------------
167177
#
168178
# Examples

module/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
boost.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+
$<INSTALL_INTERFACE:include>
16+
)
17+
18+
add_library(Boost::beast::module ALIAS boost_beast_module)
19+
20+
# Installation
21+
install(TARGETS boost_beast_module
22+
EXPORT ${PROJECT_NAME}Targets
23+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
24+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
25+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
26+
FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/module
27+
)

module/beast.cppm

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
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+
template <class T>
72+
using is_async_stream = std::integral_constant<bool,
73+
is_async_read_stream<T>::value && is_async_write_stream<T>::value>;
74+
using boost::beast::is_async_write_stream;
75+
76+
using boost::beast::is_file;
77+
using boost::beast::is_sync_read_stream;
78+
template <class T>
79+
using is_sync_stream = std::integral_constant<bool,
80+
is_sync_read_stream<T>::value && is_sync_write_stream<T>::value>;
81+
using boost::beast::is_sync_write_stream;
82+
// using boost::beast::lowest_layer_type;
83+
84+
// using boost::beast::ssl_stream;
85+
86+
namespace errc = boost::beast::errc;
87+
using boost::beast::error_category;
88+
using boost::beast::error_code;
89+
using boost::beast::error_condition;
90+
using boost::beast::system_category;
91+
using boost::beast::system_error;
92+
93+
using boost::beast::basic_flat_buffer;
94+
using boost::beast::basic_multi_buffer;
95+
// using boost::beast::buffer_ref;
96+
using boost::beast::buffered_read_stream;
97+
using boost::beast::buffers_adaptor;
98+
using boost::beast::buffers_cat_view;
99+
using boost::beast::buffers_prefix_view;
100+
using boost::beast::buffers_prefix_view;
101+
using boost::beast::buffers_suffix;
102+
using boost::beast::flat_buffer;
103+
using boost::beast::flat_static_buffer;
104+
using boost::beast::flat_static_buffer_base;
105+
using boost::beast::multi_buffer;
106+
using boost::beast::static_buffer;
107+
using boost::beast::static_buffer_base;
108+
109+
using boost::beast::async_write;
110+
111+
template <class BufferSequence>
112+
[[nodiscard]]
113+
inline std::size_t buffer_bytes(BufferSequence const& buffers) {
114+
return boost::beast::buffer_bytes(buffers);
115+
}
116+
117+
using boost::beast::buffers_cat;
118+
using boost::beast::buffers_front;
119+
using boost::beast::buffers_prefix;
120+
using boost::beast::buffers_range;
121+
using boost::beast::buffers_range_ref;
122+
using boost::beast::buffers_to_string;
123+
using boost::beast::make_printable;
124+
using boost::beast::ostream;
125+
using boost::beast::read_size;
126+
using boost::beast::read_size_or_throw;
127+
// using boost::beast::ref;
128+
using boost::beast::write;
129+
130+
using boost::beast::buffers_iterator_type;
131+
// using boost::beast::buffers_type;
132+
using boost::beast::is_buffers_generator;
133+
// using boost::beast::is_const_buffer_sequence;
134+
// using boost::beast::is_mutable_buffer_sequence;
135+
136+
namespace http {
137+
using boost::beast::http::basic_chunk_extensions;
138+
using boost::beast::http::basic_dynamic_body;
139+
using boost::beast::http::basic_fields;
140+
using boost::beast::http::basic_file_body;
141+
using boost::beast::http::basic_parser;
142+
using boost::beast::http::basic_string_body;
143+
using boost::beast::http::buffer_body;
144+
using boost::beast::http::chunk_body;
145+
using boost::beast::http::chunk_crlf;
146+
using boost::beast::http::chunk_extensions;
147+
using boost::beast::http::chunk_header;
148+
using boost::beast::http::chunk_last;
149+
using boost::beast::http::dynamic_body;
150+
using boost::beast::http::empty_body;
151+
using boost::beast::http::fields;
152+
using boost::beast::http::file_body;
153+
using boost::beast::http::header;
154+
using boost::beast::http::message;
155+
using boost::beast::http::message_generator;
156+
using boost::beast::http::parser;
157+
using boost::beast::http::request;
158+
using boost::beast::http::request_header;
159+
using boost::beast::http::request_serializer;
160+
using boost::beast::http::response;
161+
using boost::beast::http::response_header;
162+
using boost::beast::http::response_parser;
163+
using boost::beast::http::response_serializer;
164+
using boost::beast::http::serializer;
165+
using boost::beast::http::span_body;
166+
using string_body = boost::beast::http::basic_string_body<char>;
167+
using boost::beast::http::vector_body;
168+
169+
using boost::beast::http::async_read;
170+
using boost::beast::http::async_read_header;
171+
using boost::beast::http::async_read_some;
172+
using boost::beast::http::async_write;
173+
using boost::beast::http::async_write_header;
174+
using boost::beast::http::async_write_some;
175+
using boost::beast::http::int_to_status;
176+
using boost::beast::http::make_chunk;
177+
using boost::beast::http::make_chunk_last;
178+
using boost::beast::http::obsolete_reason;
179+
using boost::beast::http::operator<<;
180+
using boost::beast::http::read;
181+
using boost::beast::http::read_header;
182+
using boost::beast::http::read_some;
183+
using boost::beast::http::string_to_field;
184+
using boost::beast::http::string_to_verb;
185+
using boost::beast::http::swap;
186+
using boost::beast::http::to_string;
187+
using boost::beast::http::to_status_class;
188+
using boost::beast::http::write;
189+
using boost::beast::http::write_header;
190+
using boost::beast::http::write_some;
191+
192+
using boost::beast::http::error;
193+
using boost::beast::http::field;
194+
using boost::beast::http::status;
195+
using boost::beast::http::status_class;
196+
using boost::beast::http::verb;
197+
198+
// using boost::beast::http::is_body;
199+
using boost::beast::http::is_body_reader;
200+
using boost::beast::http::is_body_writer;
201+
using boost::beast::http::is_fields;
202+
using boost::beast::http::is_mutable_body_writer;
203+
204+
using boost::beast::http::ext_list;
205+
using boost::beast::http::opt_token_list;
206+
using boost::beast::http::param_list;
207+
using boost::beast::http::token_list;
208+
}
209+
210+
namespace websocket {
211+
using boost::beast::websocket::close_reason;
212+
using ping_data = boost::beast::static_string<125, char>;
213+
using boost::beast::websocket::stream;
214+
using boost::beast::websocket::stream_base;
215+
using reason_string = boost::beast::static_string<123, char>;
216+
217+
using boost::beast::websocket::async_teardown;
218+
using boost::beast::websocket::is_upgrade;
219+
using boost::beast::websocket::seed_prng;
220+
using boost::beast::websocket::teardown;
221+
222+
using boost::beast::websocket::permessage_deflate;
223+
224+
using boost::beast::websocket::close_code;
225+
using boost::beast::websocket::condition;
226+
using boost::beast::websocket::error;
227+
using boost::beast::websocket::frame_type;
228+
}
229+
230+
namespace zlib {
231+
using boost::beast::zlib::deflate_stream;
232+
using boost::beast::zlib::inflate_stream;
233+
using boost::beast::zlib::z_params;
234+
using boost::beast::zlib::deflate_upper_bound;
235+
using boost::beast::zlib::error;
236+
using boost::beast::zlib::Flush;
237+
using boost::beast::zlib::Strategy;
238+
}
239+
240+
namespace http {
241+
using boost::beast::http::icy_stream;
242+
}
243+
244+
namespace test {
245+
using boost::beast::test::fail_count;
246+
using boost::beast::test::handler;
247+
// using boost::beast::test::stream;
248+
using boost::beast::test::connect;
249+
using boost::beast::test::any_handler;
250+
using boost::beast::test::fail_handler;
251+
using boost::beast::test::success_handler;
252+
using boost::beast::test::error;
253+
}
254+
}

0 commit comments

Comments
 (0)