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
2 changes: 1 addition & 1 deletion .github/workflows/ci_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ jobs:

- name: Run tests
working-directory: build
run: ctest . -j
run: ctest . -j --output-on-failure --no-tests=error

90 changes: 90 additions & 0 deletions .github/workflows/ci_module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# SPDX-FileCopyrightText: 2006-2026, Knut Reinert & Freie Universität Berlin
# SPDX-FileCopyrightText: 2016-2026, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: CC0-1.0

name: Module

on:
push:
branches:
- 'main'
pull_request:
types:
- unlabeled
workflow_dispatch:

concurrency:
group: module-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name != 'push' }}

env:
TZ: Europe/Berlin

defaults:
run:
shell: bash -Eexuo pipefail {0}

jobs:
build:
runs-on: ubuntu-latest
name: ${{ matrix.compiler }}
if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch' || github.event.label.name == 'lint'
strategy:
fail-fast: false
matrix:
compiler: ["clang-latest", "gcc-latest"]
container:
image: ghcr.io/seqan/${{ matrix.compiler }}
steps:
- name: Checkout
uses: actions/checkout@v7

- name: Setup cache
uses: seqan/actions/setup-actions-cache@main

- name: Configure tests
run: |
mkdir build && cd build
cmake ../test/module -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR=Ninja
ninja gtest_main

- name: Build tests
working-directory: build
run: |
ccache -z
ninja -k 0

- name: Run tests
working-directory: build
run: ctest . -j --output-on-failure --no-tests=error

- name: Install dependencies
run: |
apt-get update 1>/dev/null
apt-get install --yes --no-install-recommends \
libcereal-dev \
libgtest-dev \
libsimde-dev \
pkgconf \
1>/dev/null

- name: Install hibf
run: |
mkdir build_install && cd build_install
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR=Ninja -DHIBF_MODULE=ON
ninja install

- name: Configure post-install tests
run: |
mkdir build_post_install && cd build_post_install
cmake ../test/module -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR=Ninja -DHIBF_POST_INSTALL_TEST=ON

- name: Build post-install tests
working-directory: build_post_install
run: |
ninja -k 0
ccache -sv

- name: Run post-install tests
working-directory: build_post_install
run: ctest . -j --output-on-failure --no-tests=error
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,46 @@ int main()
<!-- The below code snippet is automatically added from ./test/snippet/readme.cpp -->
<!-- MARKDOWN-AUTO-DOCS:END -->

## C++20 modules (experimental)

HIBF can additionally be consumed as a named module. Configure with `-DHIBF_MODULE=ON`:

```bash
cmake -S . -B build -G Ninja -DHIBF_MODULE=ON
```

`seqan::hibf` then also carries a `CXX_MODULES` file set, and consumers can write:

```cpp
#include <cstddef>
#include <vector>

import hibf;

int main()
{
seqan::hibf::interleaved_bloom_filter ibf{seqan::hibf::bin_count{64u}, seqan::hibf::bin_size{1024u}};
ibf.emplace(126u, seqan::hibf::bin_index{0u});

auto agent = ibf.containment_agent();
return agent.bulk_contains(126u)[0u] ? 0 : 1;
}
```

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:

* `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;`.
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.
30 changes: 26 additions & 4 deletions cmake/configuration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ set (CMAKE_REQUIRED_FLAGS ${CMAKE_CXX_FLAGS})
# Check supported compilers
# ----------------------------------------------------------------------------

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12)
hibf_config_error ("GCC < 12 is not supported. The detected compiler version is ${CMAKE_CXX_COMPILER_VERSION}.")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14)
hibf_config_error ("GCC < 14 is not supported. The detected compiler version is ${CMAKE_CXX_COMPILER_VERSION}.")
endif ()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17)
hibf_config_error ("Clang < 17 is not supported. The detected compiler version is ${CMAKE_CXX_COMPILER_VERSION}.")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 20)
hibf_config_error ("Clang < 20 is not supported. The detected compiler version is ${CMAKE_CXX_COMPILER_VERSION}.")
endif ()

