|
Boost : |
From: Chuanqi Xu (chuanqi.xcq_at_[hidden])
Date: 2024-12-17 02:37:22
Hi Boost Developers,
I am Chuanqi Xu, the maintainer for modules & serialization in clang and also a fan of C++20 modules. The post itself was motivated by a discussion (https://cpplang.slack.com/archives/C27KZLB0X/p1734335425348809 <https://cpplang.slack.com/archives/C27KZLB0X/p1734335425348809 >). You donât need to read it if youâre not interested. Iâll try to make the post itself self contained.
The original story comes from a high quality experiment for C++20 modules in boost (https://anarthal.github.io/cppblog/modules2 <https://anarthal.github.io/cppblog/modules2 >). The blog reads pretty good to me. However, anarthal (the author) told me later that the process of supporting modules in boost got suspended since the authors (or the maintainers) donât want it since no one is going to use them. And if I want it, I need to send a mail here. Then this is the beginning of the story.
First of first, I want to emphasize that âno one is going to use themâ is not true. Weâve already used C++20 modules at larger scale internally for roughly a year. For boost (and other third party libraries), we choose to wrap a module ourselves as a workaround (with some compiler extensions to ease the refacotoring, but we donât like it. We still want standard behavior). We didnât reach out since we feel boost will support C++20 modules later or sooner so we donât need to do anything specially. (Maybe we were wrong. We didnât understand the ecosystem enough). Until yesterday, I just knew that boost didnât know such needs.
Before I wrote this email, I wondered a lot of words to emphasize that our need are a good example and the users of closed source are important users too. But just now, I searched the use of boost in modules in GitHub. I just realized I can show it (the importance of C++20 modules support for boost) much easily with the open source world. I searched `boost path:*.cppm` in GitHub and got the following list:
https://github.com/infiniflow/infinity/blob/fa922afd58c973a9a317d2c09ad8cea8984af91e/src/common/boost.cppm#L17 <https://github.com/infiniflow/infinity/blob/fa922afd58c973a9a317d2c09ad8cea8984af91e/src/common/boost.cppm#L17 >
https://github.com/ossia/score/blob/0ce6f62a97651a1248a92b3e13ce6ede10341d1f/src/plugins/score-plugin-avnd/halp.cppm#L74 <https://github.com/ossia/score/blob/0ce6f62a97651a1248a92b3e13ce6ede10341d1f/src/plugins/score-plugin-avnd/halp.cppm#L74 >
https://github.com/RichardLuo0/make-dot-cpp/blob/e2ef10fd43060a2b56fc8f87f1407e4e3b1c2b8e/src/utils/module.cppm#L4 <https://github.com/RichardLuo0/make-dot-cpp/blob/e2ef10fd43060a2b56fc8f87f1407e4e3b1c2b8e/src/utils/module.cppm#L4 >
https://github.com/slaakko/cmajor-mod/blob/32e6eb8dc099b395fa751340de96f47817f92977/cmajor/system-x/machine/clock.cppm#L7 <https://github.com/slaakko/cmajor-mod/blob/32e6eb8dc099b395fa751340de96f47817f92977/cmajor/system-x/machine/clock.cppm#L7 >
https://github.com/df-com/dragonfly/blob/9dfcbc1153f292eb8581f1df7459600cc331c690/dragonfly/Chart.cppm#L9 <https://github.com/df-com/dragonfly/blob/9dfcbc1153f292eb8581f1df7459600cc331c690/dragonfly/Chart.cppm#L9 >
https://github.com/nofe1248/Helium/blob/92ec4452b8c05e6d86c972f843196a4392a7a6da/Events/EventBus/Helium.Events.EventBus.cppm#L20 <https://github.com/nofe1248/Helium/blob/92ec4452b8c05e6d86c972f843196a4392a7a6da/Events/EventBus/Helium.Events.EventBus.cppm#L20 >
https://github.com/LagrangeDev/liblagrange/blob/10e3b48f8d47fd65de00b14cfed64c0be18c083d/src/base/transport/service.cppm#L7 <https://github.com/LagrangeDev/liblagrange/blob/10e3b48f8d47fd65de00b14cfed64c0be18c083d/src/base/transport/service.cppm#L7 >
https://github.com/yudaichen/feature-db/blob/e94ade969af682ed5dd25d70bf282ba39253cbf0/src/common/small_utils.cppm#L7 <https://github.com/yudaichen/feature-db/blob/e94ade969af682ed5dd25d70bf282ba39253cbf0/src/common/small_utils.cppm#L7 >
This is not a complete list even for my search only and I believe there are other patterns to use boost with modules now (e.g., at least `*.cppm` is not the defacto suffix).
And I also believe, from my experience as a C++ user, if boost provide modules, I may try to use it. But if boost didnât provide it, maybe I wonât ask for it if I donât want modules super bad. Since modules doesnât add any new functionality actually. So most users may not ask for it explicitly. But if boost provides it, people may give it a try.
The above text are the body of the post. I hope it can show it is needed.
â
Following of are some technical discussion for the extra maintainance burden by introducing modules. The conclusion is, I think, the burden is pretty low.
Since modules are not complex to users. Different from other big features in C++, modules are pretty easy to understand. The complexity of modules are majorly on tools and the ecosystem. For programmers who donât get involved to much to the ecosystem (or infrastructure), modules should be pretty easy to understand.
For authors of libraries, after boost introduce modules, you only need to do 2 extra things:
- In headers, add a macro (assume its name as BOOST_MODULE_EXPORT, which will be âexportâ conditionally) to the entities that need to be exported.
- In headers, include standard headers and other dependent headers conditionally so that we donât include anything if the headers are in a module unit. e.g., https://github.com/boostorg/pfr/blob/f09e6aeae9d050897fff72b93d5f5e866cc5e11a/include/boost/pfr/detail/for_each_field.hpp#L12-L16 <https://github.com/boostorg/pfr/blob/f09e6aeae9d050897fff72b93d5f5e866cc5e11a/include/boost/pfr/detail/for_each_field.hpp#L12-L16 >
then thatâs roughly all you need for maintaining it at source level. For building and distributing related things, anarthal told me that the boost will handle it globally so the individual arthors donât need to care about it.
â
In slack, there are some other discussion about module names and linking problems (https://cpplang.slack.com/archives/C27KZLB0X/p1734345716728609 <https://cpplang.slack.com/archives/C27KZLB0X/p1734345716728609 >). But I feel they are implementation details. I may not talk too much for that as a user at least now.
And also there are opinions for configuration flags. These are the jobs of build systems (cmake is working on it). I think boost donât need to worry for that. Similarly, at least libc++ has similar problems but libc++ still released std module.
â
Boost has a special position in the C++âs ecosystem. The most simple and impressive answer Iâve heard for the question âwhen can we start to use modulesâ is, âwhen boost makes itâ.
Thanks,
Chuanqi
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk