Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test compatibility with newer C++ standards #258

Merged
merged 4 commits into from
Sep 24, 2024
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
270 changes: 270 additions & 0 deletions .github/workflows/cppstd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
# Copyright (C) 2024 Roberto Rossini (roberros@uio.no)
# SPDX-License-Identifier: MIT

name: Test compatibility with newer C++ standards

on:
push:
branches: [main]
paths:
- ".github/workflows/cppstd.yml"
- "cmake/**"
- "examples/**"
- "src/**"
- "test/scripts/**"
- "test/units/**"
- "CMakeLists.txt"
- "conanfile.py"
tags:
- "v*.*.*"

pull_request:
paths:
- ".github/workflows/cppstd.yml"
- "cmake/**"
- "examples/**"
- "src/**"
- "test/scripts/**"
- "test/units/**"
- "CMakeLists.txt"
- "conanfile.py"

# https://stackoverflow.com/a/72408109
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash

jobs:
build-deps:
runs-on: ubuntu-latest
name: Build dependencies
container:
image: ghcr.io/paulsengroup/ci-docker-images/ubuntu-24.04-cxx-clang-19
options: "--user=root"

outputs:
cache-key: ${{ steps.generate-cache-key.outputs.conan-key }}

env:
CONAN_HOME: "/opt/conan/"

steps:
- uses: actions/checkout@v4

- name: Fix permissions
run: |
chown -R $(id -u):$(id -g) $PWD

- name: Generate cache key
id: generate-cache-key
run: |
hash="${{ hashFiles('conanfile.py') }}"

echo "conan-key=conan-cppstd-$hash" | tee -a "$GITHUB_OUTPUT"

- name: Restore Conan cache
id: cache-conan
uses: actions/cache/restore@v4
with:
key: ${{ steps.generate-cache-key.outputs.conan-key }}
path: "${{ env.CONAN_HOME }}/p"
lookup-only: true

- name: Clean Conan cache (pre-build)
if: steps.cache-conan.outputs.cache-hit != 'true'
run: |
conan cache clean "*" --build
conan cache clean "*" --download
conan cache clean "*" --source
conan remove --confirm "*"

- name: Copy Conan settings
if: steps.cache-conan.outputs.cache-hit != 'true'
run: |
if [ ! -f "$CONAN_HOME/settings.yml" ]; then
cp "/root/.conan2/settings.yml" "$CONAN_HOME"
fi

- name: Install build dependencies (c++20)
if: steps.cache-conan.outputs.cache-hit != 'true'
run: |
conan install . \
--build=missing \
-pr:b="$CONAN_DEFAULT_PROFILE_PATH" \
-pr:h="$CONAN_DEFAULT_PROFILE_PATH" \
-s build_type=Debug \
-s compiler.libcxx=libstdc++11 \
-s compiler.cppstd=20

- name: Install build dependencies (c++23)
if: steps.cache-conan.outputs.cache-hit != 'true'
run: |
conan install . \
--build=missing \
-pr:b="$CONAN_DEFAULT_PROFILE_PATH" \
-pr:h="$CONAN_DEFAULT_PROFILE_PATH" \
-s build_type=Debug \
-s compiler.libcxx=libstdc++11 \
-s compiler.cppstd=23

- name: Clean Conan cache (post-build)
if: steps.cache-conan.outputs.cache-hit != 'true'
run: |
conan cache clean "*" --build
conan cache clean "*" --download
conan cache clean "*" --source

- name: Save Conan cache
uses: actions/cache/save@v4
if: steps.cache-conan.outputs.cache-hit != 'true'
with:
key: ${{ steps.generate-cache-key.outputs.conan-key }}
path: "${{ env.CONAN_HOME }}/p"

build-project:
runs-on: ubuntu-latest
name: Build project
needs: [build-deps]
container:
image: ghcr.io/paulsengroup/ci-docker-images/ubuntu-24.04-cxx-clang-19
options: "--user=root"

env:
CCACHE_DIR: "/opt/ccache-cache"
CCACHE_COMPILERCHECK: "content"
CCACHE_COMPRESSLEVEL: "1"
CCACHE_MAXSIZE: "150M"
CONAN_HOME: "/opt/conan/"

strategy:
fail-fast: false
matrix:
cppstd:
- 20
- 23

steps:
- uses: actions/checkout@v4

- name: Fix permissions
run: |
chown -R $(id -u):$(id -g) $PWD

- name: Generate cache key
id: generate-cache-key
run: |
conanfile_hash="${{ hashFiles('conanfile.py') }}"

# This can be used by to always update a cache entry (useful e.g. for ccache)
current_date="$(date '+%s')"

ccache_key_prefix="ccache-cppstd-${{ matrix.cppstd }}-$conanfile_hash"

echo "ccache-key=${ccache_key_prefix}-${current_date}" | tee -a "$GITHUB_OUTPUT"
echo "ccache-restore-key=$ccache_key_prefix" | tee -a "$GITHUB_OUTPUT"

- name: Restore Conan cache
id: cache-conan
uses: actions/cache/restore@v4
with:
key: ${{ needs.build-deps.outputs.cache-key }}
path: "${{ env.CONAN_HOME }}/p"
fail-on-cache-miss: true

- name: Copy Conan settings
run: |
if [ ! -f "$CONAN_HOME/settings.yml" ]; then
cp "/root/.conan2/settings.yml" "$CONAN_HOME"
fi

