Copilot commented on code in PR #51315: URL: https://github.com/apache/arrow/pull/51315#discussion_r4578364457
########## cpp/cmake_modules/CheckStdChrono.cmake: ########## @@ -0,0 +1,126 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Resolve the ARROW_USE_STD_CHRONO option (AUTO, ON or OFF) into a boolean. +# +# GH-51267 tracks removing the vendored datetime fallback once all supported +# toolchains provide working C++20 chrono timezone support. Until then: +# - AUTO keeps the historical platform default: std::chrono is used on Windows +# toolchains whose standard library provides working C++20 chrono timezone +# support, and the vendored datetime fallback is used everywhere else. +# - ON opts into std::chrono unconditionally, failing the configure step when +# the toolchain does not provide working C++20 chrono timezone support. +# - OFF always uses the vendored datetime fallback. +# +# The resolved value is consumed via arrow/util/config.h (ARROW_USE_STD_CHRONO) +# by arrow/util/chrono_internal.h and to decide whether the vendored datetime +# implementation is built. + +# When Arrow is consumed as a CMake subproject, ARROW_USE_STD_CHRONO is not +# defined; skip detection and let arrow/util/chrono_internal.h fall back to its +# default backend selection (vendored datetime fallback). +if(DEFINED ARROW_USE_STD_CHRONO) + if(NOT "${ARROW_USE_STD_CHRONO}" MATCHES "^(AUTO|ON|OFF)$") + message(FATAL_ERROR "ARROW_USE_STD_CHRONO must be one of AUTO, ON or OFF " + "(got \"${ARROW_USE_STD_CHRONO}\")") + endif() + + set(_ARROW_STD_CHRONO_TEST_SOURCE + " +#include <chrono> +#include <format> +#include <iterator> +#include <ostream> +#include <sstream> +#include <string> +#if !defined(__cpp_lib_chrono) || __cpp_lib_chrono < 201907L +# error \"C++20 chrono timezone support (__cpp_lib_chrono >= 201907L) is unavailable\" +#endif +#if !defined(__cpp_lib_format) +# error \"C++20 formatting support (__cpp_lib_format) is unavailable\" +#endif +int main() { + // arrow/util/chrono_internal.h (GH-51267) needs working timezone lookup + // and <format>; the toolchain must provide both, not just the chrono + // feature-test macro (e.g. GCC 12 advertises __cpp_lib_chrono but has + // no <format>). The probe only compiles and links, it never runs, so + // referencing locate_zone here needs no timezone database on the host. + // NOTE: make_format_args takes its arguments by reference, so the + // time point must be bound to a local first, not passed as a temporary. + const std::chrono::time_zone* tz = std::chrono::locate_zone(\"UTC\"); + std::ostringstream os; + const auto now = std::chrono::system_clock::now(); + std::vformat_to(std::ostreambuf_iterator<char>(os), \"{:%Y}\", + std::make_format_args(now)); Review Comment: The probe formats only `system_clock::time_point`, while the std backend in `chrono_internal.h` also instantiates `std::vformat_to(..., std::make_format_args(zt))` for `std::chrono::zoned_time`. A library with partial chrono-format support can therefore pass this CMake/Meson probe and still fail when compiling `to_stream`; construct a `zoned_time` from `tz` and format that exact type in both probes. ########## cpp/src/arrow/config.cc: ########## @@ -77,11 +89,17 @@ RuntimeInfo GetRuntimeInfo() { MakeSimdLevelString([&](int64_t flags) { return cpu_info->IsSupported(flags); }); info.detected_simd_level = MakeSimdLevelString([&](int64_t flags) { return cpu_info->IsDetected(flags); }); +#if ARROW_USE_STD_CHRONO + // GH-51267: std::chrono builds always use the OS timezone database. + info.using_os_timezone_db = true; + info.timezone_db_path = std::optional<std::string>(); Review Comment: `ARROW_HAVE_VENDORED_DATETIME` is intentionally kept enabled for std::chrono + Gandiva, but this branch unconditionally reports the whole build as OS-tzdb-backed and clears `timezone_db_path`. On Windows, the retained vendored datetime library uses its configurable database (`USE_OS_TZDB` is false), so `Initialize()` can accept a tzdb path while `GetRuntimeInfo()` lies and R/other callers skip configuring it. Only take this shortcut for pure std::chrono builds; otherwise preserve the `USE_OS_TZDB`/path reporting below. ########## cpp/src/arrow/public_api_test.cc: ########## @@ -125,7 +137,9 @@ TEST(Misc, BuildInfo) { // TODO(GH-48593): Remove when libc++ supports std::chrono timezones. ARROW_SUPPRESS_DEPRECATION_WARNING TEST(Misc, SetTimezoneConfig) { -#ifndef _WIN32 +#if ARROW_USE_STD_CHRONO + GTEST_SKIP() << "std::chrono builds use the OS timezone database (GH-51267)"; Review Comment: This skips `SetTimezoneConfig` for every std::chrono build, including std::chrono + Gandiva. That combination intentionally keeps `vendored/datetime.cpp` and `config.cc` still accepts `timezone_db_path` through `ARROW_HAVE_VENDORED_DATETIME`, so the test no longer verifies a supported configuration. Restrict the skip to pure std::chrono builds (for example, also require `!ARROW_HAVE_VENDORED_DATETIME`). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
