Skip to content

Commit 719d788

Browse files
avikivityxemul
authored andcommitted
modules: make module support standards-compliant
C++ doesn't allow #ifdef tricks with modules. Specifically, the module keywords can't be guarded with #ifdef. Here, we change the approach towards module support. It is heavily inspired by libstdc++ [1]. In the new approach, instead of two libraries, seastar and seastar-module, one without and one with module support, there is only one library. Module support comes in the form of a .cppm file that declares the module and exports the symbols. Changes in the patch: 1. remove SEASTAR_MODULE_EXPORT* defines; the export declarations are moved to seastar.cppm (causing some duplication) 2. remove the SEASTAR_MODULE define and unifdef the code it guards. There is a single complication pass rather than two. 3. The utils/modules.hh header is removed, since it no longer defines anything. 4. seastar.cc is renamed to seastar.cppm so the compiler understands it's a module definition. It now only includes headers that contain public symbols. The symbols to be exported are listed explicitly. 5. The cmake seastar library now conditionally includes seastar.cppm. 6. Minor cmake changes for hello-cxx-module to make it build. [1] https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/src/c%2B%2B23/std.cc.in Tested with clang 21. Fixes #3091 Closes #3101
1 parent cac1771 commit 719d788

File tree

186 files changed

+198
-1247
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+198
-1247
lines changed

CMakeLists.txt

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,16 @@ add_library (seastar
765765
src/websocket/server.cc
766766
)
767767

768+
if (Seastar_MODULE)
769+
target_sources(seastar
770+
PUBLIC
771+
FILE_SET CXX_MODULES
772+
TYPE CXX_MODULES
773+
FILES
774+
src/seastar.cppm
775+
)
776+
endif ()
777+
768778
add_library (Seastar::seastar ALIAS seastar)
769779

770780
add_dependencies (seastar
@@ -1176,7 +1186,6 @@ if (Seastar_MODULE)
11761186
cmake_policy (SET CMP0155 NEW)
11771187
endif ()
11781188
include (CxxModulesRules)
1179-
add_subdirectory (src)
11801189
endif ()
11811190

11821191
#
@@ -1338,7 +1347,7 @@ if (Seastar_INSTALL)
13381347
PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/seastar-json2code.py
13391348
DESTINATION ${CMAKE_INSTALL_BINDIR})
13401349