- name: Install build dependencies
run: |
conan install . \
--build=never \
-pr:b="$CONAN_DEFAULT_PROFILE_PATH" \
-pr:h="$CONAN_DEFAULT_PROFILE_PATH" \
-s build_type=Debug \
-s compiler.libcxx=libstdc++11 \
-s compiler.cppstd=${{ matrix.cppstd }} \
--output-folder=build

- name: Install Python headers
run: |
apt-get update
apt-get install -y python3.12-dev

- name: Configure project
run: |
find src test \
-type f \
-name CMakeLists.txt \
-exec sed -i 's/set(CMAKE_CXX_STANDARD 17)/set(CMAKE_CXX_STANDARD ${{ matrix.cppstd }})/' {} +

cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_PREFIX_PATH="$PWD/build" \
-DHICTK_ENABLE_TESTING=ON \
-DHICTK_ENABLE_FUZZY_TESTING=ON \
-DHICTK_BUILD_TOOLS=OFF \
-DHICTK_BUILD_EXAMPLES=ON \
-DHICTK_DOWNLOAD_TEST_DATASET=OFF \
-DHICTK_ENABLE_GIT_VERSION_TRACKING=OFF \
-S . \
-B build

- name: Restore Ccache folder
id: cache-ccache
uses: actions/cache/restore@v4
with:
key: ${{ steps.generate-cache-key.outputs.ccache-restore-key }}
path: ${{ env.CCACHE_DIR }}

- name: Reset Ccache stats
run: ccache --zero-stats

- name: Build project
run: cmake --build build -j $(nproc)

- name: Print Ccache statistics (pre-cleanup)
run: |
ccache --show-stats \
--show-compression \
--verbose

- name: Cleanup Ccache folder
run: |
ccache --evict-older-than=14400s # 4h
ccache --recompress=19 --recompress-threads="$(nproc)"
ccache --cleanup

- name: Print Ccache statistics (post-cleanup)
run: |
ccache --show-stats \
--show-compression \
--verbose

- name: Save Ccache folder
uses: actions/cache/save@v4
with:
key: ${{ steps.generate-cache-key.outputs.ccache-key }}
path: ${{ env.CCACHE_DIR }}
env:
ZSTD_CLEVEL: 1

cppstd-status-check:
name: Status Check (cppstd)
if: ${{ always() }}
runs-on: ubuntu-latest
needs:
- build-deps
- build-project

steps:
- name: Collect job results
if: |
needs.build-deps.result != 'success' ||
needs.build-project.result != 'success'
run: exit 1
1 change: 1 addition & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def configure(self):
self.options["boost"].without_atomic = False
self.options["boost"].without_charconv = True
self.options["boost"].without_chrono = True
self.options["boost"].without_cobalt = True
self.options["boost"].without_container = True
self.options["boost"].without_context = True
self.options["boost"].without_contract = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ inline HighFive::File File::open_file(std::string_view uri, unsigned int mode, b
throw std::runtime_error(
fmt::format(FMT_STRING("\"{}\" does not look like a valid Cooler file:\n"
"Validation report:\n{}"),
uri, status));
uri, fmt::to_string(status)));
}

return f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace internal {
}

template <typename NameMap>
[[nodiscard]] inline std::vector<std::string>& rename_chromosomes(std::vector<std::string>&& names,
const NameMap& mappings) {
[[nodiscard]] inline std::vector<std::string> rename_chromosomes(std::vector<std::string>&& names,
const NameMap& mappings) {
for (auto& name : names) {
auto it = mappings.find(name);
if (it != mappings.end()) {
Expand Down Expand Up @@ -82,9 +82,8 @@ inline void rename_chromosomes(cooler::Dataset& chrom_dset, const NameMap& mappi
if (mappings.empty()) {
return;
}
auto names = chrom_dset.read_all<std::vector<std::string>>();

names = internal::rename_chromosomes(std::move(names), mappings);
const auto names =
internal::rename_chromosomes(chrom_dset.read_all<std::vector<std::string>>(), mappings);

// NOLINTNEXTLINE(misc-const-correctness)
auto h5f = chrom_dset().getFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct SingleCellAttributes {
class SingleCellFile {
std::unique_ptr<RootGroup> _root_grp{};
phmap::btree_set<std::string> _cells{};
SingleCellAttributes _attrs{};
SingleCellAttributes _attrs{SingleCellAttributes::init_empty()};
std::shared_ptr<const BinTable> _bins{};

SingleCellFile(HighFive::File fp, BinTable bins, SingleCellAttributes attrs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@

#pragma once

// clang-format: off
#include "hictk/suppress_warnings.hpp"

HICTK_DISABLE_WARNING_PUSH
HICTK_DISABLE_WARNING_DEPRECATED_DECLARATIONS
#include <arrow/array.h>
#include <arrow/builder.h>
#include <arrow/compute/api_vector.h>
#include <arrow/datum.h>
#include <arrow/table.h>
#include <arrow/type.h>
HICTK_DISABLE_WARNING_POP
// clang-format: on

#include <algorithm>
#include <cassert>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@

#ifdef HICTK_WITH_ARROW

// clang-format: off
#include "hictk/suppress_warnings.hpp"

HICTK_DISABLE_WARNING_PUSH
HICTK_DISABLE_WARNING_DEPRECATED_DECLARATIONS
#include <arrow/builder.h>
#include <arrow/table.h>
#include <arrow/type.h>
HICTK_DISABLE_WARNING_POP
// clang-format: on

#include <memory>
#include <type_traits>
Expand Down
Loading