Skip to content

Commit c32f093

Browse files
pyc-copilotclaude
andcommitted
feat: add compat.fmt 12.2.0 (C++ source compat)
fmt is built as a C++-source compat lib (same shape as compat.gtest): compile src/format.cc + src/os.cc into the `fmt` lib and expose include/ for `#include <fmt/format.h>`. src/fmt.cc (C++20 module unit) is excluded; src/fmt-c.cc is source-gated behind an optional `c-api` feature. Verified locally on mcpp 0.0.81 (== CI): `mcpp test -p fmt` builds compat.fmt from source and the behavioral assertions pass. No mcpp-res write access, so the download url is a plain upstream string (CN mirror to be added by a maintainer). Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ac4cbff commit c32f093

4 files changed

Lines changed: 97 additions & 0 deletions

File tree

mcpp.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
"tests/examples/cjson",
1414
"tests/examples/core",
1515
"tests/examples/eigen",
16+
"tests/examples/fmt",
1617
"tests/examples/gui-stack",
1718
"tests/examples/imgui",
1819
"tests/examples/imgui-window",

pkgs/c/compat.fmt.lua

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
-- Form B inline descriptor for {fmt} — a modern formatting library for C++.
2+
-- C++-source compat build (same shape as compat.gtest): compile the library's
3+
-- non-header translation units into a lib and expose the `include/` tree via
4+
-- include_dirs, so consumers write `#include <fmt/core.h>` / `<fmt/format.h>`.
5+
--
6+
-- Sources: fmt's compiled implementation is `src/format.cc` (core formatting)
7+
-- and `src/os.cc` (optional OS-specific I/O — fmt::ostream, file descriptors).
8+
-- These two are exactly upstream CMake's `fmt` target sources. NOT globbed:
9+
-- * `src/fmt.cc` — the C++20 named-module unit (starts with `module;`); it
10+
-- must be compiled as a module interface, not a plain TU,
11+
-- so it is deliberately excluded here.
12+
-- * `src/fmt-c.cc` — the optional C API; gated behind the `c-api` feature
13+
-- below (excluded by default, same pattern as compat.gtest
14+
-- gating gtest_main behind `main`).
15+
--
16+
-- All `mcpp` paths are GLOBS relative to the verdir; the leading `*/` absorbs
17+
-- the GitHub tarball's `fmt-<tag>/` wrap layer.
18+
package = {
19+
spec = "1",
20+
namespace = "compat",
21+
name = "compat.fmt",
22+
description = "A modern formatting library for C++",
23+
licenses = {"MIT"},
24+
repo = "https://github.com/fmtlib/fmt",
25+
type = "package",
26+
27+
xpm = {
28+
linux = {
29+
["12.2.0"] = {
30+
url = "https://github.com/fmtlib/fmt/archive/refs/tags/12.2.0.tar.gz",
31+
sha256 = "8b852bb5aa6e7d8564f9e81394055395dd1d1936d38dfd3a17792a02bebd7af0",
32+
},
33+
},
34+
macosx = {
35+
["12.2.0"] = {
36+
url = "https://github.com/fmtlib/fmt/archive/refs/tags/12.2.0.tar.gz",
37+
sha256 = "8b852bb5aa6e7d8564f9e81394055395dd1d1936d38dfd3a17792a02bebd7af0",
38+
},
39+
},
40+
windows = {
41+
["12.2.0"] = {
42+
url = "https://github.com/fmtlib/fmt/archive/refs/tags/12.2.0.tar.gz",
43+
sha256 = "8b852bb5aa6e7d8564f9e81394055395dd1d1936d38dfd3a17792a02bebd7af0",
44+
},
45+
},
46+
},
47+
48+
mcpp = {
49+
language = "c++23",
50+
import_std = false,
51+
include_dirs = { "*/include" },
52+
sources = { "*/src/format.cc", "*/src/os.cc" },
53+
targets = { ["fmt"] = { kind = "lib" } },
54+
-- Optional C API (src/fmt-c.cc, <fmt/fmt-c.h>), source-gated like
55+
-- compat.gtest's `main` / compat.cjson's `utils`. NOTE: mcpp 0.0.81 does
56+
-- not yet propagate a feature requested on a DEPENDENCY into its compile
57+
-- plan, so this object is not built and fmt_vformat is unresolved even
58+
-- with the feature on — the same gap compat.eigen notes for `eigen_blas`.
59+
-- Kept form-correct; lights up once mcpp propagates dependency features.
60+
features = {
61+
["c-api"] = { sources = { "*/src/fmt-c.cc" } },
62+
},
63+
deps = { },
64+
},
65+
}

tests/examples/fmt/mcpp.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# {fmt} test project: depends on compat.fmt (built from source via this repo's
2+
# own index) and asserts behavior under `mcpp test`. Part of the mcpp-index
3+
# self-referential workspace.
4+
[package]
5+
name = "fmt-tests"
6+
version = "0.1.0"
7+
8+
[indices]
9+
compat = { path = "../../.." }
10+
11+
[dependencies.compat]
12+
fmt = "12.2.0"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Behavioral test: exercise {fmt}'s compiled implementation (src/format.cc via
2+
// the fmt lib target) — not just header inlines — and assert the results.
3+
// Returns non-zero on any mismatch.
4+
#include <fmt/format.h>
5+
#include <cmath>
6+
#include <string>
7+
8+
int main() {
9+
std::string a = fmt::format("{} + {} = {}", 2, 3, 2 + 3);
10+
std::string b = fmt::format("{:08.3f}", 3.14159);
11+
std::string c = fmt::format("{0}-{1}-{0}", "x", "y");
12+
std::string d = fmt::format("{:#x}", 255);
13+
14+
bool ok = a == "2 + 3 = 5"
15+
&& b == "0003.142"
16+
&& c == "x-y-x"
17+
&& d == "0xff";
18+
return ok ? 0 : 1;
19+
}

0 commit comments

Comments
 (0)