1341-
install (
1350+
set (seastar_install_targets
13421351
TARGETS
13431352
seastar
13441353
seastar_testing
@@ -1347,6 +1356,16 @@ if (Seastar_INSTALL)
13471356
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
13481357
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
13491358

1359+
if (Seastar_MODULE)
1360+
list (APPEND seastar_install_targets
1361+
FILE_SET CXX_MODULES
1362+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cxx/modules"
1363+
CXX_MODULES_BMI
1364+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cxx/bmi")
1365+
endif ()
1366+
1367+
install (${seastar_install_targets})
1368+
13501369
install (
13511370
EXPORT seastar-export
13521371
FILE SeastarTargets.cmake
@@ -1404,15 +1423,30 @@ if (Seastar_INSTALL)
14041423
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
14051424
RENAME seastar-testing.pc)
14061425

1426+
if (Seastar_MODULE)
1427+
install (
1428+
TARGETS seastar
1429+
CXX_MODULES_BMI
1430+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cxx/bmi"
1431+
FILE_SET CXX_MODULES
1432+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cxx/modules")
1433+
endif ()
1434+
14071435
#
14081436
# Export targets from the build tree for the user package registry.
14091437
#
14101438

1411-
export (
1439+
set (export_args
14121440
EXPORT seastar-export
14131441
FILE ${CMAKE_CURRENT_BINARY_DIR}/SeastarTargets.cmake
14141442
NAMESPACE Seastar::)
14151443

1444+
if (Seastar_MODULE)
1445+
list (APPEND export_args CXX_MODULES_DIRECTORY "include/cxx/modules")
1446+
endif ()
1447+
1448+
export (${export_args})
1449+
14161450
export (PACKAGE Seastar)
14171451

14181452
#

demos/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,9 @@ if (Seastar_MODULE)
130130
hello-cxx-module.cc)
131131
target_link_libraries (hello_cxx_module
132132
PRIVATE
133-
seastar-module)
133+
seastar)
134+
set_target_properties (hello_cxx_module
135+
PROPERTIES
136+
CXX_STANDARD ${CMAKE_CXX_STANDARD}
137+
CXX_EXTENSIONS ON)
134138
endif ()

include/seastar/core/abort_on_ebadf.hh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121

2222
#pragma once
2323

24-
#include <seastar/util/modules.hh>
2524

2625
namespace seastar {
2726

28-
SEASTAR_MODULE_EXPORT_BEGIN
2927

3028
/// Determines whether seastar should throw or abort when operation made by
3129
/// seastar fails because the target file descriptor is not valid. This is
@@ -37,6 +35,5 @@ void set_abort_on_ebadf(bool do_abort);
3735
/// See set_abort_on_ebadf().
3836
bool is_abort_on_ebadf_enabled();
3937

40-
SEASTAR_MODULE_EXPORT_END
4138

4239
}

include/seastar/core/abort_on_expiry.hh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <seastar/core/timer.hh>
2626
#include <seastar/core/lowres_clock.hh>
2727
#include <seastar/core/timed_out_error.hh>
28-
#include <seastar/util/modules.hh>
2928

3029
namespace seastar {
3130

@@ -34,7 +33,6 @@ namespace seastar {
3433

3534
/// Facility to tie a timeout with an abort source
3635
/// Can be used to make abortable fibers also support timeouts
37-
SEASTAR_MODULE_EXPORT
3836
template<typename Clock = lowres_clock>
3937
class abort_on_expiry {
4038
timer<Clock> _tr;

include/seastar/core/abort_source.hh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,20 @@
2222
#pragma once
2323

2424
#include <seastar/util/assert.hh>
25-
#include <seastar/util/modules.hh>
2625
#include <seastar/util/noncopyable_function.hh>
2726
#include <seastar/util/optimized_optional.hh>
2827
#include <seastar/util/std-compat.hh>
2928

30-
#ifndef SEASTAR_MODULE
3129
#include <boost/intrusive/list.hpp>
3230
#include <exception>
3331
#include <optional>
3432
#include <type_traits>
3533
#include <utility>
36-
#endif
3734

3835
namespace bi = boost::intrusive;
3936

4037
namespace seastar {
4138

42-
SEASTAR_MODULE_EXPORT_BEGIN
4339

4440
/// \addtogroup fiber-module
4541
/// @{
@@ -224,7 +220,6 @@ public:
224220

225221
/// @}
226222

227-
SEASTAR_MODULE_EXPORT_END
228223

229224
}
230225

include/seastar/core/abortable_fifo.hh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@
2525
#include <seastar/core/future.hh>
2626
#include <seastar/core/chunked_fifo.hh>
2727
#include <seastar/util/assert.hh>
28-
#include <seastar/util/modules.hh>
2928

30-
#ifndef SEASTAR_MODULE
3129
#include <memory>
3230
#include <optional>
3331
#include <type_traits>
34-
#endif
3532

3633
namespace seastar {
3734

include/seastar/core/alien.hh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,22 @@
2222

2323
#pragma once
2424

25-
#ifndef SEASTAR_MODULE
2625
#include <atomic>
2726
#include <concepts>
2827
#include <future>
2928
#include <memory>
3029
#include <type_traits>
3130
#include <boost/lockfree/queue.hpp>
32-
#endif
3331

3432
#include <seastar/core/future.hh>
3533
#include <seastar/core/cacheline.hh>
3634
#include <seastar/core/sstring.hh>
3735
#include <seastar/core/metrics_registration.hh>
38-
#include <seastar/util/modules.hh>
3936

4037
/// \file
4138

4239
namespace seastar {
4340

44-
SEASTAR_MODULE_EXPORT
4541
class reactor;
4642

4743
/// \brief Integration with non-seastar applications.
@@ -115,7 +111,6 @@ struct qs_deleter {
115111
/// system, there is just one instance, but for in-process clustering testing
116112
/// there may be more than one. Function such as run_on() direct messages to
117113
/// and (instance, shard) tuple.
118-
SEASTAR_MODULE_EXPORT
119114
class instance {
120115
using qs = std::unique_ptr<message_queue[], internal::qs_deleter>;
121116
public:
@@ -143,7 +138,6 @@ extern instance* default_instance;
143138
/// message queue managed by the shard executing the alien thread which is
144139
/// interested to the return value. Please use \c submit_to() instead, if
145140
/// \c func throws.
146-
SEASTAR_MODULE_EXPORT
147141
template <typename Func>
148142
requires std::is_nothrow_invocable_r_v<void, Func>
149143
void run_on(instance& instance, unsigned shard, Func func) {
@@ -199,7 +193,6 @@ template <typename Func> using return_type_t = typename return_type_of<Func>::ty
199193
/// the caller must guarantee that it will survive the call.
200194
/// \return whatever \c func returns, as a \c std::future<>
201195
/// \note the caller must keep the returned future alive until \c func returns
202-
SEASTAR_MODULE_EXPORT
203196
template<std::invocable Func, typename T = internal::return_type_t<Func>>
204197
std::future<T> submit_to(instance& instance, unsigned shard, Func func) {
205198
std::promise<T> pr;

include/seastar/core/align.hh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,11 @@
2121

2222
#pragma once
2323

24-
#ifndef SEASTAR_MODULE
25-
#include <seastar/util/modules.hh>
2624
#include <cstdint>
2725
#include <cstdlib>
28-
#endif
2926

3027
namespace seastar {
3128

32-
SEASTAR_MODULE_EXPORT_BEGIN
3329

3430
template <typename T>
3531
inline constexpr
@@ -57,6 +53,5 @@ T* align_down(T* v, size_t align) {
5753
return reinterpret_cast<T*>(align_down(reinterpret_cast<uintptr_t>(v), align));
5854
}
5955

60-
SEASTAR_MODULE_EXPORT_END
6156

6257
}

include/seastar/core/aligned_buffer.hh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,15 @@
1919
* Copyright (C) 2016 ScyllaDB.
2020
*/
2121
#pragma once
22-
#ifndef SEASTAR_MODULE
2322
#include <stdlib.h>
2423
#include <memory>
25-
#include <seastar/util/modules.hh>
26-
#endif
2724

2825
namespace seastar {
2926

3027
namespace internal {
3128
void* allocate_aligned_buffer_impl(size_t size, size_t align);
3229
}
3330

34-
SEASTAR_MODULE_EXPORT_BEGIN
3531

3632
struct free_deleter {
3733
void operator()(void* p) { ::free(p); }
@@ -45,6 +41,5 @@ std::unique_ptr<CharType[], free_deleter> allocate_aligned_buffer(size_t size, s
4541
return std::unique_ptr<CharType[], free_deleter>(reinterpret_cast<CharType *>(ret));
4642
}
4743

48-
SEASTAR_MODULE_EXPORT_END
4944

5045
}

include/seastar/core/app-template.hh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,16 @@
2020
*/
2121
#pragma once
2222

23-
#ifndef SEASTAR_MODULE
2423
#include <boost/program_options.hpp>
2524
#include <functional>
2625
#include <chrono>
27-
#endif
2826
#include <seastar/core/future.hh>
2927
#include <seastar/core/smp_options.hh>
3028
#include <seastar/core/sstring.hh>
3129
#include <seastar/util/program-options.hh>
3230
#include <seastar/core/metrics_api.hh>
3331
#include <seastar/core/scollectd.hh>
3432
#include <seastar/util/log-cli.hh>
35-
#include <seastar/util/modules.hh>
3633

3734
namespace seastar {
3835

@@ -44,7 +41,6 @@ class instance;
4441

4542
}
4643

47-
SEASTAR_MODULE_EXPORT
4844
class app_template {
4945
public:
5046
struct config {

0 commit comments

Comments
 (0)