Skip to content

Commit

Permalink
Add flag on date polyfill and <chrono> with mingw
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainCorlay committed Jun 4, 2024
1 parent 411eb4c commit 1d515c3
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 99 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ jobs:
fail-fast: false
matrix:
sys:
- {compiler: clang, version: '16', config-flags: '', stdlib: 'libstdc++-12' }
# - {compiler: clang, version: '16', config-flags: '-DCMAKE_CXX_FLAGS=-stdlib=libc++', stdlib: 'libc++-17' }
- {compiler: clang, version: '17', config-flags: '', stdlib: 'libstdc++-12' }
# - {compiler: clang, version: '17', config-flags: '-DCMAKE_CXX_FLAGS=-stdlib=libc++', stdlib: 'libc++-17' }
- {compiler: gcc, version: '12', config-flags: '' }
- {compiler: gcc, version: '13', config-flags: '' }
- {compiler: clang, version: '16', config-flags: '', stdlib: 'libstdc++-12', date-polyfill: 'ON' }
# - {compiler: clang, version: '16', config-flags: '-DCMAKE_CXX_FLAGS=-stdlib=libc++', stdlib: 'libc++-17', date-polyfill: 'ON' }
- {compiler: clang, version: '17', config-flags: '', stdlib: 'libstdc++-12', date-polyfill: 'ON' }
# - {compiler: clang, version: '17', config-flags: '-DCMAKE_CXX_FLAGS=-stdlib=libc++', stdlib: 'libc++-17', date-polyfill: 'ON' }

- {compiler: gcc, version: '12', config-flags: '', date-polyfill: 'ON' }
- {compiler: gcc, version: '13', config-flags: '', date-polyfill: 'ON' }
- {compiler: gcc, version: '13', config-flags: '', date-polyfill: 'OFF' }

config:
- { name: Debug }
Expand Down Expand Up @@ -61,7 +63,7 @@ jobs:
cache-downloads: true

- name: Configure using CMake
run: cmake -G Ninja -Bbuild ${{matrix.sys.config-flags}} -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DBUILD_TESTS=ON
run: cmake -G Ninja -Bbuild ${{matrix.sys.config-flags}} -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DUSE_DATE_POLYFILL=${{matrix.sys.date-polyfill}} -DBUILD_TESTS=ON

- name: Install
working-directory: build
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ defaults:
jobs:
build:
runs-on: ${{ matrix.runs-on }}
name: ${{ matrix.sys.compiler }}-${{ matrix.build-system }}-${{ matrix.config.name }}
name: ${{ matrix.sys.compiler }}-${{ matrix.build-system }}-${{ matrix.config.name }}-date-polyfill-${{ matrix.sys.date-polyfill}}
strategy:
fail-fast: false
matrix:
runs-on: [windows-latest]
sys:
- {compiler: default}
- {compiler: msvc}
- {compiler: clang}
- {compiler: msvc, date-polyfill: 'ON' }
- {compiler: msvc, date-polyfill: 'OFF' }
- {compiler: clang, date-polyfill: 'ON' }
- {compiler: clang, date-polyfill: 'OFF' }
config:
- { name: Debug }
- { name: Release }
Expand Down Expand Up @@ -55,7 +56,7 @@ jobs:
ninja
- name: Configure using CMake
run: cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DBUILD_TESTS=ON -G "${{matrix.build-system}}"
run: cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DBUILD_TESTS=ON -DUSE_DATE_POLYFILL=${{matrix.sys.date-polyfill}} -G "${{matrix.build-system}}"

- name: Install
working-directory: build
Expand Down
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ message(STATUS "Building sparrow v${${PROJECT_NAME}_VERSION}")
# Build options
# =============

OPTION(BUILD_TESTS "sparrow test suite" OFF)
OPTION(BUILD_TESTS "Build sparrow test suite" OFF)
OPTION(USE_DATE_POLYFILL "Use date polyfill implementation" ON)

include(CheckCXXSymbolExists)

