Skip to content

Make fmt, std::format optional#263

Open
K20shores wants to merge 11 commits into
mainfrom
remove_format
Open

Make fmt, std::format optional#263
K20shores wants to merge 11 commits into
mainfrom
remove_format

Conversation

@K20shores
Copy link
Copy Markdown
Collaborator

@K20shores K20shores commented Apr 30, 2026

Introduces a CMake option (default OFF) to use the {fmt} library instead of std::format, A shim header (format_compat.hpp) aliases fmt or std into mc_fmt so call sites are unchanged. Packaging conditionally installs fmt when built from source and emits find_dependency(fmt) when found via the system.

This change is necessary because NOAA uses GCC11 which does not have full c++ 20 support and they can't use std::format. We will reject this PR if they can get their compiler stack updated to a supported version of GCC

Also removed some unused variables and some erronoues std::move

closes #262

Introduces a CMake option (default OFF) to use the {fmt} library instead
of std::format, dropping the C++ requirement from 20 to 17. A shim header
(format_compat.hpp) aliases fmt or std into mc_fmt so call sites are
unchanged. The NodeInfo struct gains an explicit constructor to support
C++17 aggregate initialization rules. Packaging conditionally installs
fmt when built from source and emits find_dependency(fmt) when found
via the system.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.00%. Comparing base (b5730b0) to head (a18a8d9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #263   +/-   ##
=======================================
  Coverage   70.00%   70.00%           
=======================================
  Files           5        5           
  Lines          10       10           
=======================================
  Hits            7        7           
  Misses          3        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in build path to support C++17 by routing formatting calls through a compatibility shim that uses either {fmt} or std::format, and updates CMake/packaging to conditionally bring in {fmt}.

Changes:

  • Introduce MECH_CONFIG_USE_FMT (default OFF) to build with C++17 + {fmt} instead of C++20 + std::format.
  • Add format_compat.hpp shim and migrate call sites from std::format(...) to mc_fmt::format(...).
  • Update packaging/config generation to optionally install/declare {fmt} as a dependency; adjust ErrorLocation formatter specialization and NodeInfo construction for C++17 compatibility.

Reviewed changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/validate_schema.cpp Switch formatting calls to mc_fmt::format via shim include.
src/parser.cpp Replace std::format usage with mc_fmt::format.
src/development/utils.cpp Replace std::format usage with mc_fmt::format.
src/development/type_validators.cpp Replace std::format usage with mc_fmt::format.
src/development/reactions/validators/wet_deposition.cpp Replace <format> include with shim include.
src/development/reactions/validators/user_defined.cpp Replace <format> include with shim include.
src/development/reactions/validators/taylor_series.cpp Replace formatting calls with mc_fmt::format and include shim.
src/development/reactions/validators/surface.cpp Replace formatting calls with mc_fmt::format and include shim.
src/development/reactions/validators/simpol_phase_transfer.cpp Replace formatting calls with mc_fmt::format and include shim.
src/development/reactions/validators/photolysis.cpp Replace formatting calls with mc_fmt::format and include shim.
src/development/reactions/validators/lambda_rate_constant.cpp Replace <format> include with shim include.
src/development/reactions/validators/henrys_law.cpp Replace formatting calls with mc_fmt::format and include shim.
src/development/reactions/validators/first_order_loss.cpp Replace formatting calls with mc_fmt::format and include shim.
src/development/reactions/validators/emission.cpp Replace <format> include with shim include.
src/development/reactions/validators/condensed_phase_photolysis.cpp Replace formatting calls with mc_fmt::format and include shim.
src/development/reactions/validators/condensed_phase_arrhenius.cpp Replace formatting calls with mc_fmt::format and include shim.
src/development/reactions/validators/branched.cpp Replace <format> include with shim include.
src/development/reactions/validators/arrhenius.cpp Replace formatting calls with mc_fmt::format and include shim.
src/development/reactions/validators/aqueous_equilibrium.cpp Replace <format> include with shim include.
src/development/models/validators/modal.cpp Replace formatting calls with mc_fmt::format.
src/development/mechanism.cpp Replace formatting calls with mc_fmt::format and include shim.
src/CMakeLists.txt Conditionally set C++17 + {fmt} vs C++20 + std::format.
packaging/CMakeLists.txt Conditionally install/export {fmt} target and set config-time dependency flag.
include/mechanism_configuration/format_compat.hpp New shim header selecting {fmt} or std::format under mc_fmt.
include/mechanism_configuration/error_location.hpp Use shim include and provide {fmt} vs std::formatter specialization.
include/mechanism_configuration/development/utils.hpp Add NodeInfo constructor to support C++17 (non-parenthesized aggregate init).
cmake/mechanism_configurationConfig.cmake.in Conditionally find_dependency(fmt) for consumers.
cmake/dependencies.cmake Add optional {fmt} FetchContent dependency when enabled.
CMakeLists.txt Add MECH_CONFIG_USE_FMT option; remove global C++20 standard setting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/CMakeLists.txt Outdated
Comment thread include/mechanism_configuration/development/utils.hpp Outdated
K20shores and others added 6 commits April 30, 2026 14:23
Adds fmt-variant jobs to the Mac, Ubuntu, and Windows workflows that
mirror the existing jobs but configure with -D MECH_CONFIG_USE_FMT=ON.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replaces the duplicate fmt/non-fmt jobs with a single job per runner
that includes use_fmt: [false, true] in the matrix. On Ubuntu, use_fmt
also controls whether CMAKE_CXX_STANDARD=20 is passed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Passes the value directly to CMake rather than using boolean conditionals.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
MSVC rejects designated initializers in C++17 mode (C7555). GCC/Clang
accept them as an extension but MSVC is strict. Replace all five
occurrences in the v0 parsers with positional brace-init.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
MECH_CONFIG_USE_FMT still allows swapping std::format for fmt::format,
but the C++ standard stays at 20 regardless. Reverts the cxx_std_17
downgrade, NodeInfo constructor, and designated initializer workarounds
that were only needed for C++17 compatibility.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
K20shores and others added 2 commits May 1, 2026 09:42
These were replaced with positional brace-init during the now-abandoned
C++17 support work. C++20 is still the standard, so designated initializers
are valid and preferred.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fmt headers are included from the public header format_compat.hpp, so
consumers need fmt's include dirs propagated. PRIVATE suppresses that.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@K20shores K20shores changed the title Add MECH_CONFIG_USE_FMT option for C++17 compatibility Make fmt, std::format optional May 1, 2026
K20shores and others added 2 commits May 5, 2026 23:37
…nd Docker

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@K20shores K20shores requested a review from boulderdaze May 12, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support fmt and <format>

4 participants