Skip to content

Commit 2b52d3b

Browse files
committed
refactor(pkgs): nlohmann.json + compat.eigen generated_files -> Lua long brackets (P3)
Mechanical migration of the escaped single-line generated_files strings to [==[ ... ]==] long-bracket form (mcpp >= 0.0.85; the P1 floor gates this). Reviewability is the point: module wrapper sources become readable multi-line code instead of multi-KB one-liners. Verified: parity oracle — `mcpp xpkg parse --json` generated_contents byte-identical before/after for both; lua5.4 loadfile green (xim side still executes these); nlohmann.json and eigen member tests pass.
1 parent 277c0ac commit 2b52d3b

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

pkgs/c/compat.eigen.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ package = {
108108
include_dirs = { "*" },
109109
-- Header-only: a trivial anchor TU gives mcpp a buildable lib target.
110110
generated_files = {
111-
["mcpp_generated/eigen_anchor.c"] = "int mcpp_compat_eigen_headers_anchor(void) { return 0; }\n",
111+
["mcpp_generated/eigen_anchor.c"] = [==[
112+
int mcpp_compat_eigen_headers_anchor(void) { return 0; }
113+
]==],
112114
},
113115
sources = { "mcpp_generated/eigen_anchor.c" },
114116
targets = { ["eigen"] = { kind = "lib" } },

pkgs/n/nlohmann.json.lua

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,52 @@ package = {
6666
-- Upstream's official module unit (develop @ src/modules/json.cppm),
6767
-- reproduced verbatim. Verdir-relative path, no glob.
6868
generated_files = {
69-
["mcpp_generated/nlohmann.json.cppm"] = "module;\n\n// GCC workaround for C++ modules support.\n// When using C++20 modules, some compilers (particularly GCC) may have issues\n// with template instantiations in the module preamble. If you encounter\n// \"redefinition\" errors when including nlohmann/json.hpp, try one of:\n// 1. Include nlohmann/json.hpp in your module preamble BEFORE other #includes\n// 2. Or use: import nlohmann.json; instead of #include <nlohmann/json.hpp>\n// 3. Or upgrade to a newer GCC version with better modules support.\n// See: https://github.com/nlohmann/json/issues/5103\n\n#include <nlohmann/json.hpp>\n\nexport module nlohmann.json;\n\nexport\nNLOHMANN_JSON_NAMESPACE_BEGIN\n\nusing NLOHMANN_JSON_NAMESPACE::adl_serializer;\nusing NLOHMANN_JSON_NAMESPACE::basic_json;\nusing NLOHMANN_JSON_NAMESPACE::json;\nusing NLOHMANN_JSON_NAMESPACE::json_pointer;\nusing NLOHMANN_JSON_NAMESPACE::ordered_json;\nusing NLOHMANN_JSON_NAMESPACE::ordered_map;\nusing NLOHMANN_JSON_NAMESPACE::to_string;\n\ninline namespace literals\n{\ninline namespace json_literals\n{\n using NLOHMANN_JSON_NAMESPACE::literals::json_literals::operator\"\"_json;\n using NLOHMANN_JSON_NAMESPACE::literals::json_literals::operator\"\"_json_pointer;\n} // namespace json_literals\n} // namespace literals\n\n// Note: the following nlohmann::detail symbols must be exported due to\n// an MSVC bug failing to compile without these symbols visible (ticket #3970)\nnamespace detail\n{\n using NLOHMANN_JSON_NAMESPACE::detail::json_sax_dom_callback_parser;\n using NLOHMANN_JSON_NAMESPACE::detail::unknown_size;\n} // namespace detail\n\nNLOHMANN_JSON_NAMESPACE_END\n",
69+
["mcpp_generated/nlohmann.json.cppm"] = [==[
70+
module;
71+
72+
// GCC workaround for C++ modules support.
73+
// When using C++20 modules, some compilers (particularly GCC) may have issues
74+
// with template instantiations in the module preamble. If you encounter
75+
// "redefinition" errors when including nlohmann/json.hpp, try one of:
76+
// 1. Include nlohmann/json.hpp in your module preamble BEFORE other #includes
77+
// 2. Or use: import nlohmann.json; instead of #include <nlohmann/json.hpp>
78+
// 3. Or upgrade to a newer GCC version with better modules support.
79+
// See: https://github.com/nlohmann/json/issues/5103
80+
81+
#include <nlohmann/json.hpp>
82+
83+
export module nlohmann.json;
84+
85+
export
86+
NLOHMANN_JSON_NAMESPACE_BEGIN
87+
88+
using NLOHMANN_JSON_NAMESPACE::adl_serializer;
89+
using NLOHMANN_JSON_NAMESPACE::basic_json;
90+
using NLOHMANN_JSON_NAMESPACE::json;
91+
using NLOHMANN_JSON_NAMESPACE::json_pointer;
92+
using NLOHMANN_JSON_NAMESPACE::ordered_json;
93+
using NLOHMANN_JSON_NAMESPACE::ordered_map;
94+
using NLOHMANN_JSON_NAMESPACE::to_string;
95+
96+
inline namespace literals
97+
{
98+
inline namespace json_literals
99+
{
100+
using NLOHMANN_JSON_NAMESPACE::literals::json_literals::operator""_json;
101+
using NLOHMANN_JSON_NAMESPACE::literals::json_literals::operator""_json_pointer;
102+
} // namespace json_literals
103+
} // namespace literals
104+
105+
// Note: the following nlohmann::detail symbols must be exported due to
106+
// an MSVC bug failing to compile without these symbols visible (ticket #3970)
107+
namespace detail
108+
{
109+
using NLOHMANN_JSON_NAMESPACE::detail::json_sax_dom_callback_parser;
110+
using NLOHMANN_JSON_NAMESPACE::detail::unknown_size;
111+
} // namespace detail
112+
113+
NLOHMANN_JSON_NAMESPACE_END
114+
]==],
70115
},
71116
sources = { "mcpp_generated/nlohmann.json.cppm" },
72117
targets = { ["nlohmann_json"] = { kind = "lib" } },

0 commit comments

Comments
 (0)