Skip to content

remove dependency on fmt library, using std::format instead #929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
clang >=18
msvc >=14.40
apple-clang *
standards: '20'
standards: '23'
latest-factors: |
msvc Optimized-Debug
gcc Coverage
Expand Down Expand Up @@ -287,26 +287,6 @@ jobs:
run-tests: false
trace-commands: true

- name: Install Fmt
uses: alandefreitas/cpp-actions/[email protected]
with:
source-dir: ../third-party/fmt
git-repository: https://github.com/fmtlib/fmt
git-tag: 10.2.1
build-dir: ${sourceDir}/build
cc: ${{ steps.setup-cpp.outputs.cc }}
cxx: ${{ steps.setup-cpp.outputs.cxx }}
ccflags: ${{ matrix.ccflags }}
cxxflags: ${{ matrix.cxxflags }}
build-type: ${{ matrix.build-type }}
extra-args: |
-D FMT_DOC=OFF
-D FMT_TEST=OFF
install: true
install-prefix: ${sourceDir}/install
run-tests: false
trace-commands: true

- name: Install Libxml2
uses: alandefreitas/cpp-actions/[email protected]
if: matrix.compiler == 'msvc'
Expand Down Expand Up @@ -384,7 +364,6 @@ jobs:
-D Clang_ROOT=../third-party/llvm-project/install
-D duktape_ROOT=../third-party/duktape/install
-D Duktape_ROOT=../third-party/duktape/install
-D fmt_ROOT=../third-party/fmt/install
${{ runner.os == 'Windows' && '-D libxml2_ROOT=../third-party/libxml2/install' || '' }}
${{ runner.os == 'Windows' && '-D LibXml2_ROOT=../third-party/libxml2/install' || '' }}
export-compile-commands: true
Expand Down
6 changes: 1 addition & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ llvm_map_components_to_libnames(llvm_libs all)
string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

# fmt
find_package(fmt REQUIRED CONFIG)

