Skip to content

Commit 647c823

Browse files
committed
remove dependency on fmt library, using std::format instead
This bumps the standard version to C++23, so that the `formattable` concept becomes available. This removes the color support from `diff.cpp`, since that is not available in std::format.
1 parent 26d4c50 commit 647c823

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+498
-639
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -282,26 +282,6 @@ jobs:
282282
run-tests: false
283283
trace-commands: true
284284

285-
- name: Install Fmt
286-
uses: alandefreitas/cpp-actions/[email protected]
287-
with:
288-
source-dir: ../third-party/fmt
289-
git-repository: https://github.com/fmtlib/fmt
290-
git-tag: 10.2.1
291-
build-dir: ${sourceDir}/build
292-
cc: ${{ steps.setup-cpp.outputs.cc }}
293-
cxx: ${{ steps.setup-cpp.outputs.cxx }}
294-
ccflags: ${{ matrix.ccflags }}
295-
cxxflags: ${{ matrix.cxxflags }}
296-
build-type: ${{ matrix.build-type }}
297-
extra-args: |
298-
-D FMT_DOC=OFF
299-
-D FMT_TEST=OFF
300-
install: true
301-
install-prefix: ${sourceDir}/install
302-
run-tests: false
303-
trace-commands: true
304-
305285
- name: Install Libxml2
306286
uses: alandefreitas/cpp-actions/[email protected]
307287
if: matrix.compiler == 'msvc'
@@ -378,7 +358,6 @@ jobs:
378358
-D Clang_ROOT=../third-party/llvm-project/install
379359
-D duktape_ROOT=../third-party/duktape/install
380360
-D Duktape_ROOT=../third-party/duktape/install
381-
-D fmt_ROOT=../third-party/fmt/install
382361
${{ runner.os == 'Windows' && '-D libxml2_ROOT=../third-party/libxml2/install' || '' }}
383362
${{ runner.os == 'Windows' && '-D LibXml2_ROOT=../third-party/libxml2/install' || '' }}
384363
export-compile-commands: true

CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ llvm_map_components_to_libnames(llvm_libs all)
119119
string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
120120
string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
121121