# ----------------------------------------------------------------------------
Expand All @@ -80,6 +80,28 @@ endif ()
include ("${HIBF_SOURCE_DIR}/test/cmake/hibf_require_ccache.cmake")
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)

if (HIBF_MODULE)
if (CMAKE_VERSION VERSION_LESS 3.28)
hibf_config_error ("HIBF_MODULE requires CMake >= 3.28. The detected version is ${CMAKE_VERSION}.")
endif ()

# CMake can only order module builds with a generator that supports dynamic dependencies.
if (NOT CMAKE_GENERATOR MATCHES "Ninja")
hibf_config_error ("HIBF_MODULE requires Ninja, not the ${CMAKE_GENERATOR} generator.")
endif ()

hibf_config_print ("C++20 module: enabled")
else ()
hibf_config_print ("C++20 module: disabled")
endif ()

# ----------------------------------------------------------------------------
# Required: 128 bit unsigned integer extension
# ----------------------------------------------------------------------------
Expand Down
17 changes: 15 additions & 2 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,26 @@ if (TARGET simde)
list (APPEND HIBF_EXPORT_TARGETS "simde")
endif ()

# The module interface unit is installed as a source file: importers compile it themselves, because a BMI is only
# valid for the exact compiler and flags that produced it. `install (EXPORT ... CXX_MODULES_DIRECTORY)` writes the
# per-configuration properties that tell a consuming project how to do that.
if (HIBF_MODULE)
set (HIBF_INSTALL_MODULE_ARGS FILE_SET hibf_module DESTINATION "${CMAKE_INSTALL_DATADIR}/hibf/module")
set (HIBF_EXPORT_MODULE_ARGS CXX_MODULES_DIRECTORY "hibf-modules")
else ()
set (HIBF_INSTALL_MODULE_ARGS "")
set (HIBF_EXPORT_MODULE_ARGS "")
endif ()

# cmake-format: off
install (TARGETS ${HIBF_EXPORT_TARGETS}
EXPORT hibf_targets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})
FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
${HIBF_INSTALL_MODULE_ARGS})
# cmake-format: on

install (DIRECTORY "${HIBF_HEADER_PATH}/hibf" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
Expand All @@ -26,7 +38,8 @@ install (EXPORT hibf_targets
NAMESPACE seqan::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hibf
EXPORT_LINK_INTERFACE_LIBRARIES
FILE hibf-targets.cmake)
FILE hibf-targets.cmake
${HIBF_EXPORT_MODULE_ARGS})