# Duktape
find_package(Duktape CONFIG)
if (NOT DUKTAPE_FOUND)
Expand Down Expand Up @@ -214,7 +211,7 @@ list(APPEND LIB_SOURCES
${CMAKE_CURRENT_BINARY_DIR}/src/lib/Lib/PublicSettings.cpp
)
add_library(mrdocs-core ${LIB_SOURCES})
target_compile_features(mrdocs-core PUBLIC cxx_std_20)
target_compile_features(mrdocs-core PUBLIC cxx_std_23)
target_include_directories(mrdocs-core
PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>"
Expand All @@ -234,7 +231,6 @@ target_compile_definitions(
# Dependencies
target_include_directories(mrdocs-core SYSTEM PUBLIC ${LLVM_INCLUDE_DIRS})
target_include_directories(mrdocs-core SYSTEM PUBLIC ${CLANG_INCLUDE_DIRS})
target_link_libraries(mrdocs-core PUBLIC fmt::fmt)
target_include_directories(mrdocs-core SYSTEM PRIVATE ${DUKTAPE_INCLUDE_DIRS})
target_link_libraries(mrdocs-core PRIVATE ${DUKTAPE_LIBRARY})

Expand Down
23 changes: 1 addition & 22 deletions docs/modules/ROOT/pages/install.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,6 @@ These instructions assume all dependencies are installed in the `third-party` di
Feel free to install them anywhere you want and adjust the main MrDocs configuration command later.
====

[#install-fmt]
=== Fmt

MrDocs uses the `fmt` library for formatting strings.
From the `third-party` directory, you can clone the `fmt` repository and install it with the following commands:

[source,bash]
----
git clone https://github.com/fmtlib/fmt --branch 10.2.1 --depth 1 <.>
cd fmt
cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Release -D FMT_DOC=OFF -D FMT_TEST=OFF <.>
cmake --build ./build --config Release <.>
cmake --install ./build --prefix ./install <.>
cd ..
----

<.> Shallow clones the fmt repository.
<.> Configure the fmt library with CMake, excluding the documentation and tests.
<.> Builds the fmt library in the `build` directory.
<.> Installs the fmt library in the `install` directory.

[IMPORTANT]
====
All instructions in this document assume you are using a CMake version above 3.26.
Expand Down Expand Up @@ -376,7 +355,7 @@ cd ../..

The MrDocs repository also includes a `CMakePresets.json` file that contains the parameters to configure MrDocs with CMake.

To specify the installation directories, you can use the `LLVM_ROOT`, `DUKTAPE_ROOT`, `FMT_ROOT`, and `LIBXML2_ROOT` environment variables.
To specify the installation directories, you can use the `LLVM_ROOT`, `DUKTAPE_ROOT`, and `LIBXML2_ROOT` environment variables.
To specify a generator (`-G`) and platform name (`-A`), you can use the `CMAKE_GENERATOR` and `CMAKE_GENERATOR_PLATFORM` environment variables.

You can also customize the presets by duplicating and editing the `CMakeUserPresets.json.example` file in the `mrdocs` directory.
Expand Down
9 changes: 5 additions & 4 deletions include/mrdocs/Dom/Object.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,15 @@ Object::visit(F&& fn) const
//------------------------------------------------

template<>
struct fmt::formatter<clang::mrdocs::dom::Object>
: fmt::formatter<std::string>
struct std::formatter<clang::mrdocs::dom::Object>
: std::formatter<std::string>
{
template <class FmtContext>
auto format(
clang::mrdocs::dom::Object const& value,
fmt::format_context& ctx) const
FmtContext& ctx) const
{
return fmt::formatter<std::string>::format(
return std::formatter<std::string>::format(
toString(value), ctx);
}
};
Expand Down
20 changes: 8 additions & 12 deletions include/mrdocs/Dom/String.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#ifndef MRDOCS_API_DOM_STRING_HPP
#define MRDOCS_API_DOM_STRING_HPP

#include <format>
#include <mrdocs/Platform.hpp>
#include <mrdocs/Support/String.hpp>
#include <fmt/format.h>

namespace clang {
namespace mrdocs {
Expand Down Expand Up @@ -341,17 +341,13 @@ class MRDOCS_DECL

//------------------------------------------------

template<>
struct fmt::formatter<clang::mrdocs::dom::String>
: fmt::formatter<std::string_view>
{
auto format(
clang::mrdocs::dom::String const& value,
fmt::format_context& ctx) const
{
return fmt::formatter<std::string_view>::format(
value.get(), ctx);
}
template <>
struct std::formatter<clang::mrdocs::dom::String>
: std::formatter<std::string_view> {
template <class FmtContext>
auto format(clang::mrdocs::dom::String const &value, FmtContext &ctx) const {
return std::formatter<std::string_view>::format(value.get(), ctx);
}
};

#endif
29 changes: 13 additions & 16 deletions include/mrdocs/Dom/Value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
#ifndef MRDOCS_API_DOM_VALUE_HPP
#define MRDOCS_API_DOM_VALUE_HPP

#include <mrdocs/Platform.hpp>
#include <charconv>
#include <compare>
#include <format>
#include <mrdocs/ADT/Optional.hpp>
#include <mrdocs/Dom/Array.hpp>
#include <mrdocs/Dom/Kind.hpp>
#include <mrdocs/Dom/Function.hpp>
#include <mrdocs/Dom/Kind.hpp>
#include <mrdocs/Dom/Object.hpp>
#include <mrdocs/Dom/String.hpp>
#include <mrdocs/ADT/Optional.hpp>
#include <mrdocs/Platform.hpp>
#include <mrdocs/Support/Error.hpp>
#include <optional> // BAD
#include <string>
#include <charconv>
#include <compare>

namespace clang {
namespace mrdocs {
Expand Down Expand Up @@ -849,17 +850,13 @@ safeString(SV const& str) {

//------------------------------------------------

template<>
struct fmt::formatter<clang::mrdocs::dom::Value>
: public fmt::formatter<std::string>
{
auto format(
clang::mrdocs::dom::Value const& value,
fmt::format_context& ctx) const
{
return fmt::formatter<std::string>::format(
toString(value), ctx);
}
template <>
struct std::formatter<clang::mrdocs::dom::Value>
: public std::formatter<std::string> {
template <class FmtContext>
auto format(clang::mrdocs::dom::Value const &value, FmtContext &ctx) const {
return std::formatter<std::string>::format(toString(value), ctx);
}
};

#endif
15 changes: 8 additions & 7 deletions include/mrdocs/Metadata/Javadoc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
#ifndef MRDOCS_API_METADATA_JAVADOC_HPP
#define MRDOCS_API_METADATA_JAVADOC_HPP

#include <mrdocs/Platform.hpp>
#include <mrdocs/Metadata/SymbolID.hpp>
#include <mrdocs/Support/Visitor.hpp>
#include <mrdocs/Support/Concepts.hpp>
#include <algorithm>
#include <memory>
#include <mrdocs/ADT/Polymorphic.hpp>
#include <mrdocs/Dom/String.hpp>
#include <mrdocs/Dom/LazyObject.hpp>
#include <mrdocs/Dom/LazyArray.hpp>
#include <memory>
#include <mrdocs/Dom/LazyObject.hpp>
#include <mrdocs/Dom/String.hpp>
#include <mrdocs/Metadata/SymbolID.hpp>
#include <mrdocs/Platform.hpp>
#include <mrdocs/Support/Concepts.hpp>
#include <mrdocs/Support/Visitor.hpp>
#include <string>
#include <type_traits>
#include <utility>
Expand Down
46 changes: 19 additions & 27 deletions include/mrdocs/Support/Error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
#ifndef MRDOCS_API_SUPPORT_ERROR_HPP
#define MRDOCS_API_SUPPORT_ERROR_HPP

#include <mrdocs/Platform.hpp>
#include <mrdocs/Support/source_location.hpp>
#include <fmt/format.h>
#include <exception>
#include <format>
#include <functional>
#include <memory>
#include <mrdocs/Platform.hpp>
#include <mrdocs/Support/source_location.hpp>
#include <string>
#include <string_view>
#include <system_error>
#include <type_traits>
#include <utility>
#include <vector>
#include <functional>

namespace clang::mrdocs {

Expand Down Expand Up @@ -256,28 +257,20 @@ struct std::hash<::clang::mrdocs::Error>
}
};

template<>
struct fmt::formatter<clang::mrdocs::Error>
: fmt::formatter<std::string_view>
{
auto format(
clang::mrdocs::Error const& err,
fmt::format_context& ctx) const
{
return fmt::formatter<std::string_view>::format(err.message(), ctx);
}
template <>
struct std::formatter<clang::mrdocs::Error> : std::formatter<std::string_view> {
template <class FmtContext>
auto format(clang::mrdocs::Error const &err, FmtContext &ctx) const {
return std::formatter<std::string_view>::format(err.message(), ctx);
}
};

template<>
struct fmt::formatter<std::error_code>
: fmt::formatter<std::string_view>
{
auto format(
std::error_code const& ec,
fmt::format_context& ctx) const
{
return fmt::formatter<std::string_view>::format(ec.message(), ctx);
}
template <>
struct std::formatter<std::error_code> : std::formatter<std::string_view> {
template <class FmtContext>
auto format(std::error_code const &ec, FmtContext &ctx) const {
return std::formatter<std::string_view>::format(ec.message(), ctx);
}
};

namespace clang::mrdocs {
Expand Down Expand Up @@ -353,9 +346,8 @@ formatError(
Args&&... args)
{
std::string s;
fmt::vformat_to(
std::back_inserter(s),
fs.fs, fmt::make_format_args(args...));
std::vformat_to(std::back_inserter(s), fs.fs,
std::make_format_args(args...));
return Error(std::move(s), fs.loc);
}

Expand Down
9 changes: 4 additions & 5 deletions include/mrdocs/Support/Expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@
#ifndef MRDOCS_API_SUPPORT_EXPECTED_HPP
#define MRDOCS_API_SUPPORT_EXPECTED_HPP

#include <mrdocs/Platform.hpp>
#include <mrdocs/Support/source_location.hpp>
#include <mrdocs/Support/Error.hpp>
#include <fmt/format.h>
#include <exception>
#include <functional>
#include <iterator>
#include <memory>
#include <mrdocs/Platform.hpp>
#include <mrdocs/Support/Error.hpp>
#include <mrdocs/Support/source_location.hpp>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include <vector>
#include <functional>

namespace clang::mrdocs {

Expand Down
26 changes: 11 additions & 15 deletions include/mrdocs/Support/Handlebars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
#ifndef MRDOCS_TOOL_SUPPORT_PATH_HPP
#define MRDOCS_TOOL_SUPPORT_PATH_HPP

#include <mrdocs/Support/String.hpp>
#include <format>
#include <functional>
#include <mrdocs/Dom.hpp>
#include <mrdocs/Support/String.hpp>
#include <string_view>
#include <unordered_map>
#include <functional>
#include <type_traits>
#include <vector>
#include <unordered_map>
#include <variant>
#include <vector>

namespace clang {
namespace mrdocs {
Expand All @@ -45,15 +46,10 @@ struct HandlebarsError
HandlebarsError(std::string_view msg)
: std::runtime_error(std::string(msg)) {}

HandlebarsError(
std::string_view msg,
std::size_t line_,
std::size_t column_,
std::size_t pos_)
: std::runtime_error(fmt::format("{} - {}:{}", msg, line_, column_))
, line(line_)
, column(column_)
, pos(pos_) {}
HandlebarsError(std::string_view msg, std::size_t line_,
std::size_t column_, std::size_t pos_)
: std::runtime_error(std::format("{} - {}:{}", msg, line_, column_)),
line(line_), column(column_), pos(pos_) {}
};

namespace detail {
Expand Down Expand Up @@ -218,9 +214,9 @@ class MRDOCS_DECL OutputRef
@return A reference to this object
*/
template <class T>
requires fmt::is_formattable<T>::value
requires std::formattable<T, char>
friend OutputRef &operator<<(OutputRef &os, T v) {
std::string s = fmt::format("{}", v);
std::string s = std::format("{}", v);
return os.write_impl(s);
}

Expand Down
Loading
Loading