Expand Down Expand Up @@ -73,8 +74,11 @@ endif()

set(SPARROW_INTERFACE_DEPENDENCIES "" CACHE STRING "List of dependencies to be linked to the sparrow target")

find_package(date CONFIG REQUIRED)
list(APPEND SPARROW_INTERFACE_DEPENDENCIES date::date date::date-tz)
if (USE_DATE_POLYFILL)
find_package(date CONFIG REQUIRED)
list(APPEND SPARROW_INTERFACE_DEPENDENCIES date::date date::date-tz)
add_compile_definitions(SPARROW_USE_DATE_POLYFILL)
endif()

# Build
# =====
Expand Down
2 changes: 1 addition & 1 deletion include/sparrow/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ namespace sparrow
{
if (new_size > size())
{
const size_t nb_init = new_size - size();
const std::size_t nb_init = new_size - size();
if (new_size <= capacity())
{
initializer(nb_init);
Expand Down
8 changes: 4 additions & 4 deletions include/sparrow/data_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
#include <version>
#include <chrono>

// P0355R7 (Extending chrono to Calendars and Time Zones) has not been entirely implemented in libc++ yet.
// See: https://libcxx.llvm.org/Status/Cxx20.html#note-p0355
// For now, we use HowardHinnant/date as a replacement if we are compiling with libc++.
// TODO: remove this once libc++ has full support for P0355R7.
#if defined(SPARROW_USE_DATE_POLYFILL)
#include <date/tz.h>
#else
namespace date = std::chrono;
#endif

#include <climits>
#include <cstdint>
Expand Down
26 changes: 17 additions & 9 deletions test/array_data_creation.cpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
#include "array_data_creation.hpp"

Check notice on line 1 in test/array_data_creation.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on test/array_data_creation.cpp

File test/array_data_creation.cpp does not conform to Custom style guidelines. (lines 8, 9, 19, 20, 38)

#include <chrono>
#include <stdexcept>
#include <vector>

#if defined(SPARROW_USE_DATE_POLYFILL)
#include <date/date.h>
#include <date/tz.h>
#else
namespace date = std::chrono;
#endif

namespace sparrow::test
{
using sys_time = std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>;

using namespace date::literals;

template <>
sparrow::array_data
make_test_array_data<sparrow::timestamp>(size_t n, size_t offset, const std::vector<size_t>& false_bitmap)
make_test_array_data<sparrow::timestamp>(std::size_t n, std::size_t offset, const std::vector<std::size_t>& false_bitmap)
{
sparrow::array_data ad;
ad.type = sparrow::data_descriptor(sparrow::arrow_traits<sparrow::timestamp>::type_id);
ad.bitmap = sparrow::dynamic_bitset<uint8_t>(n, true);
for (const auto i : false_bitmap) {
if (i >= n) {
for (const auto i : false_bitmap)
{
if (i >= n)
{
throw std::invalid_argument("Index out of range");
}
ad.bitmap.set(i, false);
}
const size_t buffer_size = (n * sizeof(sparrow::timestamp)) / sizeof(uint8_t);
const std::size_t buffer_size = (n * sizeof(sparrow::timestamp)) / sizeof(uint8_t);
sparrow::buffer<uint8_t> b(buffer_size);

for (uint8_t i = 0; i < n; ++i)
{
b.data<sparrow::timestamp>()[i] = sparrow::timestamp(date::sys_days(1970_y/date::January/1_d) + date::days(i));
b.data<sparrow::timestamp>()[i] = sparrow::timestamp(date::sys_days(date::year(1970)/date::January/date::day(1)) + date::days(i));
}

ad.buffers.push_back(b);
ad.length = n;
ad.offset = offset;
ad.length = static_cast<std::int64_t>(n);
ad.offset = static_cast<std::int64_t>(offset);
ad.child_data.emplace_back();
return ad;
}
Expand Down
Loading

0 comments on commit 1d515c3

Please sign in to comment.