Skip to content

feat: add compat.tomlplusplus 3.4.0 (C++ toml parse library)#64

Open
yspbwx2010 wants to merge 2 commits into
mcpplibs:mainfrom
yspbwx2010:main
Open

feat: add compat.tomlplusplus 3.4.0 (C++ toml parse library)#64
yspbwx2010 wants to merge 2 commits into
mcpplibs:mainfrom
yspbwx2010:main

Conversation

@yspbwx2010

@yspbwx2010 yspbwx2010 commented Jul 7, 2026

Copy link
Copy Markdown

添加 toml++ —— C++17 的 TOML 解析/序列化库,以 C++23
模块形式提供,可直接 import tomlplusplus;

信息

为什么用 fork

上游官方模块单元 src/modules/tomlplusplus.cppm 只在 master 分支,未进入 v3.4.0 release。fork 在
v3.4.0-mcpp tag 里打包了它 + mcpp.toml + 测试,未改动上游代码。

用法

mcpp add compat.tomlplusplus@3.4.0
import tomlplusplus;
auto config = toml::parse("port = 8080");

说明

  • 暂无 CN 镜像CN URL 暂时指向与 GLOBAL 相同的 GitHub release,后续可由维护者补 GitCode 镜像。
  • 已用 mcpp 0.0.83 本地验证:build + run 通过

Add toml++ as a C++23 module package (import tomlplusplus).

- Add pkgs/c/compat.tomlplusplus.lua (module wrapper, MIT)
- Add tests/examples/tomlplusplus with import-based test
- Declares modules = { "tomlplusplus" } for import support
- Uses fork's src/modules/tomlplusplus.cppm as source
- SHA256: cefd81c09ae8eade62f254ba0903e4585944cc86e84c320a92116a95cb725862

toml++ is a TOML v1.0.0 config file parser and serializer for C++17+.
Fork: https://github.com/yspbwx2010/tomlplusplus @ v3.4.0-mcpp
mcpp 0.0.81 (CI version) requires package.version field.
Successfully tested with mcpp 0.0.81:
- Build: ✓ Downloaded compat.tomlplusplus v3.4.0 from GitHub
- Compile: ✓ C++23 module + test binary (5.78s)
- Run: ✓ Output 'toml++ test: OK'
Comment thread pkgs/c/compat.tomlplusplus.lua
package = {
spec = "1",
namespace = "compat",
name = "compat.tomlplusplus",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    namespace   = "marzer",
    name             = "tomlplusplus",

@Sunrisepeak

Sunrisepeak commented Jul 7, 2026

Copy link
Copy Markdown
Member

cppm 只在master分支可以参考 这个 json库的做法

generated_files = {
["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",
},

可以使用 [[ ]] 多行字符串 直接包含

        generated_files = {
            ["mcpp_generated/nlohmann.json.cppm"] = [[
// L1
// L2
// ....
            ]],
        },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants