Skip to content

Commit b440eaa

Browse files
authored
feat(compat): add compat.oniguruma 6.9.10 (#917)
1 parent a4ade86 commit b440eaa

5 files changed

Lines changed: 276 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.oniguruma` (`6.9.10`)
2+
3+
## Summary
4+
5+
Add `compat.oniguruma` (`pkgs/c/compat.oniguruma.lua`) at upstream tag `v6.9.10` (`https://github.com/kkos/oniguruma`), required as a transitive dependency by `compat.sweetline` (`Lib-RichEditor`).
6+
7+
## Package Shape
8+
9+
- **Form B pure-C static library**:
10+
- Compiles Oniguruma core engine (`regcomp.c`, `regexec.c`, `regparse.c`, etc.) and built-in character encodings (`utf8.c`, `utf16_*`, `utf32_*`, `ascii.c`, `iso8859_*`, `sjis.c`, `euc_*`, `gb18030.c`, `big5.c`, etc.) matching upstream `CMakeLists.txt` `_SRCS`.
11+
- Exposes `*/src` (`<oniguruma.h>`, `<oniggnu.h>`) and keeps generated `mcpp_generated/config/config.h` private via `private_include_dirs` to prevent `config.h` header collisions in downstream consumers.
12+
- Propagates `ONIG_STATIC` via `default -> staticlib`, and keeps legacy GNU regex compat `src/reggnu.c` (`re_compile_pattern`, `re_match`, `re_search`) opt-in behind `gnu-api` to avoid colliding with glibc `libc.so.6`.
13+
- **License**: `BSD-2-Clause` (`COPYING`), SHA256 verified twice: `ad92309d0d13eebc27f6592e875f3efbfa3dda2bf6da5952e00f0a2120c921a8`.
14+
15+
## Verification
16+
17+
- `mcpp xpkg parse pkgs/c/compat.oniguruma.lua`: `parse OK` (47 default sources, 3 features: `default`, `staticlib`, `gnu-api`).
18+
- All CI Lua lints (`check_capability_providers.lua`, `check_mirror_urls.lua`, `check_package_name.lua`, `check_reserved_namespace.lua`, `check_mplugin_layout.lua`, `check_cross_package_refs.lua`, `check_platform_version_parity.lua`, `check_duplicate_versions.lua`, `check_quill_install.lua`) and Python tests (`test_check_mplugin.py` 12, `test_check_installed_template.py` 4, `test_check_capability_providers.py` 8, `test_select_members.py` 9, `test_plan_matrix_shards.py` 3): OK.
19+
- `bash tests/run_members.sh oniguruma --cache local` (clean rebuild after cold home bootstrap): `1.71s` (`1 passed; 0 failed`), zero duplicate symbol warnings.

‎mcpp.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ members = [
318318
"tests/examples/openlifa.openas",
319319
"tests/examples/openlifa.openmui",
320320
"tests/examples/os",
321+
"tests/examples/oniguruma",
321322
"tests/examples/pdfium",
322323
"tests/examples/utf8proc",
323324
"tests/examples/zxing-cpp",

‎pkgs/c/compat.oniguruma.lua‎

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
local versions = {
2+
["6.9.10"] = {
3+
url = "https://github.com/kkos/oniguruma/archive/refs/tags/v6.9.10.tar.gz",
4+
sha256 = "ad92309d0d13eebc27f6592e875f3efbfa3dda2bf6da5952e00f0a2120c921a8",
5+
},
6+
}
7+
8+
-- compat.oniguruma — Oniguruma 6.9.10 regular expression C library (BSD-2-Clause).
9+
--
10+
-- Form B source-built package compiling the core engine and built-in character encodings.
11+
-- Generated `mcpp_generated/config/config.h` stays strictly private via `private_include_dirs`
12+
-- so `config.h` never collides with downstream consumers; consumers receive `*/src`
13+
-- (`<oniguruma.h>`, `<oniggnu.h>`) and `-DONIG_STATIC` via `default -> staticlib`.
14+
-- `src/reggnu.c` (`re_compile_pattern`, `re_match`, `re_search`) is opt-in via the
15+
-- `gnu-api` feature because its legacy GNU regex symbols collide with glibc's `libc.so.6`.
16+
package = {
17+
spec = "1",
18+
namespace = "compat",
19+
name = "oniguruma",
20+
description = "Regular expression C library supporting multiple character encodings",
21+
licenses = { "BSD-2-Clause" },
22+
repo = "https://github.com/kkos/oniguruma",
23+
type = "package",
24+
25+
extensions = {
26+
autoupdate = {
27+
tag = "v${version}",
28+
url = "https://github.com/kkos/oniguruma/archive/refs/tags/${tag}.tar.gz",
29+
},
30+
},
31+
32+
xpm = {
33+
linux = { ["6.9.10"] = versions["6.9.10"] },
34+
macosx = { ["6.9.10"] = versions["6.9.10"] },
35+
windows = { ["6.9.10"] = versions["6.9.10"] },
36+
},
37+
38+
mcpp = {
39+
language = "c++23",
40+
import_std = false,
41+
c_standard = "c11",
42+
license_files = { "*/COPYING" },
43+
include_dirs = { "*/src" },
44+
45+
cflags = { "-DHAVE_CONFIG_H", "-DONIG_STATIC" },
46+
47+
generated_files = {
48+
["mcpp_generated/config/config.h"] = [==[
49+
#ifndef ONIGURUMA_CONFIG_H_MCPP_GUARD
50+
#define ONIGURUMA_CONFIG_H_MCPP_GUARD
51+
52+
#define PACKAGE "onig"
53+
#define PACKAGE_VERSION "6.9.10"
54+
#define VERSION "6.9.10"
55+
#define USE_CRNL_AS_LINE_TERMINATOR 0
56+
57+
#define HAVE_ALLOCA 1
58+
#define HAVE_STDINT_H 1
59+
#define HAVE_INTTYPES_H 1
60+
#define HAVE_SYS_TYPES_H 1
61+
62+
#if !defined(_WIN32)
63+
#define HAVE_ALLOCA_H 1
64+
#define HAVE_SYS_TIMES_H 1
65+
#define HAVE_SYS_TIME_H 1
66+
#define HAVE_UNISTD_H 1
67+
#else
68+
#define HAVE_FCNTL_H 1
69+
#define HAVE_SYS_STAT_H 1
70+
#define HAVE_SYS_UTIME_H 1
71+
#endif
72+
73+
#define SIZEOF_INT 4
74+
#define SIZEOF_LONG_LONG 8
75+
#if defined(_WIN32)
76+
#define SIZEOF_LONG 4
77+
#else
78+
#if defined(__LP64__)
79+
#define SIZEOF_LONG 8
80+
#else
81+
#define SIZEOF_LONG 4
82+
#endif
83+
#endif
84+
85+
#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(__aarch64__)
86+
#define SIZEOF_VOIDP 8
87+
#else
88+
#define SIZEOF_VOIDP 4
89+
#endif
90+
91+
#endif
92+
]==],
93+
},
94+
95+
sources = {
96+
"*/src/regerror.c",
97+
"*/src/regparse.c",
98+
"*/src/regext.c",
99+
"*/src/regcomp.c",
100+
"*/src/regexec.c",
101+
"*/src/regenc.c",
102+
"*/src/regsyntax.c",
103+
"*/src/regtrav.c",
104+
"*/src/regversion.c",
105+
"*/src/st.c",
106+
"*/src/onig_init.c",
107+
"*/src/unicode.c",
108+
"*/src/ascii.c",
109+
"*/src/utf8.c",
110+
"*/src/utf16_be.c",
111+
"*/src/utf16_le.c",
112+
"*/src/utf32_be.c",
113+
"*/src/utf32_le.c",
114+
"*/src/euc_jp.c",
115+
"*/src/sjis.c",
116+
"*/src/iso8859_1.c",
117+
"*/src/iso8859_2.c",
118+
"*/src/iso8859_3.c",
119+
"*/src/iso8859_4.c",
120+
"*/src/iso8859_5.c",
121+
"*/src/iso8859_6.c",
122+
"*/src/iso8859_7.c",
123+
"*/src/iso8859_8.c",
124+
"*/src/iso8859_9.c",
125+
"*/src/iso8859_10.c",
126+
"*/src/iso8859_11.c",
127+
"*/src/iso8859_13.c",
128+
"*/src/iso8859_14.c",
129+
"*/src/iso8859_15.c",
130+
"*/src/iso8859_16.c",
131+
"*/src/euc_tw.c",
132+
"*/src/euc_kr.c",
133+
"*/src/big5.c",
134+
"*/src/gb18030.c",
135+
"*/src/koi8_r.c",
136+
"*/src/cp1251.c",
137+
"*/src/euc_jp_prop.c",
138+
"*/src/sjis_prop.c",
139+
"*/src/unicode_unfold_key.c",
140+
"*/src/unicode_fold1_key.c",
141+
"*/src/unicode_fold2_key.c",
142+
"*/src/unicode_fold3_key.c",
143+
},
144+
145+
linux = {
146+
include_dirs = { "mcpp_generated/config" },
147+
private_include_dirs = { "mcpp_generated/config" },
148+
},
149+
macosx = {
150+
include_dirs = { "mcpp_generated/config" },
151+
private_include_dirs = { "mcpp_generated/config" },
152+
},
153+
windows = {
154+
include_dirs = { "mcpp_generated/config" },
155+
private_include_dirs = { "mcpp_generated/config" },
156+
cflags = { "-D_CRT_SECURE_NO_WARNINGS" },
157+
},
158+
159+
targets = { onig = { kind = "lib" } },
160+
161+
features = {
162+
["default"] = { implies = { "staticlib" } },
163+
["staticlib"] = { defines = { "ONIG_STATIC" } },
164+
["gnu-api"] = { sources = { "*/src/reggnu.c" } },
165+
},
166+
167+
deps = {},
168+
},
169+
}

‎tests/examples/oniguruma/mcpp.toml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[indices]
2+
compat = { path = "../../.." }
3+
4+
[package]
5+
name = "oniguruma-tests"
6+
version = "0.1.0"
7+
standard = "c++23"
8+
9+
[dependencies.compat]
10+
oniguruma = "6.9.10"
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include <oniguruma.h>
2+
3+
#include <cstring>
4+
#include <iostream>
5+
#include <string>
6+
#include <string_view>
7+
8+
namespace {
9+
10+
bool Expect(bool ok, const char* msg) {
11+
if (!ok) {
12+
std::cerr << "FAIL: " << msg << "\n";
13+
}
14+
return ok;
15+
}
16+
17+
} // namespace
18+
19+
int main() {
20+
bool ok = true;
21+
22+
const char* ver = onig_version();
23+
std::cout << "oniguruma version: " << (ver ? ver : "(null)") << "\n";
24+
ok &= Expect(ver != nullptr && std::string_view(ver) == "6.9.10", "onig_version is 6.9.10");
25+
26+
OnigEncoding encs[] = {ONIG_ENCODING_UTF8};
27+
if (!Expect(onig_initialize(encs, sizeof(encs) / sizeof(encs[0])) == ONIG_NORMAL, "onig_initialize")) {
28+
return 1;
29+
}
30+
31+
// Negative check: malformed regex pattern fails cleanly.
32+
const std::string bad_pat = "[unclosed";
33+
regex_t* bad_reg = nullptr;
34+
OnigErrorInfo einfo{};
35+
const int bad_r = onig_new(&bad_reg,
36+
reinterpret_cast<const OnigUChar*>(bad_pat.data()),
37+
reinterpret_cast<const OnigUChar*>(bad_pat.data() + bad_pat.size()),
38+
ONIG_OPTION_DEFAULT, ONIG_ENCODING_UTF8, ONIG_SYNTAX_DEFAULT, &einfo);
39+
ok &= Expect(bad_r != ONIG_NORMAL && bad_reg == nullptr, "negative: invalid pattern rejected");
40+
41+
// Positive check: compile UTF-8 pattern and extract capture groups.
42+
const std::string pat = "(hello)-([[:alpha:]]+)";
43+
regex_t* reg = nullptr;
44+
const int rc = onig_new(&reg,
45+
reinterpret_cast<const OnigUChar*>(pat.data()),
46+
reinterpret_cast<const OnigUChar*>(pat.data() + pat.size()),
47+
ONIG_OPTION_DEFAULT, ONIG_ENCODING_UTF8, ONIG_SYNTAX_DEFAULT, &einfo);
48+
ok &= Expect(rc == ONIG_NORMAL && reg != nullptr, "onig_new valid pattern");
49+
50+
if (reg) {
51+
OnigRegion* region = onig_region_new();
52+
const std::string text = "__hello-world__";
53+
const auto* begin = reinterpret_cast<const OnigUChar*>(text.data());
54+
const auto* end = begin + text.size();
55+
const int pos = onig_search(reg, begin, end, begin, end, region, ONIG_OPTION_NONE);
56+
ok &= Expect(pos == 2, "match offset == 2");
57+
ok &= Expect(region->num_regs == 3, "3 capture regions");
58+
if (region->num_regs == 3) {
59+
const std::string cap1(text.substr(region->beg[1], region->end[1] - region->beg[1]));
60+
const std::string cap2(text.substr(region->beg[2], region->end[2] - region->beg[2]));
61+
ok &= Expect(cap1 == "hello" && cap2 == "world", "capture groups match");
62+
}
63+
64+
// Negative check: non-matching string returns ONIG_MISMATCH.
65+
const std::string nomatch = "12345";
66+
const auto* nbegin = reinterpret_cast<const OnigUChar*>(nomatch.data());
67+
const int npos = onig_search(reg, nbegin, nbegin + nomatch.size(),
68+
nbegin, nbegin + nomatch.size(), region, ONIG_OPTION_NONE);
69+
ok &= Expect(npos == ONIG_MISMATCH, "negative: non-matching input returns ONIG_MISMATCH");
70+
71+
onig_region_free(region, 1);
72+
onig_free(reg);
73+
}
74+
75+
onig_end();
76+
return ok ? 0 : 1;
77+
}

0 commit comments

Comments
 (0)