Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ cmake -S . -B build -G Ninja -DHIBF_MODULE=ON
#include <cstddef>
#include <vector>

import hibf;
import seqan.hibf;

int main()
{
Expand All @@ -191,17 +191,17 @@ int main()
On top of HIBF's usual requirements, this needs CMake >= 3.28 and the Ninja generator; every compiler
HIBF supports can build the module. CI covers the latest GCC and Clang version.

The switch is additive rather than exclusive. `src/hibf.cppm` includes the headers in its *global module fragment*, so
imported and included declarations name the same entities:
The switch is additive rather than exclusive. `src/seqan.hibf.cppm` includes the headers in its *global module
fragment*, so imported and included declarations name the same entities:

* `libhibf.a` is the same either way; the module adds one almost empty object file.
* Headers keep working unchanged, and a single translation unit may both `#include <hibf/...>` and `import hibf;`.
* Headers keep working unchanged, and a single translation unit may both `#include <hibf/...>` and `import seqan.hibf;`.
Downstream projects can therefore migrate file by file.
* `HIBF_HAS_MODULE` is defined when the module was built, for code that has to support both modes.

Two caveats:

* Only the names listed in `src/hibf.cppm` are visible to importers. `seqan::stl` (the `include/hibf/contrib` standard
library backports) is not exported; use the headers for those.
* GCC 16 rejects a textual `#include` that appears *after* an `import hibf;` in the same translation unit. Put includes
first. Clang accepts either order.
* Only the names listed in `src/seqan.hibf.cppm` are visible to importers. `seqan::stl` (the `include/hibf/contrib`
standard library backports) is not exported; use the headers for those.
* GCC 16 rejects a textual `#include` that appears *after* an `import seqan.hibf;` in the same translation unit. Put
includes first. Clang accepts either order.
5 changes: 3 additions & 2 deletions cmake/configuration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ hibf_require_ccache ()
# Optional: C++20 modules
# ----------------------------------------------------------------------------

# The module is an addition, not a replacement: the headers and libhibf.a are the same either way. See src/hibf.cppm.
option (HIBF_MODULE "Additionally build the `hibf` C++20 module. Consumers may then use `import hibf;`." OFF)
# The module is an addition, not a replacement: the headers and libhibf.a are the same either way.
# See src/seqan.hibf.cppm.
option (HIBF_MODULE "Additionally build the `seqan.hibf` C++20 module, enabling `import seqan.hibf;`." OFF)

if (HIBF_MODULE)
if (CMAKE_VERSION VERSION_LESS 3.28)
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if (NOT TARGET hibf)
target_sources (hibf
PUBLIC FILE_SET hibf_module TYPE CXX_MODULES
BASE_DIRS "${CMAKE_CURRENT_LIST_DIR}"
FILES "${CMAKE_CURRENT_LIST_DIR}/hibf.cppm")
FILES "${CMAKE_CURRENT_LIST_DIR}/seqan.hibf.cppm")
# cmake-format: on

# Lets downstream code branch on the build mode.
Expand Down
11 changes: 6 additions & 5 deletions src/hibf.cppm → src/seqan.hibf.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/*!\file
* \author Enrico Seiler <enrico.seiler AT fu-berlin.de>
* \brief Provides the `hibf` C++20 module.
* \brief Provides the `seqan.hibf` C++20 module.
*
* \details
*
Expand All @@ -14,14 +14,15 @@
* * `libhibf.a` is bit-identical whether or not the module is built; the module adds one (almost empty) object file.
* * The source files in `src` need no changes: they are ordinary translation units, and the symbols they define are
* the same symbols the module declares.
* * A translation unit may `#include <hibf/...>` and `import hibf;` at the same time. Both refer to the same entities,
* so there is no ODR hazard and downstream projects can migrate file by file.
* * A translation unit may `#include <hibf/...>` and `import seqan.hibf;` at the same time. Both refer to the same
* entities, so there is no ODR hazard and downstream projects can migrate file by file.
*
* The price is that the exported names have to be listed explicitly below. Names that are absent from this list are
* still *reachable* (e.g. a member function of an exported class can use them), just not *visible* to importers.
*
* \attention GCC (as of 16.2) rejects a textual `#include` of a standard library header that appears *after* an
* `import hibf;` in the same translation unit. Put includes before imports. Clang has no such restriction.
* `import seqan.hibf;` in the same translation unit. Put includes before imports. Clang has no such
* restriction.
*/

