← Back to Pull requests

GH-51267: [C++] Add std::chrono opt-in with toolchain feature detection #51315

Open
Adarsh-Me opened this pull request with 434 lines diff across 15 files
View on GitHub
Adarsh-Me Adarsh-Me commented on Sep 12, 2026 15:53 UTC
Author

Rationale for this change

GH-51267 tracks removing the vendored datetime fallback once all supported toolchains provide working C++20 chrono timezone support. The backend selection is currently hardcoded in chrono_internal.h (Windows-only) with no build-level switch, and the vendored tz implementation is compiled into every binary — including standard-backend ones.

What changes are included in this PR?

  • New ARROW_USE_STD_CHRONO CMake option (AUTO/ON/OFF, default AUTO) resolved by a toolchain feature probe (__cpp_lib_chrono >= 201907L) in cpp/cmake_modules/CheckStdChrono.cmake; new matching use_std_chrono Meson feature option with the same semantics.

  • AUTO preserves the current platform default (std::chrono on Windows toolchains with timezone support, vendored fallback elsewhere) until the minimum-toolchain prerequisites in GH-51267 are met. Explicit opt-in fails loudly at configure time on unsupported toolchains.

  • The resolved backend is recorded in arrow/util/config.h and honored by chrono_internal.h; standard-backend binaries no longer build vendored/datetime.cpp, and config.cc / the SetTimezoneConfig test honor the selected backend (OS tzdb, no vendored set_install/reload_tzdb).
  • Are these changes tested?

  • CMake 3.31.6: verified the new module resolves AUTO→OFF on Linux/GCC 11, passes OFF through, fails configure on ON without toolchain support and on invalid values; verified config.h.cmake renders ARROW_USE_STD_CHRONO 0/1 via real configure_file.

  • Meson 1.7.2: verified auto/disabled keep the fallback and render 0, and enabled errors out on an unsupported toolchain.

  • g++ 11 (C++20): compiled the real vendored/datetime.cpp plus a functional test against the modified chrono_internal.h fallback path — calendar round-trip, floor/ceil/trunc, format, make_time, OffsetZone, and a live locate_zone("America/New_York") lookup against system zoneinfo all pass; also confirmed the header selects the std branch when ARROW_USE_STD_CHRONO=1.

  • Full ctest matrix (notably Windows/MSVC and opt-in toolchains) left to CI: this environment has no CMake project build deps and GCC 11 lacks <format>/chrono-tz.
  • Are there any user-facing changes?

    New opt-in build options only; default builds behave exactly as before.

  • GitHub Issue: #51267
  • Closes #51267

    Was AI used for this PR?

    In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.

    PR code and description written by:

  • Human

  • AI
  • Reviewed before submission by:

  • Human

  • AI

  • Not reviewed
  • Summary of AI usage: both the diff and this description were produced by an AI
    coding agent working on a human contributor's machine under that contributor's
    direction. The agent wrote the CMake option plumbing, the Meson equivalent, the
    config.h/chrono_internal.h wiring and the description above, and it also
    executed every verification reported under "Are these changes tested?" (CMake
    3.31.6 configure_file renders, Meson 1.7.2 resolution, g++ 11 compile and run
    of vendored/datetime.cpp against the modified header). No human re-ran those
    commands before submission, and no copyrighted material was copied into the
    diff. Full toolchain inventory of that host is in the "Are these changes
    tested?" section, which is why the ctest matrix is delegated to CI.

    Diff: 434 lines (+377 / -57) across 15 files Reviewer: Adarsh-Me Review duration: 47441m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.81) × (1 − Review Confidence (0.83)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.81 · 434 lines diff across 15 files
    0.81
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.93 · 5 substantive comment(s)
    0.93
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    82%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.363
    Self Review self_review
    0.140
    Real PR Conversation Timeline
    32 items
    Copilot Copilot commented on code on Sep 12, 2026 15:59 UTC
    Code Review
    cpp/src/arrow/CMakeLists.txt:1
    @@ -549,9 +549,16 @@ set(ARROW_VENDORED_SRCS
         vendored/uriparser/UriRecompose.c
         vendored/uriparser/UriResolve.c
         vendored/uriparser/UriShorten.c)
    -if(APPLE)
    +if(APPLE AND NOT ARROW_USE_STD_CHRONO)
       list(APPEND ARROW_VENDORED_SRCS vendored/datetime/ios.mm)
     endif()
    +if(ARROW_USE_STD_CHRONO)

    When ARROW_GANDIVA is enabled, gandiva/cast_time.cc and gdv_function_stubs.cc still call arrow_vendored::date::locate_zone/zoned_time. Those definitions come from vendored/datetime.cpp, and Gandiva links arrow_shared/arrow_static; removing this translation unit here leaves undefined symbols (or a runtime load failure). Keep the TU for Gandiva or migrate those call sites to the standard backend.

    Copilot Copilot commented on code on Sep 12, 2026 15:59 UTC
    Code Review
    cpp/src/arrow/config.cc:1
    @@ -91,7 +103,11 @@ RuntimeInfo GetRuntimeInfo() {
     Status Initialize(const GlobalOptions& options) noexcept {
       ARROW_SUPPRESS_DEPRECATION_WARNING
       if (options.timezone_db_path.has_value()) {
    -#if !USE_OS_TZDB
    +#if defined(ARROW_USE_STD_CHRONO) && ARROW_USE_STD_CHRONO
    +    return Status::Invalid(
    +        "Arrow was built with C++20 std::chrono and uses the OS timezone database, "
    +        "so a downloaded database cannot be provided at runtime.");

    This new error path is also reached by the R package's startup configure_tzdb(), which unconditionally calls set_timezone_database(tzdb::tzdb_path("text")) when the tzdb package is installed. In a std::chrono build the OS tzdb is the intended backend, so R will report a false startup failure that timezones are unavailable; make the R initialization backend-aware or otherwise avoid passing a vendored database path for this backend.

    Copilot Copilot commented on code on Sep 12, 2026 15:59 UTC
    Code Review
    cpp/src/arrow/util/config.h.cmake:1
    @@ -54,6 +54,7 @@
     #cmakedefine ARROW_HDFS
     #cmakedefine ARROW_S3
     #cmakedefine ARROW_USE_GLOG
    +#cmakedefine01 ARROW_USE_STD_CHRONO

    When Arrow is added as a CMake subproject, ARROW_DEFINE_OPTIONS defaults to OFF, so ARROW_USE_STD_CHRONO is undefined and CheckStdChrono.cmake intentionally skips resolution. However, #cmakedefine01 still generates #define ARROW_USE_STD_CHRONO 0, preventing chrono_internal.h from using its existing Windows feature-detection fallback and changing those builds from the previous std::chrono backend to vendored datetime. Preserve the undefined state for an unset option (while retaining 0 for an explicit OFF) or resolve the subproject default explicitly.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 12, 2026 15:59 UTC
    Reviewer

    🟡 Changes recommended

    Unresolved Gandiva linkage, R initialization, and CMake subproject configuration issues block approval.

    Get a fresh assessment by requesting another Copilot review.

    <details>
    <summary>Pull request overview</summary>

    Adds opt-in std::chrono backend selection with CMake/Meson toolchain detection while retaining the vendored fallback.

    Changes:

  • Adds AUTO/enabled/disabled build options and feature probes.

  • Records backend selection in generated configuration.

  • Conditionally builds vendored datetime and updates timezone handling/tests.

  • </details>

    <details>
    <summary>File summaries</summary>

    | File | Summary |
    |---|---|
    | cpp/src/arrow/util/meson.build | Configures the selected chrono backend for Meson. |
    | cpp/src/arrow/util/config.h.cmake | Generates the backend macro. Moderate (3 votes): unset CMake subproject options may change the previous Windows fallback behavior. |
    | cpp/src/arrow/util/chrono_internal.h | Selects the configured chrono implementation. |
    | cpp/src/arrow/public_api_test.cc | Adjusts timezone configuration coverage. |
    | cpp/src/arrow/meson.build | Conditionally includes vendored datetime sources. |
    | cpp/src/arrow/config.cc | Updates timezone initialization. Moderate (2 votes): R startup may falsely fail when passing a vendored database path to the standard backend. |
    | cpp/src/arrow/CMakeLists.txt | Conditionally excludes vendored datetime sources. Critical (3 votes): Gandiva still references vendored symbols, risking link or runtime failures. |
    | cpp/meson.options | Adds the Meson chrono feature option. |
    | cpp/meson.build | Detects and resolves Meson chrono support. |
    | cpp/CMakeLists.txt | Loads chrono feature detection. |
    | cpp/cmake_modules/DefineOptions.cmake | Defines the CMake chrono option. |
    | cpp/cmake_modules/CheckStdChrono.cmake | Resolves and validates the CMake backend selection. |
    </details>

    <details>
    <summary>Review details</summary>

  • Files reviewed: 12/12 changed files

  • Comments generated: 3

  • Review effort level: Lite

  • </details>

    ---

    💡 <a href="/apache/arrow/new/main?filename=.github/skills/code-review/SKILL.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add a code-review agent skill</a> or configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review?tool=webui#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>

    Adarsh-Me Adarsh-Me commented on code on Sep 12, 2026 18:19 UTC
    Code Review
    cpp/src/arrow/CMakeLists.txt:1
    @@ -549,9 +549,16 @@ set(ARROW_VENDORED_SRCS
         vendored/uriparser/UriRecompose.c
         vendored/uriparser/UriResolve.c
         vendored/uriparser/UriShorten.c)
    -if(APPLE)
    +if(APPLE AND NOT ARROW_USE_STD_CHRONO)
       list(APPEND ARROW_VENDORED_SRCS vendored/datetime/ios.mm)
     endif()
    +if(ARROW_USE_STD_CHRONO)

    Fixed at 7b99c74fe: the TU is now only removed when Gandiva is not built (if(ARROW_USE_STD_CHRONO AND NOT ARROW_GANDIVA)). Gandiva's cast_time.cc / gdv_function_stubs.cc keep their locate_zone/zoned_time definitions, so ARROW_USE_STD_CHRONO=ON + ARROW_GANDIVA=ON links; migrating those call sites to the standard backend can come later under GH-51267.

    Adarsh-Me Adarsh-Me commented on code on Sep 12, 2026 18:19 UTC
    Code Review
    cpp/src/arrow/config.cc:1
    @@ -91,7 +103,11 @@ RuntimeInfo GetRuntimeInfo() {
     Status Initialize(const GlobalOptions& options) noexcept {
       ARROW_SUPPRESS_DEPRECATION_WARNING
       if (options.timezone_db_path.has_value()) {
    -#if !USE_OS_TZDB
    +#if defined(ARROW_USE_STD_CHRONO) && ARROW_USE_STD_CHRONO
    +    return Status::Invalid(
    +        "Arrow was built with C++20 std::chrono and uses the OS timezone database, "
    +        "so a downloaded database cannot be provided at runtime.");

    Fixed at 7b99c74fe on the R side: runtime_info() now reports using_os_timezone_db (third element, "true"/"false"), and configure_tzdb() skips set_timezone_database(tzdb::tzdb_path("text")) entirely when the runtime reads the OS timezone database — exactly the std::chrono case here. So R no longer surfaces the false "timezones will not be available" startup warning on this backend; the tzdb package path is only used when Arrow actually consumes a vendored, non-OS database (preserving the GH-49866 MinGW behavior). arrow_info() exposes the flag as runtime_info$using_os_timezone_db too.

    Adarsh-Me Adarsh-Me commented on code on Sep 12, 2026 18:19 UTC
    Code Review
    cpp/src/arrow/util/config.h.cmake:1
    @@ -54,6 +54,7 @@
     #cmakedefine ARROW_HDFS
     #cmakedefine ARROW_S3
     #cmakedefine ARROW_USE_GLOG
    +#cmakedefine01 ARROW_USE_STD_CHRONO

    Fixed at 7b99c74fe: config.h.cmake now emits @ARROW_USE_STD_CHRONO_DEFINITION@, which the build system resolves as — #define ARROW_USE_STD_CHRONO 1 / 0 when the option is defined (explicit ON/OFF, AUTO-resolved), and / #undef ARROW_USE_STD_CHRONO / when it is unset (subproject with ARROW_DEFINE_OPTIONS=OFF). The undefined state restores chrono_internal.h's platform fallback for those builds, while an explicit OFF keeps 0 so the fallback cannot re-enable std::chrono against the user's choice. The Meson side sets the same definition key from its resolved option (Meson options always resolve, so there is no unset case there).

    Copilot Copilot commented on code on Sep 12, 2026 18:26 UTC
    Code Review
    cpp/cmake_modules/CheckStdChrono.cmake:1
    @@ -0,0 +1,93 @@
    +# 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.
    +
    +include(CheckCXXSourceCompiles)
    +
    +# 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>
    +#if !defined(__cpp_lib_chrono) || __cpp_lib_chrono < 201907L
    +#  error \"C++20 chrono timezone support (__cpp_lib_chrono >= 201907L) is unavailable\"
    +#endif
    +int main() { return 0; }

    This probe only checks the feature-test macro and links an empty main, but the selected branch unconditionally includes <format>, calls std::chrono::locate_zone, and uses std::vformat. A standard library can advertise __cpp_lib_chrono >= 201907L while one of those headers/APIs is unavailable, so ARROW_USE_STD_CHRONO=ON can pass configure and then fail to build. Make the CMake and Meson probes compile/link the APIs actually used by chrono_internal.h.

    Copilot Copilot commented on code on Sep 12, 2026 18:26 UTC
    Code Review
    cpp/src/arrow/config.cc:1
    @@ -91,7 +103,11 @@ RuntimeInfo GetRuntimeInfo() {
     Status Initialize(const GlobalOptions& options) noexcept {
       ARROW_SUPPRESS_DEPRECATION_WARNING
       if (options.timezone_db_path.has_value()) {
    -#if !USE_OS_TZDB
    +#if defined(ARROW_USE_STD_CHRONO) && ARROW_USE_STD_CHRONO
    +    return Status::Invalid(
    +        "Arrow was built with C++20 std::chrono and uses the OS timezone database, "
    +        "so a downloaded database cannot be provided at runtime.");

    ARROW_USE_STD_CHRONO does not mean every datetime consumer uses the standard backend: the build deliberately keeps vendored/datetime.cpp when Gandiva is enabled, and Gandiva still calls arrow_vendored::date::locate_zone/zoned_time. Rejecting timezone_db_path here prevents configuring the vendored database that Gandiva needs, so std-chrono + Gandiva can fail at runtime. Keep the vendored configuration path for that combination (using a generated Gandiva/backend flag) instead of treating the whole library as OS-tzdb-only.

    Copilot Copilot commented on code on Sep 12, 2026 18:26 UTC
    Code Review
    cpp/src/arrow/config.cc:1
    @@ -77,11 +83,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 defined(ARROW_USE_STD_CHRONO) && 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>();
    +#else

    In a CMake subproject with ARROW_DEFINE_OPTIONS=OFF, the generated config intentionally leaves ARROW_USE_STD_CHRONO undefined, so chrono_internal.h still selects std::chrono on Windows via its platform fallback. config.cc does not include that header, so this preprocessor branch is skipped and such a binary reports using_os_timezone_db=false (and continues exposing the vendored timezone configuration) even though its chrono backend uses the OS database. Please use a shared/resolved backend predicate here so RuntimeInfo and Initialize match the header-level fallback as well.

    Copilot Copilot commented on code on Sep 12, 2026 18:26 UTC
    Code Review
    r/R/arrow-package.R:1
    @@ -180,6 +180,13 @@ s3_finalizer <- new.env(parent = emptyenv())
     
     configure_tzdb <- function() {
       if (requireNamespace("tzdb", quietly = TRUE)) {
    +    if (runtime_info()[[3]] == "true") {
    +      # GH-51267: builds reading the OS timezone database (C++20 std::chrono,
    +      # or the vendored library built against the OS tzdata) cannot use a
    +      # downloaded database, and their timezones already work — skip the
    +      # vendored path instead of surfacing a false startup failure.
    +      return(invisible())
    +    }

    Because this check is nested under requireNamespace(), a std::chrono build with no tzdb package still falls into the existing else and emits “Timezones will not be available”, even though using_os_timezone_db is true. Move the backend check before package detection (or guard the else) so the OS-backend path is silent regardless of whether tzdb is installed.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 12, 2026 18:26 UTC
    Reviewer

    🟡 Changes recommended

    Unresolved probe, backend-consistency, Gandiva timezone, and R initialization findings remain.

    Get a fresh assessment by requesting another Copilot review.

    <details>
    <summary>Review details</summary>

  • Files reviewed: 15/15 changed files

  • Comments generated: 4

  • Review effort level: Lite

  • </details>

    Adarsh-Me Adarsh-Me commented on Sep 12, 2026 19:29 UTC
    Author

    CI triage on the failing runs — one real bug (fixed), the rest infrastructure:

    Fixed at f96c81bcf — the AMD64 Ubuntu 24.04 R 4.6 / Windows 2022 Python 3.13 / other from-source pyarrow failures. Root cause: the ARROW_USE_STD_CHRONO description in DefineOptions.cmake used an escaped backslash (\\) before the newline instead of a line-continuation backslash, so the newline stayed inside the quoted description and leaked into the generated ArrowOptions.cmake as a bare statement line (AUTO keeps the current platform default (GH-51267)). Every consumer that includes the installed file via find_package(Arrow) then failed with Parse error. Expected "(", got identifier with text "keeps" — that's the ERROR: Failed building wheel for pyarrow inside the R docker build and the Windows Python build. Reproduced locally with the exact generated file, fixed, and verified: the regenerated ArrowOptions.cmake parses clean via find_package (parsed OK).

    Not from this PR:

  • macOS 15-intel C++, Windows MinGW CLANG64/MINGW64 C++ (and likely the remaining MinIO-dependent jobs): dl.min.io returns 410: Gone while downloading the MinIO release archive — upstream infrastructure.

  • Windows 2022 MATLAB: workflow template error — hashFiles('cpp/, matlab/') failed to hash files on the runner; workflow-side.

  • AMD64 Conda C++ AVX2: arrow-filesystem-test fails with "Attempt to initialize S3 after it has been finalized" — pre-existing flake, this same job was the only failure on my merged #51203 as well.
  • Copilot Copilot commented on code on Sep 12, 2026 19:36 UTC
    Code Review
    r/R/arrow-package.R:1
    @@ -180,6 +180,13 @@ s3_finalizer <- new.env(parent = emptyenv())
     
     configure_tzdb <- function() {
       if (requireNamespace("tzdb", quietly = TRUE)) {
    +    if (runtime_info()[[3]] == "true") {
    +      # GH-51267: builds reading the OS timezone database (C++20 std::chrono,
    +      # or the vendored library built against the OS tzdata) cannot use a
    +      # downloaded database, and their timezones already work — skip the
    +      # vendored path instead of surfacing a false startup failure.
    +      return(invisible())
    +    }

    Because this check is nested under requireNamespace("tzdb"), a std::chrono build with no R tzdb package still reaches the else branch below and emits the false “Timezones will not be available” startup message. Check using_os_timezone_db before testing for the optional package so OS-backed builds return without requiring or warning about tzdb.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 12, 2026 19:36 UTC
    Reviewer

    🟡 Changes recommended

    Unresolved backend detection, Gandiva configuration, runtime selection, and R/Python compatibility issues remain.

    Get a fresh assessment by requesting another Copilot review.

    <details>
    <summary>Review details</summary>

    Suppressed comments (6)

    cpp/cmake_modules/CheckStdChrono.cmake:49
    This probe only includes <chrono> and checks __cpp_lib_chrono, but selecting this backend makes chrono_internal.h unconditionally include <format> and use std::vformat. A standard library can advertise chrono timezone support without implementing the separate format facility, so ARROW_USE_STD_CHRONO=ON can pass configure and then fail compiling Arrow. Probe <format>/__cpp_lib_format and the required formatting expression here as part of the opt-in check.

    #include <chrono>
    #if !defined(__cpp_lib_chrono) || __cpp_lib_chrono < 201907L
    #  error \"C++20 chrono timezone support (__cpp_lib_chrono >= 201907L) is unavailable\"
    #endif
    

    cpp/meson.build:125
    The Meson probe has the same gap as the CMake probe: it accepts a toolchain based only on __cpp_lib_chrono, while the selected backend includes <format> and calls std::vformat. This can make use_std_chrono=enabled configure successfully and then fail during the Arrow build when the separate C++20 format facility is unavailable. Check <format>/__cpp_lib_format and exercise the formatting expression here too.
    #include <chrono>
    #if !defined(__cpp_lib_chrono) || __cpp_lib_chrono < 201907L
    #error "C++20 chrono timezone support (__cpp_lib_chrono >= 201907L) is unavailable"
    #endif
    int main() { return 0; }
    

    cpp/src/arrow/CMakeLists.txt:574
    This intentionally retains vendored/datetime.cpp for Gandiva, creating a mixed-backend build. On Windows that TU uses USE_OS_TZDB=0, but config.cc now treats every ARROW_USE_STD_CHRONO=1 build as OS-backed and rejects timezone_db_path, leaving Gandiva without a way to load its required timezone database. Either reject this combination at configure time or preserve the vendored database configuration for Gandiva.
    if(ARROW_USE_STD_CHRONO AND NOT ARROW_GANDIVA)
      # GH-51267: standard-backend binaries use C++20 std::chrono and do not bundle
      # the vendored datetime implementation. The remaining direct users of
      # arrow/vendored/datetime.h (formatting, parsing, pretty printing) only rely
      # on its header-only calendar types — except Gandiva, whose cast_time.cc and
    

    cpp/src/arrow/config.cc:109
    When ARROW_GANDIVA=ON, the source-list change intentionally retains vendored/datetime.cpp because Gandiva still calls arrow_vendored::date::locate_zone directly. On Windows that vendored implementation is not OS-backed and needs set_install/reload_tzdb to point at its database; this unconditional std::chrono rejection prevents Initialize() from configuring it, so std+Gandiva timezone calls fail unless the default download location is already populated. Keep a separate vendored-database configuration path for Gandiva or migrate those callers before rejecting the path.
    #if defined(ARROW_USE_STD_CHRONO) && ARROW_USE_STD_CHRONO
        return Status::Invalid(
            "Arrow was built with C++20 std::chrono and uses the OS timezone database, "
            "so a downloaded database cannot be provided at runtime.");
    

    cpp/src/arrow/config.cc:90
    When ARROW_DEFINE_OPTIONS=OFF, the generated header intentionally leaves ARROW_USE_STD_CHRONO undefined, but chrono_internal.h still derives it as 1 on a supported Windows toolchain. config.cc does not use that same fallback selector, so this branch reports the build as vendored and the following initialization logic can configure an unused vendored database while compute uses std::chrono. Please centralize or reuse the backend selection so runtime info and timezone configuration match in CMake subprojects.
    #if defined(ARROW_USE_STD_CHRONO) && 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>();
    #else
    

    cpp/src/arrow/config.cc:109
    On non-Windows std::chrono opt-in builds, pa.set_timezone_db_path() now raises the new C++20-specific message, while python/pyarrow/tests/test_misc.py:140-149 still matches only Arrow was set to use OS timezone database at compile time. The existing Python test will fail for this supported configuration; update it to accept the new message (or preserve the previous wording).
    #if defined(ARROW_USE_STD_CHRONO) && ARROW_USE_STD_CHRONO
        return Status::Invalid(
            "Arrow was built with C++20 std::chrono and uses the OS timezone database, "
            "so a downloaded database cannot be provided at runtime.");
    

  • Files reviewed: 15/15 changed files

  • Comments generated: 1

  • Review effort level: Lite

  • </details>

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 12, 2026 19:41 UTC
    Reviewer

    Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 13, 2026 06:45 UTC
    Reviewer

    Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

    Adarsh-Me Adarsh-Me commented on Sep 13, 2026 06:46 UTC
    Author

    Found and fixed a real one from the latest run's CI triage: the Windows 2022 AVX2 C++ failure (arrow-substrait-substrait-test with Cannot locate or parse timezone 'UTC': Timezone database not found at "C:\Users\runneradmin\Downloads\tzdata") was caused by this PR's configure probe. It passed /std:c++20 through CMAKE_REQUIRED_FLAGS on top of the project-wide CMAKE_CXX_STANDARD=20 that try_compile already applies, and under CMake 4.1 + MSVC 19.44 the probe failed spuriously — so AUTO silently downgraded the build to the vendored backend, whose tzdb lookups then fail at runtime on Windows (no downloaded database). Fixed at c1c045ad5: the probe now compiles with the project standard alone and prints its compiler output on failure, so any future probe regression is diagnosable from CI directly. Verified the new mechanics locally (probe compiles with a single -std=c++20, failure output surfaced, explicit ON on an unsupported toolchain still fails the configure with the intended message).

    The remaining failures in that run are all the MinIO 410: Gone outage (Install MinIO step — macOS/ARM64/MinGW/R jobs) and the pre-existing Conda S3 after finalized flake; Windows R release is MinIO too, and Windows 2022 MATLAB is the workflow-template hashFiles error.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 16, 2026 12:41 UTC
    Reviewer

    Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 16, 2026 12:44 UTC
    Reviewer

    Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

    Adarsh-Me Adarsh-Me commented on Sep 16, 2026 12:44 UTC
    Author

    Ready for another look — pushed fixes for the 4 open review findings and rebased onto latest main (b274238).

    Fixes (commit 3f41597):
    1. Probe gap: CMake + Meson probes now compile <format> (vformat_to/make_format_args) and std::chrono::locate_zone, not just __cpp_lib_chrono (catches e.g. GCC 12, which advertises the macro but has no <format>).
    2. R startup: configure_tzdb() checks using_os_timezone_db first and skips entirely — no more false "Timezones will not be available" when the tzdb package is missing on OS-db builds.
    3. Gandiva mix: new ARROW_HAVE_VENDORED_DATETIME (CMake + Meson) records whether datetime.cpp is linked; Initialize() honors timezone_db_path for std+Gandiva builds (which still carry the vendored copy) and keeps rejecting it for pure-std builds.
    4. Subproject: config.cc now includes chrono_internal.h, so ARROW_DEFINE_OPTIONS=OFF builds use the same backend predicate as the header (no more using_os_timezone_db=false on Windows-std); the SetTimezoneConfig skip follows it too.

    Also fixed the cmake-format lint failure on CheckStdChrono.cmake (try_compile layout).

    Reds triage on the previous head (c1c045a) — all CI-side except one to watch:

  • Install/Download MinIO failures: macOS 15-intel C++, ARM64 macOS 14 C++, MinGW MINGW64 + CLANG64 C++, macOS Python, Windows R release — MinIO infra, unrelated to this PR.

  • Windows 2022 MATLAB: failed at Post Cache ccache — infra flake.

  • Conda C++ AVX2: Execute Docker Build — looks infra-related; will confirm on the new head.

  • Windows 2022 AVX2 C++: failed at the Test step — please flag if still red on the new head and I'll dig into the log.

  • Lint pre-commit: only cmake-format on this PR's own file, fixed in this push.
  • New CI is running on this head; will re-triage anything still red.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 16, 2026 14:34 UTC
    Reviewer

    Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 16, 2026 14:37 UTC
    Reviewer

    Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 17, 2026 20:28 UTC
    Reviewer

    Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

    Adarsh-Me Adarsh-Me commented on code on Oct 02, 2026 09:47 UTC
    Code Review
    cpp/cmake_modules/CheckStdChrono.cmake:1
    @@ -0,0 +1,93 @@
    +# 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.
    +
    +include(CheckCXXSourceCompiles)
    +
    +# 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>
    +#if !defined(__cpp_lib_chrono) || __cpp_lib_chrono < 201907L
    +#  error \"C++20 chrono timezone support (__cpp_lib_chrono >= 201907L) is unavailable\"
    +#endif
    +int main() { return 0; }

    Fixed and verified against this head: the probe now compiles and links the APIs actually used — <format>, std::chrono::locate_zone, std::vformat_to with make_format_args — and additionally requires __cpp_lib_format (cpp/cmake_modules/CheckStdChrono.cmake:42-71). The same source is mirrored in cpp/meson.build:120-153, so Meson no longer trusts the feature-test macro alone either.

    Adarsh-Me Adarsh-Me commented on code on Oct 02, 2026 09:47 UTC
    Code Review
    cpp/src/arrow/config.cc:1
    @@ -91,7 +103,11 @@ RuntimeInfo GetRuntimeInfo() {
     Status Initialize(const GlobalOptions& options) noexcept {
       ARROW_SUPPRESS_DEPRECATION_WARNING
       if (options.timezone_db_path.has_value()) {
    -#if !USE_OS_TZDB
    +#if defined(ARROW_USE_STD_CHRONO) && ARROW_USE_STD_CHRONO
    +    return Status::Invalid(
    +        "Arrow was built with C++20 std::chrono and uses the OS timezone database, "
    +        "so a downloaded database cannot be provided at runtime.");

    Addressed: Initialize() no longer keys on ARROW_USE_STD_CHRONO alone but on ARROW_HAVE_VENDORED_DATETIME (cpp/src/arrow/config.cc:112-133). std::chrono plus Gandiva still bundles the vendored timezone code and takes the set_install/reload_tzdb branch; only pure std::chrono builds, which carry no vendored code, reject timezone_db_path.

    Adarsh-Me Adarsh-Me commented on code on Oct 02, 2026 09:47 UTC
    Code Review
    cpp/src/arrow/config.cc:1
    @@ -77,11 +83,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 defined(ARROW_USE_STD_CHRONO) && 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>();
    +#else

    Addressed: cpp/src/arrow/config.cc now includes arrow/util/chrono_internal.h (lines 22-26), so the CMake-subproject case (ARROW_DEFINE_OPTIONS=OFF, macro undefined) resolves through the same header-level backend predicate that RuntimeInfo() and Initialize() use, instead of drifting to the vendored reading.

    Adarsh-Me Adarsh-Me commented on code on Oct 02, 2026 09:47 UTC
    Code Review
    r/R/arrow-package.R:1
    @@ -180,6 +180,13 @@ s3_finalizer <- new.env(parent = emptyenv())
     
     configure_tzdb <- function() {
       if (requireNamespace("tzdb", quietly = TRUE)) {
    +    if (runtime_info()[[3]] == "true") {
    +      # GH-51267: builds reading the OS timezone database (C++20 std::chrono,
    +      # or the vendored library built against the OS tzdata) cannot use a
    +      # downloaded database, and their timezones already work — skip the
    +      # vendored path instead of surfacing a false startup failure.
    +      return(invisible())
    +    }

    Addressed: configure_tzdb() returns before touching the optional package when runtime_info() reports the OS database (r/R/arrow-package.R:181-188), so an OS-backed build without tzdb installed no longer reaches the warning branch. The check now precedes requireNamespace as requested.

    Adarsh-Me Adarsh-Me commented on code on Oct 02, 2026 09:47 UTC
    Code Review
    r/R/arrow-package.R:1
    @@ -180,6 +180,13 @@ s3_finalizer <- new.env(parent = emptyenv())
     
     configure_tzdb <- function() {
       if (requireNamespace("tzdb", quietly = TRUE)) {
    +    if (runtime_info()[[3]] == "true") {
    +      # GH-51267: builds reading the OS timezone database (C++20 std::chrono,
    +      # or the vendored library built against the OS tzdata) cannot use a
    +      # downloaded database, and their timezones already work — skip the
    +      # vendored path instead of surfacing a false startup failure.
    +      return(invisible())
    +    }

    Same fix as the earlier thread on this file: the backend check at r/R/arrow-package.R:181-188 now precedes requireNamespace("tzdb"), so OS-backed builds return early and never emit that startup message. Resolving as a duplicate of that thread.

    Adarsh-Me Adarsh-Me commented on Oct 02, 2026 10:00 UTC
    Author

    CI triage for this head, so the two non-green checks aren't read as coming from this diff: AMD64 Windows 2022 MATLAB fails with .github/workflows/matlab.yml (Line: 168, Col: 16): hashFiles('cpp/, matlab/') failed. Fail to hash files under directory 'D:\a\arrow\arrow'. That line is unchanged on main, and this PR touches zero .github/ files. AMD64 macOS 15-intel C++ was cancelled after hitting the 1 h 15 m job cap. Everything else on the head is green (41 success, 16 skipped), and all 8 review threads are now answered and resolved.

    github-actions[bot] github-actions[bot] commented on Oct 14, 2026 06:50 UTC
    Bot

    :warning: GitHub issue #51267 has been automatically assigned in GitHub to PR creator.

    Reviewers
    Assignees
    Adarsh-Me Adarsh-Me
    Labels
    risk: low confidence: 82.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 80.9% (HIGH) · Higher = larger blast radius
    80.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 82.8% · Lower = rushed or shallow review
    82.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 13.9% · Safe to merge
    13.9%
    Repository