This is an automated email from the ASF dual-hosted git repository.

Fokko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/main by this push:
     new d77446e5d0 AVRO-XXX: [C++] Replace fmt with std::format and require 
C++20 (#3788)
d77446e5d0 is described below

commit d77446e5d05cd68c28d09c1af800a428dea34e03
Author: Gang Wu <[email protected]>
AuthorDate: Wed Jun 3 04:07:22 2026 +0800

    AVRO-XXX: [C++] Replace fmt with std::format and require C++20 (#3788)
---
 .github/workflows/test-lang-c++.yml     |  2 +-
 lang/c++/CMakeLists.txt                 | 14 --------------
 lang/c++/cmake/avro-cpp-config.cmake.in |  1 -
 lang/c++/cmake/avro-cpp.pc.in           |  1 -
 lang/c++/impl/Compiler.cc               |  1 +
 lang/c++/impl/DataFile.cc               |  1 +
 lang/c++/impl/avrogencpp.cc             |  1 +
 lang/c++/include/avro/Exception.hh      |  6 +++---
 lang/c++/include/avro/Node.hh           |  8 ++++----
 lang/c++/include/avro/Types.hh          |  9 ++++-----
 10 files changed, 15 insertions(+), 29 deletions(-)

diff --git a/.github/workflows/test-lang-c++.yml 
b/.github/workflows/test-lang-c++.yml
index ab2a60a9a6..015cd831b8 100644
--- a/.github/workflows/test-lang-c++.yml
+++ b/.github/workflows/test-lang-c++.yml
@@ -44,7 +44,7 @@ jobs:
       - uses: actions/checkout@v6
 
       - name: Install Dependencies
-        run: sudo apt update && sudo apt-get install -qqy cppcheck 
libboost-all-dev libsnappy-dev libfmt-dev zlib1g-dev libzstd-dev cmake
+        run: sudo apt update && sudo apt-get install -qqy cppcheck 
libboost-all-dev libsnappy-dev zlib1g-dev libzstd-dev cmake
 
       - name: Print Versions
         run: |
diff --git a/lang/c++/CMakeLists.txt b/lang/c++/CMakeLists.txt
index 8fb643cd82..a88bc77f09 100644
--- a/lang/c++/CMakeLists.txt
+++ b/lang/c++/CMakeLists.txt
@@ -83,19 +83,6 @@ if (AVRO_BUILD_TESTS OR AVRO_USE_BOOST)
     find_package (Boost 1.70 REQUIRED CONFIG)
 endif ()
 
-find_package(fmt QUIET)
-if (NOT fmt_FOUND)
-    include(FetchContent)
-    FetchContent_Declare(
-            fmt
-            GIT_REPOSITORY  https://github.com/fmtlib/fmt.git
-            GIT_TAG         10.2.1
-            GIT_PROGRESS    TRUE
-            USES_TERMINAL_DOWNLOAD TRUE
-    )
-    FetchContent_MakeAvailable(fmt)
-endif ()
-
 find_package(Snappy CONFIG)
 if (Snappy_FOUND)
     # Use CONFIG mode to guarantee that Snappy::snappy target exists if found.
@@ -149,7 +136,6 @@ function (setup_avro_lib target lib_type)
     endif ()
     set_target_properties (${target} PROPERTIES VERSION ${AVRO_VERSION})
     target_link_libraries (${target} PUBLIC
-      $<BUILD_INTERFACE:fmt::fmt-header-only>
       $<BUILD_INTERFACE:ZLIB::ZLIB>
       $<BUILD_INTERFACE:$<TARGET_NAME_IF_EXISTS:Snappy::snappy>>
       
$<$<BOOL:${zstd_FOUND}>:$<BUILD_INTERFACE:$<TARGET_NAME_IF_EXISTS:${ZSTD_TARGET}>>>
diff --git a/lang/c++/cmake/avro-cpp-config.cmake.in 
b/lang/c++/cmake/avro-cpp-config.cmake.in
index 5104843f3a..dc8506c763 100644
--- a/lang/c++/cmake/avro-cpp-config.cmake.in
+++ b/lang/c++/cmake/avro-cpp-config.cmake.in
@@ -38,7 +38,6 @@ endif()
 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
 
 find_dependency(ZLIB REQUIRED)
-find_dependency(fmt REQUIRED)
 if(@Snappy_FOUND@)
     find_dependency(Snappy REQUIRED)
 endif()
diff --git a/lang/c++/cmake/avro-cpp.pc.in b/lang/c++/cmake/avro-cpp.pc.in
index e37d602f36..3889d7350f 100644
--- a/lang/c++/cmake/avro-cpp.pc.in
+++ b/lang/c++/cmake/avro-cpp.pc.in
@@ -29,4 +29,3 @@ Version: @AVRO_VERSION@
 
 Cflags: -I${includedir}
 Libs: -L${libdir} -lavrocpp
-Requires: fmt
diff --git a/lang/c++/impl/Compiler.cc b/lang/c++/impl/Compiler.cc
index d0ac20d020..c0b39f9e74 100644
--- a/lang/c++/impl/Compiler.cc
+++ b/lang/c++/impl/Compiler.cc
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 
+#include <cstring>
 #include <sstream>
 #include <unordered_set>
 #include <utility>
diff --git a/lang/c++/impl/DataFile.cc b/lang/c++/impl/DataFile.cc
index 3a93a5fdf5..661ee583d0 100644
--- a/lang/c++/impl/DataFile.cc
+++ b/lang/c++/impl/DataFile.cc
@@ -18,6 +18,7 @@
 
 #include "DataFile.hh"
 #include "Compiler.hh"
+#include <cstring>
 #include "Exception.hh"
 
 #include <random>
diff --git a/lang/c++/impl/avrogencpp.cc b/lang/c++/impl/avrogencpp.cc
index d6e914e965..dd5826efbf 100644
--- a/lang/c++/impl/avrogencpp.cc
+++ b/lang/c++/impl/avrogencpp.cc
@@ -18,6 +18,7 @@
 
 #include <algorithm>
 #include <cctype>
+#include <cstring>
 #ifndef _WIN32
 #include <ctime>
 #endif
diff --git a/lang/c++/include/avro/Exception.hh 
b/lang/c++/include/avro/Exception.hh
index 234a1c9302..b5e33519e4 100644
--- a/lang/c++/include/avro/Exception.hh
+++ b/lang/c++/include/avro/Exception.hh
@@ -20,7 +20,7 @@
 #define avro_Exception_hh__
 
 #include "Config.hh"
-#include <fmt/core.h>
+#include <format>
 #include <stdexcept>
 
 namespace avro {
@@ -33,8 +33,8 @@ public:
     explicit Exception(const std::string &msg) : std::runtime_error(msg) {}
 
     template<typename... Args>
-    Exception(fmt::format_string<Args...> fmt, Args &&...args)
-        : std::runtime_error(fmt::format(fmt, std::forward<Args>(args)...)) {}
+    Exception(std::format_string<Args...> fmt, Args &&...args)
+        : std::runtime_error(std::format(fmt, std::forward<Args>(args)...)) {}
 };
 
 } // namespace avro
diff --git a/lang/c++/include/avro/Node.hh b/lang/c++/include/avro/Node.hh
index 72e85e0ee4..5f8dd2a443 100644
--- a/lang/c++/include/avro/Node.hh
+++ b/lang/c++/include/avro/Node.hh
@@ -22,6 +22,7 @@
 #include "Config.hh"
 
 #include <cassert>
+#include <format>
 #include <memory>
 #include <utility>
 #include <vector>
@@ -223,10 +224,9 @@ inline std::ostream &operator<<(std::ostream &os, const 
avro::Node &n) {
 } // namespace std
 
 template<>
-struct fmt::formatter<avro::Name> : fmt::formatter<std::string> {
-    template<typename FormatContext>
-    constexpr auto format(const avro::Name &n, FormatContext &ctx) const {
-        return fmt::formatter<std::string>::format(n.fullname(), ctx);
+struct std::formatter<avro::Name, char> : std::formatter<std::string, char> {
+    auto format(const avro::Name &n, std::format_context &ctx) const {
+        return std::formatter<std::string, char>::format(n.fullname(), ctx);
     }
 };
 
diff --git a/lang/c++/include/avro/Types.hh b/lang/c++/include/avro/Types.hh
index d02b8006e5..fca3a4b86f 100644
--- a/lang/c++/include/avro/Types.hh
+++ b/lang/c++/include/avro/Types.hh
@@ -19,7 +19,7 @@
 #ifndef avro_Types_hh__
 #define avro_Types_hh__
 
-#include <fmt/format.h>
+#include <format>
 #include <iostream>
 
 #include "Config.hh"
@@ -111,10 +111,9 @@ std::ostream &operator<<(std::ostream &os, const Null 
&null);
 } // namespace avro
 
 template<>
-struct fmt::formatter<avro::Type> : fmt::formatter<std::string> {
-    template<typename FormatContext>
-    constexpr auto format(avro::Type t, FormatContext &ctx) const {
-        return fmt::formatter<std::string>::format(avro::toString(t), ctx);
+struct std::formatter<avro::Type, char> : std::formatter<std::string, char> {
+    auto format(avro::Type t, std::format_context &ctx) const {
+        return std::formatter<std::string, char>::format(avro::toString(t), 
ctx);
     }
 };
 

Reply via email to