Skip to content

Commit bd276ab

Browse files
authored
mcpplibs.mwrap.wuffs 0.3.6: wuffs-m (Wuffs as C++23 modules) (#857)
* mcpplibs.mwrap.wuffs: the consumer member wuffs-decode, the installed-template notice row and its validate step * mcpplibs.mwrap.wuffs 0.3.6: the descriptor (wuffs-m mwrap-0.3.6, GLOBAL and CN), the changelog and the record
1 parent f219551 commit bd276ab

9 files changed

Lines changed: 204 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Plan and record: mcpplibs.mwrap.wuffs 0.3.6 (compat.wuffs + wuffs-m)
2+
3+
Status: done, 2026-11-20.
4+
5+
## Shape
6+
7+
- `compat.wuffs` 0.3.6 (mcpp-index#855): the tag archive (upstream publishes no release assets); one generated
8+
translation unit compiles `release/c/wuffs-v0.3.c` under `WUFFS_IMPLEMENTATION` **as C++**, so the C API (in
9+
`extern "C"`) and `wuffs_aux` (defined only for C++) are one library. Every package built. CN: `mcpp-res/wuffs`.
10+
- `wuffs-m` (`mcpplibs.mwrap.wuffs` 0.3.6): one module per upstream package (`base` and 15 others), `.aux`
11+
(`wuffs_aux`), `.macros`, a root re-exporting all; generated by `tools/gen_exports.py` from
12+
`clang++ -Xclang -ast-dump=json -Xclang -ast-dump-filter=wuffs` (every Wuffs name contains "wuffs"), audited by
13+
`tools/check_exports.py`. CN: `mcpp-res/mwrap-wuffs`.
14+
15+
## Measured surface
16+
17+
429 globals exported; 315 `static inline` functions adapted in `mcpplibs::mwrap::wuffs` (sdl3-m's pattern; defined
18+
non-inline in the interface, since an inline body calling an internal-linkage function is a TU-local exposure);
19+
`wuffs_aux` 36 names; 341 macros: 296 constants (captured type preserved), 34 macros naming functions as constexpr
20+
pointers, 11 listed with reasons (attributes, feature tests, the include guard, the token-pasting
21+
`WUFFS_BASE__SLICE/TABLE/RESULT(T)`). `src/wuffs_aux.cppm`, not `aux.cppm`: AUX is a reserved name on Windows.
22+
23+
## Verification
24+
25+
- `tests/surface_test.cpp` (generated): every adapter's type equals the header function's, every constant equals its
26+
macro with its type, every alias points at its target — compile time, GCC 16 and Clang 23.
27+
- `tests/api_test.cpp`: every package through the module alone (PNG, GIF, BMP, TGA, WBMP, NIE; DEFLATE, zlib, gzip,
28+
bzip2; CRC-32, Adler-32; JSON with a JSON pointer, CBOR; numbers, UTF-8, base-64; the error paths).
29+
- Conformance: upstream's `example/convert-to-nia` ported against the module vs upstream's `convert-to-nia.c` on all
30+
246 files of `test/data`, NIA and NIE: identical bytes, message and exit code; 82/82 checksums of
31+
`test/nia-checksums-of-data.txt`. CI: Linux x86_64, Linux arm64, macOS arm64 (Windows: the reference needs
32+
`<unistd.h>`). The reference backports upstream main's end-of-input test: 0.3.6's `errno == 0` reads a stale
33+
errno where the Linux seccomp call fails (EINVAL on hosts refusing strict mode) and stops a step early.
34+
- wuffs-m CI: 5 rows (Linux gcc/llvm, Linux arm64, macOS, Windows), dev and release; templates job.
35+
- Installed acceptance (this PR): `check_installed_template.py --deploy` on the real archive (template strict build
36+
and run, relocated bundle, 5 byte-identical notices); member `wuffs-decode` (behavior, side header).
37+
38+
## Notes
39+
40+
- Publication delay: wuffs-m's first CI run on the published index started 1m48s after `publish-artifact` finished
41+
and did not see `compat.wuffs`; a rerun minutes later did.

‎.github/workflows/validate.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,11 @@ jobs:
17221722
shell: bash
17231723
run: python3 tests/mwrap/check_installed_template.py --mcpp "$MCPP" --package mcpplibs.mwrap.sheenbidi@3.0.0 --deploy
17241724

1725+
- name: Installed Wuffs wrapper archive, actual default decode template and its relocated notices
1726+
if: contains(format(' {0} ', env.MEMBERS), ' wuffs-decode ') && matrix.toolchain == 'default'
1727+
shell: bash
1728+
run: python3 tests/mwrap/check_installed_template.py --mcpp "$MCPP" --package mcpplibs.mwrap.wuffs@0.3.6 --deploy
1729+
17251730
- name: Installed dr_libs wrapper archive, actual default tone template and its relocated notices
17261731
if: contains(format(' {0} ', env.MEMBERS), ' dr_libs-audio ') && matrix.toolchain == 'default'
17271732
shell: bash

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
### Added
1111

12+
- **mcpplibs.mwrap.wuffs 0.3.6:wuffs-m(Wuffs 的 C++23 模块),基于 compat.wuffs 0.3.6。** 每个上游包一个模块(`.base`、`.png`、`.gif`、`.json`、`.gzip` 等 16 个)、`.aux`(`wuffs_aux`)与 `.macros`;由 clang AST 生成并审计:429 个全局名导出,315 个 `static inline` 函数在 `mcpplibs::mwrap::wuffs` 中同名同签名适配,296 个宏常量与 34 个函数名宏映射,11 个附原因列出。上游 `convert-to-nia` 的模块移植版与上游程序在 `test/data` 的 246 个文件上逐字节一致,82/82 个 NIA 校验和一致。成员 tests/mwrap/wuffs-decode;validate.yml 以真实归档做已安装模板与部署通知检查。CN:mcpp-res/mwrap-wuffs。
1213
- **compat.wuffs 0.3.6:Google 的 Wuffs,面向不可信文件格式的内存安全解码器(Apache-2.0)。** 上游只发布单文件 `release/c/wuffs-v0.3.c`:本包取 tag 归档,以一个生成的翻译单元在 `WUFFS_IMPLEMENTATION` 下按 C++ 编译,C API(`extern "C"`)与只在 C++ 下定义的 `wuffs_aux`(DecodeImage、DecodeJson、DecodeCbor)都在同一个库里;使用者按上游写法 `#include <wuffs-v0.3.c>`。成员 tests/examples/wuffs:版本串、gzip 经 C API、CRC-32 与 Adler-32 的标准校验值、PNG 经 DecodeImage 逐像素、截断 PNG 被拒绝、JSON 遍历。0.4 线上游仍为 alpha。
1314
- **openkal-platform 0.31.2:版本组的补丁,一个成员。** openkal-image 0.7.2(载体 openkal-run、工具 okld/okrun/okprof 与构建依赖
1415
openkal-tools):程序的副本按副本自己结束它的方式结束,映像以 fork 加 exec 启动的程序不再停在副本的 `kal_exit` 中

‎mcpp.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ members = [
2323
"tests/mwrap/pocketpy-embed",
2424
"tests/mwrap/libpng-image",
2525
"tests/mwrap/libwebp-image",
26+
"tests/mwrap/wuffs-decode",
2627
"tests/mwrap/concurrentqueue-mpmc",
2728
"tests/mwrap/fribidi-bidi",
2829
"tests/mwrap/sheenbidi-bidi",

‎pkgs/mwrap/wuffs.lua‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
-- Immutable upstream-aligned mwrap source release (wuffs-m mwrap-0.3.6);
2+
-- GLOBAL and CN bytes are identical.
3+
--
4+
-- The wrapper is Apache-2.0, and so is the library it links, compat.wuffs
5+
-- (Wuffs 0.3.6, release/c/wuffs-v0.3.c compiled as C++), linked statically:
6+
-- the package deploys Wuffs' README, LICENSE and AUTHORS beside programs
7+
-- (runtime.deploy).
8+
package = {
9+
spec = "1",
10+
namespace = "mcpplibs.mwrap",
11+
name = "wuffs",
12+
description = "wuffs-m: Wuffs (memory-safe decoders for untrusted formats: PNG, GIF, BMP, DEFLATE, gzip, JSON …) as C++23 modules",
13+
licenses = { "Apache-2.0" },
14+
repo = "https://github.com/mcpplibs/wuffs-m",
15+
type = "package",
16+
extensions = {
17+
autoupdate = {
18+
tag = "mwrap-${version}",
19+
url = "https://github.com/mcpplibs/wuffs-m/releases/download/${tag}/wuffs-m-${version}.tar.gz",
20+
},
21+
},
22+
xpm = {
23+
linux = {
24+
["0.3.6"] = {
25+
url = {
26+
GLOBAL = "https://github.com/mcpplibs/wuffs-m/releases/download/mwrap-0.3.6/wuffs-m-0.3.6.tar.gz",
27+
CN = "https://gitcode.com/mcpp-res/mwrap-wuffs/releases/download/0.3.6/wuffs-m-0.3.6.tar.gz",
28+
},
29+
sha256 = "fe71c84320c16afc8c45a301cd2de2c65d88a3c99909a1d24ce1acc831d0c248",
30+
},
31+
},
32+
macosx = {
33+
["0.3.6"] = {
34+
url = {
35+
GLOBAL = "https://github.com/mcpplibs/wuffs-m/releases/download/mwrap-0.3.6/wuffs-m-0.3.6.tar.gz",
36+
CN = "https://gitcode.com/mcpp-res/mwrap-wuffs/releases/download/0.3.6/wuffs-m-0.3.6.tar.gz",
37+
},
38+
sha256 = "fe71c84320c16afc8c45a301cd2de2c65d88a3c99909a1d24ce1acc831d0c248",
39+
},
40+
},
41+
windows = {
42+
["0.3.6"] = {
43+
url = {
44+
GLOBAL = "https://github.com/mcpplibs/wuffs-m/releases/download/mwrap-0.3.6/wuffs-m-0.3.6.tar.gz",
45+
CN = "https://gitcode.com/mcpp-res/mwrap-wuffs/releases/download/0.3.6/wuffs-m-0.3.6.tar.gz",
46+
},
47+
sha256 = "fe71c84320c16afc8c45a301cd2de2c65d88a3c99909a1d24ce1acc831d0c248",
48+
},
49+
},
50+
},
51+
}

‎tests/mwrap/check_installed_template.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"mcpplibs.mwrap.libc": ("libc.cppm", None, b"", b"ISO/IEC 9899:2018"),
3232
"mcpplibs.mwrap.abseil": ("abseil.cppm", "upstream/abseil-cpp/LICENSE", b"Apache License", b"The Abseil Authors"),
3333
"mcpplibs.mwrap.openssl": ("openssl.cppm", "upstream/openssl/LICENSE.txt", b"Apache License", b"The OpenSSL Project Authors"),
34+
"mcpplibs.mwrap.wuffs": ("wuffs.cppm", "upstream/wuffs/LICENSE", b"Apache License", b"The Wuffs Authors"),
3435
"mcpplibs.mwrap.protobuf": ("protobuf.cppm", "upstream/protobuf/LICENSE", b"Redistribution and use in source and binary forms", b"Google"),
3536
}
3637

‎tests/mwrap/wuffs-decode/mcpp.toml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "wuffs-decode"
3+
version = "0.3.6"
4+
description = "Consume the immutable Wuffs wrapper: a PNG and a GIF decoded pixel by pixel, gzip inflated by the C API and the adapted static inline helpers, JSON walked by wuffs_aux, a truncated image refused, the mapped macros, the side header beside the import"
5+
6+
[indices]
7+
# Use the complete candidate built-in index prepared by tests/run_members.sh.
8+
# An explicit empty table overrides the legacy workspace redirect.
9+
10+
[dependencies]
11+
mcpplibs.mwrap.wuffs = "0.3.6"
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// mcpplibs.mwrap.wuffs, installed: Wuffs through the module alone.
2+
import std;
3+
import mcpplibs.mwrap.wuffs;
4+
5+
using namespace mcpplibs::mwrap::wuffs; // the adapted static inline API
6+
using namespace mcpplibs::mwrap::wuffs::macros; // WUFFS_VERSION, WUFFS_BASE__FOURCC__PNG …
7+
8+
namespace {
9+
// 2x2 RGB PNG: red, green / blue, white.
10+
constexpr std::uint8_t png[] = {
11+
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x02,
12+
0x00, 0x00, 0x00, 0x02, 0x08, 0x02, 0x00, 0x00, 0x00, 0xfd, 0xd4, 0x9a, 0x73, 0x00, 0x00, 0x00, 0x12, 0x49, 0x44, 0x41,
13+
0x54, 0x78, 0xda, 0x63, 0xf8, 0xcf, 0xc0, 0xc0, 0x00, 0xc2, 0x0c, 0xff, 0x81, 0x00, 0x00, 0x1f, 0xee, 0x05, 0xfb, 0xf1,
14+
0xab, 0xba, 0x77, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82};
15+
// 1x1 GIF, a red pixel.
16+
constexpr std::uint8_t gif[] = {0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00, 0x80, 0x00, 0x00, 0xff, 0x00, 0x00,
17+
0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44,
18+
0x01, 0x00, 0x3b};
19+
20+
int failures = 0;
21+
void check(bool ok, std::string_view what) {
22+
std::println("{} {}", ok ? "ok " : "FAIL", what);
23+
failures += !ok;
24+
}
25+
26+
std::vector<std::uint32_t> pixels(const std::uint8_t* p, std::size_t n, std::string& error) {
27+
wuffs_aux::DecodeImageCallbacks callbacks;
28+
wuffs_aux::sync_io::MemoryInput input(p, n);
29+
wuffs_aux::DecodeImageResult res = wuffs_aux::DecodeImage(callbacks, input);
30+
error = res.error_message;
31+
std::vector<std::uint32_t> out;
32+
if (!error.empty()) return out;
33+
wuffs_base__table_u8 plane = res.pixbuf.plane(0);
34+
for (std::uint32_t y = 0; y < res.pixbuf.pixcfg.height(); ++y)
35+
for (std::uint32_t x = 0; x < res.pixbuf.pixcfg.width(); ++x)
36+
out.push_back(wuffs_base__peek_u32le__no_bounds_check(plane.ptr + y * plane.stride + x * 4));
37+
return out;
38+
}
39+
} // namespace
40+
41+
int main() {
42+
std::string error;
43+
// BGRA little-endian u32 = 0xAARRGGBB.
44+
check(pixels(png, sizeof png, error) == std::vector<std::uint32_t>{0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFFFF},
45+
"PNG decoded pixel by pixel");
46+
check(pixels(gif, sizeof gif, error) == std::vector<std::uint32_t>{0xFFFF0000}, "GIF decoded");
47+
pixels(png, 40, error);
48+
check(error == "png: truncated input", "a truncated PNG is refused: " + error);
49+
check(wuffs_base__magic_number_guess_fourcc(wuffs_base__make_slice_u8(const_cast<std::uint8_t*>(png), sizeof png), true) ==
50+
WUFFS_BASE__FOURCC__PNG,
51+
"magic number");
52+
53+
const std::string doc = R"({"a":[1,2,3]})";
54+
struct Count : wuffs_aux::DecodeJsonCallbacks {
55+
std::int64_t sum = 0;
56+
std::string AppendNull() override { return ""; }
57+
std::string AppendBool(bool) override { return ""; }
58+
std::string AppendF64(double) override { return ""; }
59+
std::string AppendI64(std::int64_t v) override { sum += v; return ""; }
60+
std::string AppendTextString(std::string&&) override { return ""; }
61+
std::string Push(std::uint32_t) override { return ""; }
62+
std::string Pop(std::uint32_t) override { return ""; }
63+
} count;
64+
wuffs_aux::sync_io::MemoryInput input(doc.data(), doc.size());
65+
check(wuffs_aux::DecodeJson(count, input).error_message.empty() && count.sum == 6, "JSON walked");
66+
check(WUFFS_VERSION_MINOR == 3 && std::string_view(WUFFS_VERSION_STRING).starts_with("0.3.6"), "the release");
67+
return failures ? 1 : 0;
68+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// The side header before the import: the header's entities are the module's,
2+
// its macros work beside it, and an adapted helper is the header's function.
3+
#include <mwrap/wuffs/macros.hpp>
4+
5+
#include <cstdint>
6+
#include <cstdio>
7+
#include <cstdlib>
8+
#include <type_traits>
9+
10+
import mcpplibs.mwrap.wuffs;
11+
12+
static_assert(std::is_same_v<decltype(&mcpplibs::mwrap::wuffs::wuffs_base__make_slice_u8),
13+
decltype(&::wuffs_base__make_slice_u8)>);
14+
static_assert(WUFFS_VERSION_MAJOR == 0 && WUFFS_VERSION_MINOR == 3);
15+
16+
int main() {
17+
std::uint8_t bytes[3] = {1, 2, 3};
18+
wuffs_base__slice_u8 a = ::wuffs_base__make_slice_u8(bytes, 3); // the header's
19+
wuffs_base__slice_u8 b = mcpplibs::mwrap::wuffs::wuffs_base__make_slice_u8(bytes, 3); // the module's
20+
wuffs_crc32__ieee_hasher* hasher = wuffs_crc32__ieee_hasher__alloc(); // the header's declaration, the library's definition
21+
bool ok = a.ptr == b.ptr && a.len == b.len && hasher != nullptr;
22+
std::free(hasher);
23+
std::puts(ok ? "side header and module agree" : "FAIL");
24+
return ok ? 0 : 1;
25+
}

0 commit comments

Comments
 (0)