Skip to content

Commit fc433f9

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 521cc70 commit fc433f9

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

+523
-669
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ jobs:
3030
uses: actions/checkout@v4
3131

3232
- name: Generate Test Matrix
33-
uses: alandefreitas/cpp-actions/[email protected].8
33+
uses: alandefreitas/cpp-actions/[email protected].10
3434
id: cpp-matrix
3535
with:
3636
compilers: |
3737
gcc 14
38-
clang 18
38+
clang 20
3939
msvc >=14.40
40-
apple-clang *
41-
standards: '20'
40+
apple-clang 17
41+
standards: '23'
4242
latest-factors: |
4343
msvc Optimized-Debug
4444
gcc Coverage
@@ -60,7 +60,7 @@ jobs:
6060
install: |
6161
gcc: git build-essential pkg-config python3 curl openjdk-11-jdk pkg-config libncurses-dev libxml2-utils libxml2-dev
6262
gcc Coverage: git build-essential pkg-config python3 curl openjdk-11-jdk pkg-config libncurses-dev libxml2-utils libxml2-dev lcov
63-
clang: git build-essential pkg-config python3 curl openjdk-11-jdk pkg-config libncurses-dev libxml2-utils libxml2-dev
63+
clang: git build-essential pkg-config python3 curl openjdk-11-jdk pkg-config libncurses-dev libxml2-utils libxml2-dev g++-14=14.2.0-4ubuntu2~24.04
6464
msvc: ''
6565
extra-values: |
6666
llvm-hash: dd7a3d4d798e30dfe53b5bbbbcd9a23c24ea1af9
@@ -125,7 +125,7 @@ jobs:
125125

126126
steps:
127127
- name: Install Git
128-
uses: alandefreitas/cpp-actions/[email protected].8
128+
uses: alandefreitas/cpp-actions/[email protected].10
129129
if: matrix.container != ''
130130
env:
131131
DEBIAN_FRONTEND: 'noninteractive'
@@ -141,7 +141,7 @@ jobs:
141141
uses: actions/checkout@v4
142142

143143
- name: Install Git
144-
uses: alandefreitas/cpp-actions/[email protected].8
144+
uses: alandefreitas/cpp-actions/[email protected].10
145145
if: matrix.container != ''
146146
env:
147147
DEBIAN_FRONTEND: 'noninteractive'
@@ -162,7 +162,7 @@ jobs:
162162
uses: seanmiddleditch/gha-setup-ninja@v5
163163

164164
- name: Setup C++
165-
uses: alandefreitas/cpp-actions/[email protected].8
165+
uses: alandefreitas/cpp-actions/[email protected].10
166166
id: setup-cpp
167167
with:
168168
compiler: ${{ matrix.compiler }}
@@ -178,7 +178,7 @@ jobs:
178178
${{ steps.setup-cpp.outputs.cxx }} --print-target-triple
179179
180180
- name: Install System Packages
181-
uses: alandefreitas/cpp-actions/[email protected].8
181+
uses: alandefreitas/cpp-actions/[email protected].10
182182
if: matrix.compiler != 'msvc'
183183
id: package-install
184184
env:
@@ -238,7 +238,7 @@ jobs:
238238
fi
239239
240240
- name: Install LLVM
241-
uses: alandefreitas/cpp-actions/[email protected].8
241+
uses: alandefreitas/cpp-actions/[email protected].10
242242
if: steps.llvm-cache.outputs.cache-hit != 'true' && steps.llvm-download.outputs.found != 'true'
243243
with:
244244
cmake-version: '>=3.26'
@@ -263,7 +263,7 @@ jobs:
263263
trace-commands: true
264264

265265
- name: Install Duktape
266-
uses: alandefreitas/cpp-actions/[email protected].8
266+
uses: alandefreitas/cpp-actions/[email protected].10
267267
with:
268268
source-dir: ../third-party/duktape
269269
url: https://github.com/svaarala/duktape/releases/download/v2.7.0/duktape-2.7.0.tar.xz
@@ -282,28 +282,8 @@ 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
306-
uses: alandefreitas/cpp-actions/[email protected].8
286+
uses: alandefreitas/cpp-actions/[email protected].10
307287
if: matrix.compiler == 'msvc'
308288
with:
309289
source-dir: ../third-party/libxml2
@@ -360,7 +340,7 @@ jobs:
360340
node-version: '20'
361341

362342
- name: CMake Workflow
363-
uses: alandefreitas/cpp-actions/[email protected].8
343+
uses: alandefreitas/cpp-actions/[email protected].10
364344
with:
365345
cmake-version: '>=3.26'
366346
cxxstd: ${{ matrix.cxxstd }}
@@ -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
@@ -409,7 +388,7 @@ jobs:
409388
retention-days: 1
410389

