remove use of fmt

All uses of fmt can be replaced with either std::format directly
or a tentative implementation of std::print (which we can use
until GCC supports std::print).  Remove the extra dependency.

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I466497695a6d53b7767a6456bebe165c5a75121a
diff --git a/src/args.cpp b/src/args.cpp
index b81de5a..f56da60 100644
--- a/src/args.cpp
+++ b/src/args.cpp
@@ -1,8 +1,8 @@
 #include "args.hpp"
 
-#include <fmt/format.h>
 #include <getopt.h>
 
+#include <format>
 #include <stdexcept>
 
 namespace kcsbridge
@@ -26,10 +26,10 @@
                 break;
             case ':':
                 throw std::runtime_error(
-                    fmt::format("Missing argument for `{}`", argv[optind - 1]));
+                    std::format("Missing argument for `{}`", argv[optind - 1]));
                 break;
             default:
-                throw std::runtime_error(fmt::format(
+                throw std::runtime_error(std::format(
                     "Invalid command line argument `{}`", argv[optind - 1]));
         }
     }
diff --git a/src/cmd.cpp b/src/cmd.cpp
index 4d0dec8..a3c9d3f 100644
--- a/src/cmd.cpp
+++ b/src/cmd.cpp
@@ -1,6 +1,6 @@
 #include "cmd.hpp"
 
-#include <fmt/format.h>
+#include "print.hpp"
 
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/exception.hpp>
@@ -10,6 +10,8 @@
 #include <stdplus/fd/ops.hpp>
 
 #include <array>
+#include <cstdio>
+#include <format>
 #include <map>
 #include <span>
 #include <stdexcept>
@@ -45,7 +47,7 @@
         // netfn needs to be changed to odd in KCS responses
         if (data.size() + 3 > buffer.size())
         {
-            throw std::runtime_error(fmt::format(
+            throw std::runtime_error(std::format(
                 "too large {} > {}", data.size() + 3, buffer.size()));
         }
         buffer[0] = (netfn | 1) << 2;
@@ -57,7 +59,7 @@
     }
     catch (const std::exception& e)
     {
-        fmt::print(stderr, "IPMI response failure: {}\n", e.what());
+        std::print(stderr, "IPMI response failure: {}\n", e.what());
         buffer[0] |= 1 << 2;
         buffer[2] = 0xff;
     }
@@ -74,12 +76,12 @@
     }
     if (outstanding)
     {
-        fmt::print(stderr, "Canceling outstanding request\n");
+        std::print(stderr, "Canceling outstanding request\n");
         outstanding = slot_t(nullptr);
     }
     if (in.size() < 2)
     {
-        fmt::print(stderr, "Read too small, ignoring\n");
+        std::print(stderr, "Read too small, ignoring\n");
         return;
     }
     auto m = bus.new_method_call("xyz.openbmc_project.Ipmi.Host",
diff --git a/src/main.cpp b/src/main.cpp
index 6abd949..9d7d99e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,8 +1,8 @@
 #include "args.hpp"
 #include "cmd.hpp"
+#include "print.hpp"
 #include "server.hpp"
 
-#include <fmt/format.h>
 #include <systemd/sd-daemon.h>
 
 #include <sdbusplus/bus.hpp>
@@ -15,6 +15,8 @@
 #include <stdplus/signal.hpp>
 
 #include <algorithm>
+#include <cstdio>
+#include <format>
 #include <stdexcept>
 #include <string>
 
@@ -36,7 +38,7 @@
 
     // Configure basic signal handling
     auto exit_handler = [&event](Signal&, const struct signalfd_siginfo*) {
-        fmt::print(stderr, "Interrupted, Exiting\n");
+        std::print(stderr, "Interrupted, Exiting\n");
         event.exit(0);
     };
     stdplus::signal::block(SIGINT);
@@ -46,7 +48,7 @@
 
     // Open an FD for the KCS channel
     stdplus::ManagedFd kcs = stdplus::fd::open(
-        fmt::format("/dev/{}", channel),
+        std::format("/dev/{}", channel),
         OpenFlags(OpenAccess::ReadWrite).set(OpenFlag::NonBlock));
     sdbusplus::slot_t slot(nullptr);
 
@@ -79,7 +81,7 @@
     }
     catch (const std::exception& e)
     {
-        fmt::print(stderr, "FAILED: {}\n", e.what());
+        std::print(stderr, "FAILED: {}\n", e.what());
         return 1;
     }
 }
diff --git a/src/meson.build b/src/meson.build
index 68b6f9a..55b914d 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,23 +1,6 @@
 headers = include_directories('.')
 
-fmt_dep = dependency('fmt', required: false)
-if not fmt_dep.found()
-  fmt_opts = import('cmake').subproject_options()
-  fmt_opts.add_cmake_defines({
-    'CMAKE_POSITION_INDEPENDENT_CODE': 'ON',
-    'MASTER_PROJECT': 'OFF',
-  })
-  fmt_proj = import('cmake').subproject(
-    'fmt',
-    options: fmt_opts,
-    required: false)
-  assert(fmt_proj.found(), 'fmtlib is required')
-  fmt_dep = fmt_proj.dependency('fmt')
-endif
-
-
 deps = [
-  fmt_dep,
   dependency('stdplus', fallback: ['stdplus', 'stdplus_dep']),
   dependency('sdbusplus', fallback: ['sdbusplus', 'sdbusplus_dep']),
 ]
diff --git a/src/print.hpp b/src/print.hpp
new file mode 100644
index 0000000..001149c
--- /dev/null
+++ b/src/print.hpp
@@ -0,0 +1,27 @@
+#pragma once
+
+#include <stdio.h>
+
+#include <format>
+
+// use this until gcc c++ lib has <print>
+namespace std
+{
+inline void vprint(std::FILE* f, std::string_view format, std::format_args args)
+{
+    std::string d = std::vformat(format, args);
+    fwrite(d.data(), 1, d.size(), f);
+}
+template <class... Args>
+inline void print(std::FILE* f, std::format_string<Args...> format,
+                  Args&&... args)
+{
+    vprint(f, format.get(), std::make_format_args(std::forward<Args>(args)...));
+}
+template <class... Args>
+inline void print(std::format_string<Args...> format, Args&&... args)
+{
+    vprint(stdout, format.get(),
+           std::make_format_args(std::forward<Args>(args)...));
+}
+} // namespace std
diff --git a/src/server.cpp b/src/server.cpp
index 5b41c05..4ac4929 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -1,6 +1,7 @@
 #include "server.hpp"
 
-#include <fmt/format.h>
+#include "print.hpp"
+
 #include <linux/ipmi_bmc.h>
 
 #include <sdbusplus/exception.hpp>
@@ -8,6 +9,7 @@
 #include <sdbusplus/vtable.hpp>
 #include <stdplus/fd/ops.hpp>
 
+#include <cstdio>
 #include <stdexcept>
 
 namespace kcsbridge
@@ -41,7 +43,7 @@
     }
     catch (const std::exception& e)
     {
-        fmt::print(stderr, "Method response failed: {}\n", e.what());
+        std::print(stderr, "Method response failed: {}\n", e.what());
         sd_bus_error_set(error,
                          "xyz.openbmc_project.Common.Error.InternalFailure",
                          "The operation failed internally.");
diff --git a/subprojects/fmt.wrap b/subprojects/fmt.wrap
deleted file mode 100644
index 6847ae5..0000000
--- a/subprojects/fmt.wrap
+++ /dev/null
@@ -1,3 +0,0 @@
-[wrap-git]
-url = https://github.com/fmtlib/fmt
-revision = HEAD