module;
Expand Down Expand Up @@ -75,7 +76,7 @@ module;
// Module purview
// ============================================================================

export module hibf;
export module seqan.hibf;

//!\brief The main namespace of the HIBF library.
export namespace seqan::hibf
Expand Down
2 changes: 1 addition & 1 deletion test/all/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cmake_minimum_required (VERSION 3.20...3.31)
project (hibf_test)

option (INSTALL_HIBF "" OFF)
option (HIBF_MODULE "Additionally build the `hibf` C++20 module." OFF)
option (HIBF_MODULE "Additionally build the `seqan.hibf` C++20 module." OFF)
enable_testing ()
add_subdirectory (../unit/ unit)
add_subdirectory (../performance/ performance)
Expand Down
6 changes: 3 additions & 3 deletions test/module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
cmake_minimum_required (VERSION 3.28...3.31)
project (hibf_test_module CXX)

# These tests `import hibf;`, so the module has to be part of the library.
# These tests `import seqan.hibf;`, so the module has to be part of the library.
set (HIBF_MODULE
ON
CACHE BOOL "Additionally build the `hibf` C++20 module." FORCE)
CACHE BOOL "Additionally build the `seqan.hibf` C++20 module." FORCE)

include (../hibf-test.cmake)
include (GoogleTest OPTIONAL)
Expand All @@ -31,7 +31,7 @@ macro (hibf_module_test module_test_cpp)
add_executable (${target} ${module_test_cpp})
# This is `hibf::test::unit` spelled out. `seqan::hibf` has to be a *direct* link dependency: with
# HIBF_POST_INSTALL_TEST it is an IMPORTED target, and CMake (4.0) does not propagate the module usage requirements
# of an imported target through an intermediate INTERFACE library -- `import hibf;` then fails with "no such
# of an imported target through an intermediate INTERFACE library -- `import seqan.hibf;` then fails with "no such
# module". Going through `hibf::test::unit` as well would put libhibf.a on the link line twice, which Clang's
# ThinLTO rejects.
target_link_libraries (${target} GTest::gtest_main seqan::hibf)
Expand Down
6 changes: 3 additions & 3 deletions test/module/hibf_module_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: BSD-3-Clause

/*!\file
* \brief Checks that the public API is usable through `import hibf;`.
* \brief Checks that the public API is usable through `import seqan.hibf;`.
* \details
* Every textual `#include` must appear before the `import`: GCC 16 rejects the reverse order (it sees the standard
* library declarations of the global module fragment a second time). Clang accepts both orders.
Expand All @@ -20,7 +20,7 @@

#include <cereal/archives/binary.hpp>

import hibf;
import seqan.hibf;

TEST(module_test, version)
{
Expand Down Expand Up @@ -124,7 +124,7 @@ TEST(module_test, serialisation)
TEST(module_test, path_serialisation)
{
// hibf/cereal/path.hpp adds `save`/`load` overloads in namespace cereal. cereal finds them by ADL, so they have to
// be visible to importers, not merely reachable. See the `export namespace cereal` block in src/hibf.cppm.
// be visible to importers, not merely reachable. See the `export namespace cereal` block in src/seqan.hibf.cppm.
std::filesystem::path const original{"/some/random/path.txt"};

std::stringstream stream{};
Expand Down
8 changes: 4 additions & 4 deletions test/module/mixed_mode_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// SPDX-License-Identifier: BSD-3-Clause

/*!\file
* \brief Checks that headers and `import hibf;` can be mixed within one translation unit.
* \brief Checks that headers and `import seqan.hibf;` can be mixed within one translation unit.
* \details
* Because src/hibf.cppm includes the headers in its global module fragment, an imported entity and an included entity
* are the *same* entity. A project can therefore migrate to the module file by file instead of all at once.
* Because src/seqan.hibf.cppm includes the headers in its global module fragment, an imported entity and an included
* entity are the *same* entity. A project can therefore migrate to the module file by file instead of all at once.
*/

#include <gtest/gtest.h>
Expand All @@ -17,7 +17,7 @@
#include <hibf/interleaved_bloom_filter.hpp>
#include <hibf/misc/bit_vector.hpp>

import hibf;
import seqan.hibf;

TEST(mixed_mode_test, same_entity)
{
Expand Down
Loading