411390
- name: FlameGraph
412-
uses: alandefreitas/cpp-actions/[email protected].8
391+
uses: alandefreitas/cpp-actions/[email protected].10
413392
if: matrix.time-trace
414393
with:
415394
build-dir: build
@@ -479,7 +458,7 @@ jobs:
479458

480459
steps:
481460
- name: Install packages
482-
uses: alandefreitas/cpp-actions/[email protected].8
461+
uses: alandefreitas/cpp-actions/[email protected].10
483462
id: package-install
484463
with:
485464
apt-get: build-essential asciidoctor cmake bzip2 git
@@ -538,7 +517,7 @@ jobs:
538517
$MRDOCS_ROOT/bin/mrdocs --version
539518
540519
- name: Clone Boost.URL
541-
uses: alandefreitas/cpp-actions/[email protected].8
520+
uses: alandefreitas/cpp-actions/[email protected].10
542521
id: boost-url-clone
543522
with:
544523
branch: develop
@@ -803,7 +782,7 @@ jobs:
803782
scp -o StrictHostKeyChecking=no -r $(pwd)/demos/* [email protected]:$demo_dir/
804783
805784
- name: Create changelog
806-
uses: alandefreitas/cpp-actions/[email protected].8
785+
uses: alandefreitas/cpp-actions/[email protected].10
807786
with:
808787
output-path: CHANGELOG.md
809788
thank-non-regular: ${{ startsWith(github.ref, 'refs/tags/') }}
@@ -845,7 +824,7 @@ jobs:
845824

846825
steps:
847826
- name: Install packages
848-
uses: alandefreitas/cpp-actions/[email protected].8
827+
uses: alandefreitas/cpp-actions/[email protected].10
849828
id: package-install
850829
with:
851830
apt-get: ${{ matrix.install }}

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
@@ -70,27 +70,9 @@ These instructions assume all dependencies are installed in the `third-party` di
7070
Feel free to install them anywhere you want and adjust the main MrDocs configuration command later.
7171
====
7272
73-
[#install-fmt]
73+
[#install-vcpkg]
7474
=== Fmt
7575
76-
MrDocs uses the `fmt` library for formatting strings.
77-
From the `third-party` directory, you can clone the `fmt` repository and install it with the following commands:
78-
79-
[source,bash]
80-
----
81-
git clone https://github.com/fmtlib/fmt --branch 10.2.1 --depth 1 <.>
82-
cd fmt
83-
cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Release -D FMT_DOC=OFF -D FMT_TEST=OFF <.>
84-
cmake --build ./build --config Release <.>
85-
cmake --install ./build --prefix ./install <.>
86-
cd ..
87-
----
88-
89-
<.> Shallow clones the fmt repository.
90-
<.> Configure the fmt library with CMake, excluding the documentation and tests.
91-
<.> Builds the fmt library in the `build` directory.
92-
<.> Installs the fmt library in the `install` directory.
93-
9476
[IMPORTANT]
9577
====
9678
All instructions in this document assume you are using a CMake version above 3.26.
@@ -111,12 +93,10 @@ Windows PowerShell::
11193
git clone https://github.com/microsoft/vcpkg.git -b master <.>
11294
cd vcpkg
11395
bootstrap-vcpkg.bat <.>
114-
vcpkg.exe install fmt --triplet x64-windows <.>
11596
----
11697
11798
<.> Clones the Vcpkg repository.
11899
<.> Bootstraps Vcpkg.
119-
<.> Installs the `fmt` library.
120100
--
121101
122102
Unix Variants::
@@ -127,18 +107,16 @@ Unix Variants::
127107
git clone https://github.com/microsoft/vcpkg.git -b master <.>
128108
cd vcpkg
129109
./bootstrap-vcpkg.sh <.>
130-
./vcpkg install fmt <.>
131110
----
132111
133112
<.> Clones the Vcpkg repository.
134113
<.> Bootstraps Vcpkg.
135-
<.> Installs the `fmt` library.
136114
--
137115
====
138116
139117
[NOTE]
140118
====
141-
You can also install `fmt` with Vcpkg in _Manifest mode_.
119+
You can also install the dependencies with Vcpkg in _Manifest mode_.
142120
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`.
143121
MrDocs includes a `vcpkg.json.example` file you can duplicate or create a symlink as `vcpkg.json` to use this mode.
144122
This file includes all the dependencies MrDocs needs, except for LLVM.
@@ -278,7 +256,7 @@ cd vcpkg
278256
--
279257
====
280258

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

283261
=== Libxml2
284262

@@ -332,7 +310,7 @@ cd vcpkg
332310
--
333311
====
334312

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

337315
=== LLVM
338316

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

0 commit comments

Comments
 (0)