include (CMakePackageConfigHelpers)
configure_package_config_file (cmake/hibf-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/hibf-config.cmake
Expand Down
4 changes: 2 additions & 2 deletions include/hibf/hierarchical_interleaved_bloom_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ namespace bin_kind
{

//!\brief The value that indicates a merged bin.
static constexpr uint64_t merged{std::numeric_limits<uint64_t>::max()};
inline constexpr uint64_t merged{std::numeric_limits<uint64_t>::max()};
//!\brief The value that indicates a deleted bin.
static constexpr uint64_t deleted{std::numeric_limits<uint64_t>::max() - 1u};
inline constexpr uint64_t deleted{std::numeric_limits<uint64_t>::max() - 1u};

} // namespace bin_kind

Expand Down
18 changes: 9 additions & 9 deletions include/hibf/layout/prefixes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@ namespace seqan::hibf::prefix
* ```
* \{
*/
constexpr std::string_view meta_header{"@"};
inline constexpr std::string_view meta_header{"@"};

constexpr std::string_view meta_hibf_config_start{"@HIBF_CONFIG"};
inline constexpr std::string_view meta_hibf_config_start{"@HIBF_CONFIG"};
static_assert(meta_hibf_config_start.starts_with(meta_header));

constexpr std::string_view meta_hibf_config_end{"@HIBF_CONFIG_END"};
inline constexpr std::string_view meta_hibf_config_end{"@HIBF_CONFIG_END"};
static_assert(meta_hibf_config_end.starts_with(meta_header));

constexpr std::string_view layout_header{"#"};
inline constexpr std::string_view layout_header{"#"};

constexpr std::string_view layout_top_level{"TOP_LEVEL_IBF"};
inline constexpr std::string_view layout_top_level{"TOP_LEVEL_IBF"};

constexpr std::string_view layout_lower_level{"LOWER_LEVEL_IBF"};
inline constexpr std::string_view layout_lower_level{"LOWER_LEVEL_IBF"};

constexpr std::string_view layout_fullest_technical_bin_idx{"fullest_technical_bin_idx:"};
inline constexpr std::string_view layout_fullest_technical_bin_idx{"fullest_technical_bin_idx:"};

constexpr std::string_view layout_first_header_line{"#TOP_LEVEL_IBF"};
inline constexpr std::string_view layout_first_header_line{"#TOP_LEVEL_IBF"};
static_assert(layout_first_header_line.starts_with(layout_header));
static_assert(layout_first_header_line.ends_with(layout_top_level));

constexpr std::string_view layout_column_names{"#USER_BIN_IDX\tTECHNICAL_BIN_INDICES\tNUMBER_OF_TECHNICAL_BINS"};
inline constexpr std::string_view layout_column_names{"#USER_BIN_IDX\tTECHNICAL_BIN_INDICES\tNUMBER_OF_TECHNICAL_BINS"};
static_assert(layout_column_names.starts_with(layout_header));
//!\}

Expand Down
2 changes: 1 addition & 1 deletion include/hibf/misc/print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ struct print_t
void operator()(std::vector<uint64_t> const & vector, std::ostream & stream = std::cout) const;
};

static inline constexpr auto print = print_t{};
inline constexpr auto print = print_t{};

} // namespace seqan::hibf
10 changes: 5 additions & 5 deletions include/hibf/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ namespace seqan::hibf
{

//!\brief The major version.
constexpr uint8_t hibf_version_major = HIBF_VERSION_MAJOR;
inline constexpr uint8_t hibf_version_major = HIBF_VERSION_MAJOR;
//!\brief The minor version.
constexpr uint8_t hibf_version_minor = HIBF_VERSION_MINOR;
inline constexpr uint8_t hibf_version_minor = HIBF_VERSION_MINOR;
//!\brief The patch version.
constexpr uint8_t hibf_version_patch = HIBF_VERSION_PATCH;
inline constexpr uint8_t hibf_version_patch = HIBF_VERSION_PATCH;

//!\brief The full version as `std::size_t`.
constexpr std::size_t hibf_version = HIBF_VERSION;
inline constexpr std::size_t hibf_version = HIBF_VERSION;

//!\brief The full version as null terminated string.
constexpr char const * hibf_version_cstring = HIBF_VERSION_CSTRING;
inline constexpr char const * hibf_version_cstring = HIBF_VERSION_CSTRING;

} // namespace seqan::hibf

Expand Down
17 changes: 17 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,21 @@ if (NOT TARGET hibf)

target_include_directories (hibf PUBLIC "$<BUILD_INTERFACE:${HIBF_HEADER_PATH}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")

if (HIBF_MODULE)
# The module interface unit includes all headers in its global module fragment, so it declares exactly the
# entities that ${HIBF_SOURCE_FILES} define. Those sources neither import nor export anything; skipping the
# scanner for them keeps the dependency graph (and the build) as it is in a header build.
set_source_files_properties (${HIBF_SOURCE_FILES} PROPERTIES CXX_SCAN_FOR_MODULES OFF)

# cmake-format: off
target_sources (hibf
PUBLIC FILE_SET hibf_module TYPE CXX_MODULES
BASE_DIRS "${CMAKE_CURRENT_LIST_DIR}"
FILES "${CMAKE_CURRENT_LIST_DIR}/hibf.cppm")
# cmake-format: on

# Lets downstream code branch on the build mode.
target_compile_definitions (hibf PUBLIC "HIBF_HAS_MODULE=1")
endif ()
endif ()
Loading
Loading