122-
# fmt
123-
find_package(fmt REQUIRED CONFIG)
124-
125122
# Duktape
126123
find_package(Duktape CONFIG)
127124
if (NOT DUKTAPE_FOUND)
@@ -214,7 +211,7 @@ list(APPEND LIB_SOURCES
214211
${CMAKE_CURRENT_BINARY_DIR}/src/lib/Lib/PublicSettings.cpp
215212
)
216213
add_library(mrdocs-core ${LIB_SOURCES})
217-
target_compile_features(mrdocs-core PUBLIC cxx_std_20)
214+
target_compile_features(mrdocs-core PUBLIC cxx_std_23)
218215
target_include_directories(mrdocs-core
219216
PUBLIC
220217
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>"
@@ -234,7 +231,6 @@ target_compile_definitions(
234231
# Dependencies
235232
target_include_directories(mrdocs-core SYSTEM PUBLIC ${LLVM_INCLUDE_DIRS})
236233
target_include_directories(mrdocs-core SYSTEM PUBLIC ${CLANG_INCLUDE_DIRS})
237-
target_link_libraries(mrdocs-core PUBLIC fmt::fmt)
238234
target_include_directories(mrdocs-core SYSTEM PRIVATE ${DUKTAPE_INCLUDE_DIRS})
239235
target_link_libraries(mrdocs-core PRIVATE ${DUKTAPE_LIBRARY})
240236

docs/modules/ROOT/pages/install.adoc

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,9 @@ These instructions assume all dependencies are installed in the `third-party` di
4141
Feel free to install them anywhere you want and adjust the main MrDocs configuration command later.
4242
====
4343
44-
[#install-fmt]
44+
[#install-vcpkg]
4545
=== Fmt
4646
47-
MrDocs uses the `fmt` library for formatting strings.
48-
From the `third-party` directory, you can clone the `fmt` repository and install it with the following commands:
49-
50-
[source,bash]
51-
----
52-
git clone https://github.com/fmtlib/fmt --branch 10.2.1 --depth 1 <.>
53-
cd fmt
54-
cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Release -D FMT_DOC=OFF -D FMT_TEST=OFF <.>
55-
cmake --build ./build --config Release <.>
56-
cmake --install ./build --prefix ./install <.>
57-
cd ..
58-
----
59-
60-
<.> Shallow clones the fmt repository.
61-
<.> Configure the fmt library with CMake, excluding the documentation and tests.
62-
<.> Builds the fmt library in the `build` directory.
63-
<.> Installs the fmt library in the `install` directory.
64-
6547
[IMPORTANT]
6648
====
6749
All instructions in this document assume you are using a CMake version above 3.26.
@@ -82,12 +64,10 @@ Windows PowerShell::
8264
git clone https://github.com/microsoft/vcpkg.git -b master <.>
8365
cd vcpkg
8466
bootstrap-vcpkg.bat <.>
85-
vcpkg.exe install fmt --triplet x64-windows <.>
8667
----
8768
8869
<.> Clones the Vcpkg repository.
8970
<.> Bootstraps Vcpkg.
90-
<.> Installs the `fmt` library.
9171
--
9272
9373
Unix Variants::
@@ -98,18 +78,16 @@ Unix Variants::
9878
git clone https://github.com/microsoft/vcpkg.git -b master <.>
9979
cd vcpkg
10080
./bootstrap-vcpkg.sh <.>
101-
./vcpkg install fmt <.>
10281
----
10382
10483
<.> Clones the Vcpkg repository.
10584
<.> Bootstraps Vcpkg.
106-
<.> Installs the `fmt` library.
10785
--
10886
====
10987
11088
[NOTE]
11189
====
112-
You can also install `fmt` with Vcpkg in _Manifest mode_.
90+
You can also install the dependencies with Vcpkg in _Manifest mode_.
11391
In https://learn.microsoft.com/en-us/vcpkg/users/manifests[manifest mode,windows=blank_], you declare your project's direct dependencies in a manifest file named `vcpkg.json`.
11492
MrDocs includes a `vcpkg.json.example` file you can duplicate or create a symlink as `vcpkg.json` to use this mode.
11593
This file includes all the dependencies MrDocs needs, except for LLVM.
@@ -238,7 +216,7 @@ cd vcpkg
238216
--
239217
====
240218

241-
NOTE: These examples assume VcPkg is already installed in the `third-party/vcpkg` directory (see the <<install-fmt>> section).
219+
NOTE: These examples assume VcPkg is already installed in the `third-party/vcpkg` directory (see the <<install-vcpkg>> section).
242220

243221
=== Libxml2
244222

@@ -292,7 +270,7 @@ cd vcpkg
292270
--
293271
====
294272

295-
NOTE: These examples assume VcPkg is already installed in the `third-party/vcpkg` directory (see the <<install-fmt>> section).
273+
NOTE: These examples assume VcPkg is already installed in the `third-party/vcpkg` directory (see the <<install-vcpkg>> section).
296274

297275
=== LLVM
298276

include/mrdocs/Dom/Object.ipp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,15 @@ Object::visit(F&& fn) const
149149
//------------------------------------------------
150150

151151
template<>
152-
struct fmt::formatter<clang::mrdocs::dom::Object>
153-
: fmt::formatter<std::string>
152+
struct std::formatter<clang::mrdocs::dom::Object>
153+
: std::formatter<std::string>
154154
{
155+
template <class FmtContext>
155156
auto format(
156157
clang::mrdocs::dom::Object const& value,
157-
fmt::format_context& ctx) const
158+
FmtContext& ctx) const
158159
{
159-
return fmt::formatter<std::string>::format(
160+
return std::formatter<std::string>::format(
160161
toString(value), ctx);
161162
}
162163
};

include/mrdocs/Dom/String.hpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#ifndef MRDOCS_API_DOM_STRING_HPP
1212
#define MRDOCS_API_DOM_STRING_HPP
1313

14+
#include <format>
1415
#include <mrdocs/Platform.hpp>
1516
#include <mrdocs/Support/String.hpp>
16-
#include <fmt/format.h>
1717

1818
namespace clang {
1919
namespace mrdocs {
@@ -341,17 +341,13 @@ class MRDOCS_DECL
341341

342342
//------------------------------------------------
343343

344-
template<>
345-
struct fmt::formatter<clang::mrdocs::dom::String>
346-
: fmt::formatter<std::string_view>
347-
{
348-
auto format(
349-
clang::mrdocs::dom::String const& value,
350-
fmt::format_context& ctx) const
351-
{
352-
return fmt::formatter<std::string_view>::format(
353-
value.get(), ctx);
354-
}
344+
template <>
345+
struct std::formatter<clang::mrdocs::dom::String>
346+
: std::formatter<std::string_view> {
347+
template <class FmtContext>
348+
auto format(clang::mrdocs::dom::String const &value, FmtContext &ctx) const {
349+
return std::formatter<std::string_view>::format(value.get(), ctx);
350+
}
355351
};
356352

357353
#endif

include/mrdocs/Dom/Value.hpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
#ifndef MRDOCS_API_DOM_VALUE_HPP
1212
#define MRDOCS_API_DOM_VALUE_HPP
1313

14-
#include <mrdocs/Platform.hpp>
14+
#include <charconv>
15+
#include <compare>
16+
#include <format>
17+
#include <mrdocs/ADT/Optional.hpp>
1518
#include <mrdocs/Dom/Array.hpp>
16-
#include <mrdocs/Dom/Kind.hpp>
1719
#include <mrdocs/Dom/Function.hpp>
20+
#include <mrdocs/Dom/Kind.hpp>
1821
#include <mrdocs/Dom/Object.hpp>
1922
#include <mrdocs/Dom/String.hpp>
20-
#include <mrdocs/ADT/Optional.hpp>
23+
#include <mrdocs/Platform.hpp>
2124
#include <mrdocs/Support/Error.hpp>
2225
#include <optional> // BAD
2326
#include <string>
24-
#include <charconv>
25-
#include <compare>
2627

2728
namespace clang {
2829
namespace mrdocs {
@@ -849,17 +850,13 @@ safeString(SV const& str) {
849850

850851
//------------------------------------------------
851852

852-
template<>
853-
struct fmt::formatter<clang::mrdocs::dom::Value>
854-
: public fmt::formatter<std::string>
855-
{
856-
auto format(
857-
clang::mrdocs::dom::Value const& value,
858-
fmt::format_context& ctx) const
859-
{
860-
return fmt::formatter<std::string>::format(
861-
toString(value), ctx);
862-
}
853+
template <>
854+
struct std::formatter<clang::mrdocs::dom::Value>
855+
: public std::formatter<std::string> {
856+
template <class FmtContext>
857+
auto format(clang::mrdocs::dom::Value const &value, FmtContext &ctx) const {
858+
return std::formatter<std::string>::format(toString(value), ctx);
859+
}
863860
};
864861

865862
#endif

include/mrdocs/Metadata/Javadoc.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
#ifndef MRDOCS_API_METADATA_JAVADOC_HPP
1414
#define MRDOCS_API_METADATA_JAVADOC_HPP
1515

16-
#include <mrdocs/Platform.hpp>
17-
#include <mrdocs/Metadata/SymbolID.hpp>
18-
#include <mrdocs/Support/Visitor.hpp>
19-
#include <mrdocs/Support/Concepts.hpp>
16+
#include <algorithm>
17+
#include <memory>
2018
#include <mrdocs/ADT/Polymorphic.hpp>
21-
#include <mrdocs/Dom/String.hpp>
22-
#include <mrdocs/Dom/LazyObject.hpp>
2319
#include <mrdocs/Dom/LazyArray.hpp>
24-
#include <memory>
20+
#include <mrdocs/Dom/LazyObject.hpp>
21+
#include <mrdocs/Dom/String.hpp>
22+
#include <mrdocs/Metadata/SymbolID.hpp>
23+
#include <mrdocs/Platform.hpp>
24+
#include <mrdocs/Support/Concepts.hpp>
25+
#include <mrdocs/Support/Visitor.hpp>
2526
#include <string>
2627
#include <type_traits>
2728
#include <utility>

include/mrdocs/Support/Error.hpp

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@
1212
#ifndef MRDOCS_API_SUPPORT_ERROR_HPP
1313
#define MRDOCS_API_SUPPORT_ERROR_HPP
1414

15-
#include <mrdocs/Platform.hpp>
16-
#include <mrdocs/Support/source_location.hpp>
17-
#include <fmt/format.h>
1815
#include <exception>
16+
#include <format>
17+
#include <functional>
1918
#include <memory>
19+
#include <mrdocs/Platform.hpp>
20+
#include <mrdocs/Support/source_location.hpp>
2021
#include <string>
2122
#include <string_view>
23+
#include <system_error>
2224
#include <type_traits>
2325
#include <utility>
2426
#include <vector>
25-
#include <functional>
2627

2728
namespace clang::mrdocs {
2829

@@ -256,28 +257,20 @@ struct std::hash<::clang::mrdocs::Error>
256257
}
257258
};
258259

259-
template<>
260-
struct fmt::formatter<clang::mrdocs::Error>
261-
: fmt::formatter<std::string_view>
262-
{
263-
auto format(
264-
clang::mrdocs::Error const& err,
265-
fmt::format_context& ctx) const
266-
{
267-
return fmt::formatter<std::string_view>::format(err.message(), ctx);
268-
}
260+
template <>
261+
struct std::formatter<clang::mrdocs::Error> : std::formatter<std::string_view> {
262+
template <class FmtContext>
263+
auto format(clang::mrdocs::Error const &err, FmtContext &ctx) const {
264+
return std::formatter<std::string_view>::format(err.message(), ctx);
265+
}
269266
};
270267

271-
template<>
272-
struct fmt::formatter<std::error_code>
273-
: fmt::formatter<std::string_view>
274-
{
275-
auto format(
276-
std::error_code const& ec,
277-
fmt::format_context& ctx) const
278-
{
279-
return fmt::formatter<std::string_view>::format(ec.message(), ctx);
280-
}
268+
template <>
269+
struct std::formatter<std::error_code> : std::formatter<std::string_view> {
270+
template <class FmtContext>
271+
auto format(std::error_code const &ec, FmtContext &ctx) const {
272+
return std::formatter<std::string_view>::format(ec.message(), ctx);
273+
}
281274
};
282275

283276
namespace clang::mrdocs {
@@ -353,9 +346,8 @@ formatError(
353346
Args&&... args)
354347
{
355348
std::string s;
356-
fmt::vformat_to(
357-
std::back_inserter(s),
358-
fs.fs, fmt::make_format_args(args...));
349+
std::vformat_to(std::back_inserter(s), fs.fs,
350+
std::make_format_args(args...));
359351
return Error(std::move(s), fs.loc);
360352
}
361353

include/mrdocs/Support/Expected.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@
1212
#ifndef MRDOCS_API_SUPPORT_EXPECTED_HPP
1313
#define MRDOCS_API_SUPPORT_EXPECTED_HPP
1414

15-
#include <mrdocs/Platform.hpp>
16-
#include <mrdocs/Support/source_location.hpp>
17-
#include <mrdocs/Support/Error.hpp>
18-
#include <fmt/format.h>
1915
#include <exception>
16+
#include <functional>
2017
#include <iterator>
2118
#include <memory>
19+
#include <mrdocs/Platform.hpp>
20+
#include <mrdocs/Support/Error.hpp>
21+
#include <mrdocs/Support/source_location.hpp>
2222
#include <string>
2323
#include <string_view>
2424
#include <type_traits>
2525
#include <utility>
2626
#include <vector>
27-
#include <functional>
2827

2928
namespace clang::mrdocs {
3029

0 commit comments

Comments
 (0)