Skip to content

Commit

Permalink
Re-apply 3389 for C++20 -> 17
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Dec 9, 2024
1 parent 7702105 commit 7181f50
Show file tree
Hide file tree
Showing 33 changed files with 945 additions and 312 deletions.
2 changes: 1 addition & 1 deletion apis/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def run(self):
library_dirs=LIB_DIRS,
libraries=["tiledbsoma"] + (["tiledb"] if os.name == "nt" else []),
extra_link_args=CXX_FLAGS,
extra_compile_args=["-std=c++20" if os.name != "nt" else "/std:c++20"]
extra_compile_args=["-std=c++17" if os.name != "nt" else "/std:c++17"]
+ CXX_FLAGS,
language="c++",
)
Expand Down
23 changes: 11 additions & 12 deletions apis/python/src/tiledbsoma/fastercsx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
/* #define FASTERCSX__DEBUGGING_HOOKS 1 */

#include <tiledbsoma/utils/fastercsx.h>
#include <span>
#include "common.h"

namespace libtiledbsomacpp {
Expand Down Expand Up @@ -76,36 +75,36 @@ std::vector<T> to_vector_(const py::tuple& tup) {
*/

template <typename T>
std::span<T const> make_span_(py::array arr) {
tcb::span<T const> make_span_(py::array arr) {
assert(py::isinstance<py::array_t<T>>(arr));
return std::span<T const>(arr.unchecked<T, 1>().data(0), arr.size());
return tcb::span<T const>(arr.unchecked<T, 1>().data(0), arr.size());
}

template <typename T>
std::span<T> make_mutable_span_(py::array arr) {
tcb::span<T> make_mutable_span_(py::array arr) {
assert(py::isinstance<py::array_t<T>>(arr));
return std::span<T>(
return tcb::span<T>(
arr.mutable_unchecked<T, 1>().mutable_data(0), arr.size());
}

template <typename T, typename R>
std::span<R const> make_casted_span_(py::array arr) {
tcb::span<R const> make_casted_span_(py::array arr) {
static_assert(sizeof(T) == sizeof(R));
assert(py::isinstance<py::array_t<T>>(arr));
std::remove_cv_t<T>* p = (std::remove_cv_t<T>*)arr
.unchecked<std::remove_cv_t<T>, 1>()
.data(0);
return std::span<R const>(reinterpret_cast<R*>(p), arr.size());
return tcb::span<R const>(reinterpret_cast<R*>(p), arr.size());
}

template <typename T, typename R>
std::span<R> make_mutable_casted_span_(py::array arr) {
tcb::span<R> make_mutable_casted_span_(py::array arr) {
static_assert(sizeof(T) == sizeof(R));
assert(py::isinstance<py::array_t<T>>(arr));
std::remove_cv_t<T>* p = (std::remove_cv_t<T>*)arr
.mutable_unchecked<std::remove_cv_t<T>, 1>()
.data(0);
return std::span<R>(reinterpret_cast<R*>(p), arr.size());
return tcb::span<R>(reinterpret_cast<R*>(p), arr.size());
}

/*
Expand Down Expand Up @@ -351,8 +350,8 @@ void compress_coo(
typename decltype(csx_minor_index_type)::type;
using VALUE = typename decltype(value_type)::type;

std::vector<std::span<COO_INDEX const>> Ai_views, Aj_views;
std::vector<std::span<remap_value_t<VALUE> const>> Ad_views;
std::vector<tcb::span<COO_INDEX const>> Ai_views, Aj_views;
std::vector<tcb::span<remap_value_t<VALUE> const>> Ad_views;
for (size_t i = 0; i < Ai.size(); ++i) {
Ai_views.push_back(make_span_<COO_INDEX>(Ai[i]));
Aj_views.push_back(make_span_<COO_INDEX>(Aj[i]));
Expand Down Expand Up @@ -552,7 +551,7 @@ void count_rows(
using CSX_MAJOR_INDEX =
typename decltype(csx_major_index_type)::type;

std::vector<std::span<COO_INDEX const>> Ai_views, Aj_views;
std::vector<tcb::span<COO_INDEX const>> Ai_views, Aj_views;
for (size_t i = 0; i < Ai.size(); ++i) {
Ai_views.push_back(make_span_<COO_INDEX>(Ai[i]));
}
Expand Down
8 changes: 4 additions & 4 deletions apis/r/configure
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ if [ $? -eq 0 ]; then
pkgcflags=`pkg-config --cflags tiledb tiledbsoma`
pkglibs=`pkg-config --libs tiledb tiledbsoma`

## substitute them in (leaving @tiledb_rpath@ and @cxx20_macos@ alone for now)
## substitute them in (leaving @tiledb_rpath@ and @cxx17_macos@ alone for now)
sed -e "s|@tiledb_include@|$pkgcflags |" \
-e "s|@tiledb_libs@|$pkglibs|" \
-e "s|@tiledb_rpath@||" \
-e "s|@cxx20_macos@||" \
-e "s|@cxx17_macos@||" \
src/Makevars.in > src/Makevars

echo "** updated src/Makevars for system library via pkg-config"
Expand Down Expand Up @@ -54,10 +54,10 @@ tools/build_libtiledbsoma.sh
pkgincl="-I../inst/tiledb/include -I../inst/tiledbsoma/include -I../inst/tiledbsoma/include/tiledbsoma"
pkglibs="-ltiledb -L../inst/tiledb/lib -ltiledbsoma -L../inst/tiledbsoma/lib"
rpath="-Wl,-rpath,'\$\$ORIGIN/../tiledb/lib' -Wl,-rpath,'\$\$ORIGIN/../tiledbsoma/lib'"
macosver=`${R_HOME}/bin/Rscript -e 'if (Sys.info()["sysname"] == "Darwin") cat("-mmacosx-version-min=13.3") else cat("")'`
macosver=`${R_HOME}/bin/Rscript -e 'if (Sys.info()["sysname"] == "Darwin") cat("-mmacosx-version-min=11.0") else cat("")'`

sed -e "s|@tiledb_include@|$pkgincl |" \
-e "s|@tiledb_libs@|$pkglibs|" \
-e "s|@tiledb_rpath@|$rpath|" \
-e "s|@cxx20_macos@|$macosver|" \
-e "s|@cxx17_macos@|$macosver|" \
src/Makevars.in > src/Makevars
10 changes: 10 additions & 0 deletions apis/r/inst/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ The package also includes code written by other contributors as
detailed below:


-- libtiledbsoma/src/external/include/span/span.hpp ---------------------------------------------
The span.hpp implements std::span, part of C++20, for use by C++11 or later. It
was written by Tristan Brindle and is released at https://github.com/tcbrindle/span

// Copyright Tristan Brindle 2018.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file ../../LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)


-- libtiledbsoma/src/external/{src,include}/thread_pool/ ----------------------------------------
The thread_pool implementation is from TileDB, Inc., and part of TileDB Embedded released at
https://github.com/tiledb-inc/tiledb
Expand Down
6 changes: 3 additions & 3 deletions apis/r/src/Makevars.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CXX_STD = CXX20
CXX_STD = CXX17

## We need the TileDB Headers, and for macOS aka Darwin need to set minimum version 10.14 for macOS
PKG_CPPFLAGS = -I. -I../inst/include/ @tiledb_include@ @cxx20_macos@ -D SPDLOG_USE_STD_FORMAT
PKG_CPPFLAGS = -I. -I../inst/include/ @tiledb_include@ @cxx17_macos@

## We also need the TileDB library
PKG_LIBS = @cxx20_macos@ @tiledb_libs@ @tiledb_rpath@
PKG_LIBS = @cxx17_macos@ @tiledb_libs@ @tiledb_rpath@

all: $(SHLIB)
# On macOS aka Darwin we call install_name_tool
Expand Down
4 changes: 2 additions & 2 deletions libtiledbsoma/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ if(CCACHE_FOUND)
endif()

# Set C++20 as required standard for all C++ targets (C++17 minimum is required to use the TileDB C++ API).
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) # Don't use GNU extensions

Expand Down Expand Up @@ -218,7 +218,7 @@ if(MSVC)
)
else()

set(TILEDBSOMA_COMPILE_OPTIONS -Wall -Wextra -DSPDLOG_USE_STD_FORMAT)
set(TILEDBSOMA_COMPILE_OPTIONS -Wall -Wextra)

if(${TILEDBSOMA_ENABLE_WERROR})
set(TILEDBSOMA_WERROR_OPTION -Werror)
Expand Down
2 changes: 1 addition & 1 deletion libtiledbsoma/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## System Dependencies

* C++20 compiler
* C++17 compiler
* Python 3.9+

Run these commands to setup a fresh Ubuntu 22.04 instance (tested on x86 and Arm):
Expand Down
5 changes: 5 additions & 0 deletions libtiledbsoma/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ install(FILES
DESTINATION "include/tiledbsoma/utils"
)

install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/external/include/span/span.hpp
DESTINATION "include/tiledbsoma/soma/span"
)

install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/external/include/nanoarrow/nanoarrow.h
${CMAKE_CURRENT_SOURCE_DIR}/external/include/nanoarrow/nanoarrow.hpp
Expand Down
11 changes: 5 additions & 6 deletions libtiledbsoma/src/cli/cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
* This file is currently a sandbox for C++ API experiments
*/

#include <format>
#include "soma/enums.h"
#include "soma/soma_array.h"
#include "utils/arrow_adapter.h"
Expand Down Expand Up @@ -78,8 +77,8 @@ void test_sdf(const std::string& uri) {
total_num_rows += (*batch)->num_rows();
}

LOG_INFO(std::format("X/data rows = {}", total_num_rows));
LOG_INFO(std::format(" batches = {}", batches));
LOG_INFO(fmt::format("X/data rows = {}", total_num_rows));
LOG_INFO(fmt::format(" batches = {}", batches));
}

namespace tdbs = tiledbsoma;
Expand All @@ -90,10 +89,10 @@ void test_arrow(const std::string& uri) {
// Getting next batch: std::optional<std::shared_ptr<ArrayBuffers>>
auto obs_data = obs->read_next();
if (!obs->results_complete()) {
tdbs::LOG_WARN(std::format("Read of '{}' incomplete", uri));
tdbs::LOG_WARN(fmt::format("Read of '{}' incomplete", uri));
exit(-1);
}
tdbs::LOG_INFO(std::format(
tdbs::LOG_INFO(fmt::format(
"Read complete with {} obs and {} cols",
obs_data->get()->num_rows(),
obs_data->get()->names().size()));
Expand All @@ -102,7 +101,7 @@ void test_arrow(const std::string& uri) {
auto buf = obs_data->get()->at(nm);
auto pp = tdbs::ArrowAdapter::to_arrow(buf);
ArrowSchema* schema = pp.second.get();
tdbs::LOG_INFO(std::format(
tdbs::LOG_INFO(fmt::format(
"Accessing '{}', retrieved '{}', n_children {}",
nm,
schema->name,
Expand Down
Loading

0 comments on commit 7181f50

Please sign in to comment.