Skip to content

Commit 428b63d

Browse files
authored
feat(compat): add pugixml 1.16 (#924)
1 parent ea6ebdc commit 428b63d

5 files changed

Lines changed: 128 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Add `compat.pugixml` (`zeux/pugixml` v1.16)
2+
3+
## Summary
4+
5+
Add `compat.pugixml` (`pkgs/c/compat.pugixml.lua`) wrapping `zeux/pugixml` release `1.16` (MIT license) off `upstream/main`.
6+
7+
## Package Architecture
8+
9+
- **Upstream Archive**:
10+
- Uses stable GitHub tag release archive `https://github.com/zeux/pugixml/archive/refs/tags/v1.16.tar.gz` across `linux`, `macosx`, and `windows` (plain string URL; CN mirrors can be added later).
11+
- SHA256 verified twice for stability: `357bcab8877dc9943f355d3a72daba1b053238ba955f50fa81586afb65090219`.
12+
- **Source Build**:
13+
- `include_dirs = { "*/src" }`, `sources = { "*/src/pugixml.cpp" }`, `license_files = { "*/LICENSE.md" }`, `targets = { ["pugixml"] = { kind = "lib" } }`.
14+
- **Automatic Updates**:
15+
- `extensions.autoupdate` tracks `zeux/pugixml` with `tag = "v${version}"`.
16+
17+
## Workspace Test Member
18+
19+
- `tests/examples/pugixml`: asserts `PUGIXML_VERSION == 1160`, DOM traversal, XPath query (`/catalog/book[@id='2']/title`), node mutation + serialization, and malformed XML rejection.

‎mcpp.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ members = [
324324
"tests/examples/pdfium",
325325
"tests/examples/utf8proc",
326326
"tests/examples/zxing-cpp",
327+
"tests/examples/pugixml",
327328
]
328329

329330
# ── The index each member tests through ─────────────────────────────────

‎pkgs/c/compat.pugixml.lua‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
local versions = {
2+
["1.16"] = {
3+
url = "https://github.com/zeux/pugixml/archive/refs/tags/v1.16.tar.gz",
4+
sha256 = "357bcab8877dc9943f355d3a72daba1b053238ba955f50fa81586afb65090219",
5+
},
6+
}
7+
8+
-- compat.pugixml — Light-weight, simple and fast XML parser for C++ with XPath support.
9+
-- Static C++ source build: compiles src/pugixml.cpp and exposes src/ (`<pugixml.hpp>`,
10+
-- `<pugiconfig.hpp>`).
11+
--
12+
-- All `mcpp` paths are GLOBS relative to the verdir; the leading `*/`
13+
-- absorbs the GitHub tarball's `pugixml-<ver>/` wrap layer.
14+
-- Plain upstream URLs are used here because no local gitcode `mcpp-res`
15+
-- credentials are available; CN mirrors can be added by maintainers later.
16+
package = {
17+
spec = "1",
18+
namespace = "compat",
19+
name = "pugixml",
20+
description = "Light-weight, simple and fast XML parser for C++ with XPath support",
21+
licenses = {"MIT"},
22+
repo = "https://github.com/zeux/pugixml",
23+
type = "package",
24+
25+
extensions = {
26+
autoupdate = {
27+
tag = "v${version}",
28+
url = "https://github.com/zeux/pugixml/archive/refs/tags/${tag}.tar.gz",
29+
},
30+
},
31+
32+
xpm = {
33+
linux = { ["1.16"] = versions["1.16"] },
34+
macosx = { ["1.16"] = versions["1.16"] },
35+
windows = { ["1.16"] = versions["1.16"] },
36+
},
37+
38+
mcpp = {
39+
language = "c++23",
40+
import_std = false,
41+
license_files = { "*/LICENSE.md" },
42+
include_dirs = { "*/src" },
43+
sources = { "*/src/pugixml.cpp" },
44+
targets = { ["pugixml"] = { kind = "lib" } },
45+
deps = {},
46+
},
47+
}

‎tests/examples/pugixml/mcpp.toml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "pugixml-tests"
3+
version = "0.1.0"
4+
5+
[dependencies.compat]
6+
pugixml = "1.16"
7+
8+
[indices]
9+
compat = { path = "../../.." }
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <cstdio>
2+
#include <sstream>
3+
#include <string>
4+
5+
#include <pugixml.hpp>
6+
7+
static_assert(PUGIXML_VERSION == 1160, "expected pugixml 1.16 headers");
8+
9+
int main() {
10+
bool ok = true;
11+
12+
const char *xml = R"(<?xml version="1.0" encoding="UTF-8"?>
13+
<catalog>
14+
<book id="1" price="19.99"><title>Alpha</title></book>
15+
<book id="2" price="29.50"><title>Beta</title></book>
16+
</catalog>)";
17+
18+
pugi::xml_document doc;
19+
pugi::xml_parse_result res = doc.load_string(xml);
20+
if (!res) {
21+
std::fprintf(stderr, "pugixml load_string failed: %s\n", res.description());
22+
return 1;
23+
}
24+
25+
// DOM traversal and typed attributes
26+
pugi::xml_node catalog = doc.child("catalog");
27+
ok = ok && catalog;
28+
pugi::xml_node first = catalog.child("book");
29+
ok = ok && first.attribute("id").as_int() == 1;
30+
ok = ok && std::string(first.child_value("title")) == "Alpha";
31+
32+
// XPath query
33+
pugi::xpath_node match = doc.select_node("/catalog/book[@id='2']/title");
34+
ok = ok && match && std::string(match.node().child_value()) == "Beta";
35+
36+
// Mutation and serialization
37+
pugi::xml_node added = catalog.append_child("book");
38+
added.append_attribute("id") = 3;
39+
added.append_child("title").text().set("Gamma");
40+
41+
std::ostringstream oss;
42+
doc.save(oss, " ", pugi::format_raw);
43+
const std::string out = oss.str();
44+
ok = ok && out.find("<book id=\"3\"><title>Gamma</title></book>") != std::string::npos;
45+
46+
// Malformed XML rejection
47+
pugi::xml_document bad;
48+
pugi::xml_parse_result bad_res = bad.load_string("<unclosed>");
49+
ok = ok && !bad_res && bad_res.status != pugi::status_ok;
50+
51+
return ok ? 0 : 1;
52+
}

0 commit comments

Comments
 (0)