diff --git a/mcpp.toml b/mcpp.toml index d4e04ca..1e4a377 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -13,6 +13,7 @@ members = [ "tests/examples/cjson", "tests/examples/core", "tests/examples/eigen", + "tests/examples/fmt", "tests/examples/gui-stack", "tests/examples/imgui", "tests/examples/imgui-window", diff --git a/pkgs/c/compat.fmt.lua b/pkgs/c/compat.fmt.lua new file mode 100644 index 0000000..11cfb4b --- /dev/null +++ b/pkgs/c/compat.fmt.lua @@ -0,0 +1,65 @@ +-- Form B inline descriptor for {fmt} — a modern formatting library for C++. +-- C++-source compat build (same shape as compat.gtest): compile the library's +-- non-header translation units into a lib and expose the `include/` tree via +-- include_dirs, so consumers write `#include ` / ``. +-- +-- Sources: fmt's compiled implementation is `src/format.cc` (core formatting) +-- and `src/os.cc` (optional OS-specific I/O — fmt::ostream, file descriptors). +-- These two are exactly upstream CMake's `fmt` target sources. NOT globbed: +-- * `src/fmt.cc` — the C++20 named-module unit (starts with `module;`); it +-- must be compiled as a module interface, not a plain TU, +-- so it is deliberately excluded here. +-- * `src/fmt-c.cc` — the optional C API; gated behind the `c-api` feature +-- below (excluded by default, same pattern as compat.gtest +-- gating gtest_main behind `main`). +-- +-- All `mcpp` paths are GLOBS relative to the verdir; the leading `*/` absorbs +-- the GitHub tarball's `fmt-/` wrap layer. +package = { + spec = "1", + namespace = "compat", + name = "compat.fmt", + description = "A modern formatting library for C++", + licenses = {"MIT"}, + repo = "https://github.com/fmtlib/fmt", + type = "package", + + xpm = { + linux = { + ["12.2.0"] = { + url = "https://github.com/fmtlib/fmt/archive/refs/tags/12.2.0.tar.gz", + sha256 = "8b852bb5aa6e7d8564f9e81394055395dd1d1936d38dfd3a17792a02bebd7af0", + }, + }, + macosx = { + ["12.2.0"] = { + url = "https://github.com/fmtlib/fmt/archive/refs/tags/12.2.0.tar.gz", + sha256 = "8b852bb5aa6e7d8564f9e81394055395dd1d1936d38dfd3a17792a02bebd7af0", + }, + }, + windows = { + ["12.2.0"] = { + url = "https://github.com/fmtlib/fmt/archive/refs/tags/12.2.0.tar.gz", + sha256 = "8b852bb5aa6e7d8564f9e81394055395dd1d1936d38dfd3a17792a02bebd7af0", + }, + }, + }, + + mcpp = { + language = "c++23", + import_std = false, + include_dirs = { "*/include" }, + sources = { "*/src/format.cc", "*/src/os.cc" }, + targets = { ["fmt"] = { kind = "lib" } }, + -- Optional C API (src/fmt-c.cc, ), source-gated like + -- compat.gtest's `main` / compat.cjson's `utils`. NOTE: mcpp 0.0.81 does + -- not yet propagate a feature requested on a DEPENDENCY into its compile + -- plan, so this object is not built and fmt_vformat is unresolved even + -- with the feature on — the same gap compat.eigen notes for `eigen_blas`. + -- Kept form-correct; lights up once mcpp propagates dependency features. + features = { + ["c-api"] = { sources = { "*/src/fmt-c.cc" } }, + }, + deps = { }, + }, +} diff --git a/tests/examples/fmt/mcpp.toml b/tests/examples/fmt/mcpp.toml new file mode 100644 index 0000000..b4b0184 --- /dev/null +++ b/tests/examples/fmt/mcpp.toml @@ -0,0 +1,12 @@ +# {fmt} test project: depends on compat.fmt (built from source via this repo's +# own index) and asserts behavior under `mcpp test`. Part of the mcpp-index +# self-referential workspace. +[package] +name = "fmt-tests" +version = "0.1.0" + +[indices] +compat = { path = "../../.." } + +[dependencies.compat] +fmt = "12.2.0" diff --git a/tests/examples/fmt/tests/format_test.cpp b/tests/examples/fmt/tests/format_test.cpp new file mode 100644 index 0000000..da7e0eb --- /dev/null +++ b/tests/examples/fmt/tests/format_test.cpp @@ -0,0 +1,19 @@ +// Behavioral test: exercise {fmt}'s compiled implementation (src/format.cc via +// the fmt lib target) — not just header inlines — and assert the results. +// Returns non-zero on any mismatch. +#include +#include +#include + +int main() { + std::string a = fmt::format("{} + {} = {}", 2, 3, 2 + 3); + std::string b = fmt::format("{:08.3f}", 3.14159); + std::string c = fmt::format("{0}-{1}-{0}", "x", "y"); + std::string d = fmt::format("{:#x}", 255); + + bool ok = a == "2 + 3 = 5" + && b == "0003.142" + && c == "x-y-x" + && d == "0xff"; + return ok ? 0 : 1; +}