Skip to content

Commit 7741d10

Browse files
authored
feat(libdisplay-info): 生成全部走 build.mcpp,并带模块 (#308)
按规范重做:fork 的生成物不再用 sh + python 预生成再签进仓,改由 build.mcpp 产出——它是 C++,mcpp 编译并运行它,所以这个包不需要 python3、sh 或任何外部工具。 pnp-id-table.c 2583 行厂商表,写进 out dir src/libdisplay-info.cppm 模块包装,206 个名字(130 类型 + 76 函数) 没有签进仓的生成物,也就没有「重生成再 diff」的 CI 步骤——数据与代码不一致 这个状态不存在。这是构建期生成和签生成物的本质区别。 模块解决一个真问题:七个公共头一个 extern "C" 都没有,C++ 消费者 #include 会 mangle 到链接失败。测试成员之前就得自己包一层;现在 import freedesktop.displayinfo; 把包装做在模块内。测试已改成 import 并通过,证明经索引也可用。 顺带:build.mcpp 的表比上游生成器更正确。pnp.ids 里 U+00A0 编码是 c2 a0 两字节, 上游按文本读、按码点转义成 \240(单字节,不是 UTF-8);build.mcpp 按字节转义成 \302\240。全文件 diff:2583 行,除几个非 ASCII 名字外完全一致。 只改了 pkgs/ 与 tests/examples/。
1 parent 7a2305f commit 7741d10

2 files changed

Lines changed: 44 additions & 23 deletions

File tree

pkgs/f/freedesktop.libdisplay-info.lua

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,35 @@
2424
-- tables generated from them by 15 (2568 vs 2583) — so an unpinned build makes
2525
-- `di_info_get_make` answer differently depending on where it was compiled.
2626
--
27-
-- The fork pins hwdata v0.410, checks the input in beside the output, and its
28-
-- CI regenerates and diffs. Same arrangement as freedesktop.libevdev with
29-
-- upstream's bundled kernel headers.
30-
--
31-
-- NO MODULE WRAPPER, deliberately: this library's consumer is wlroots, which is
32-
-- C, and the surface is 74 functions over ~360 structs. The design doc's rule
33-
-- applies — the module layer is a RESULT of forking, not a reason to fork.
34-
--
35-
-- ⚠ C++ CONSUMERS MUST WRAP THE INCLUDES. Not one of the seven public headers
36-
-- has an `extern "C"` block, so a C++ TU mangles every declaration and the link
37-
-- fails with `undefined reference to di_info_get_make(di_info const*)` — naming
38-
-- a symbol that is right there. Same as compat.libseat.
27+
-- The fork pins hwdata v0.410 and checks it in as an INPUT. There is no
28+
-- checked-in output and no regenerate-and-diff CI step, because there is
29+
-- nothing to keep honest: `build.mcpp` PRODUCES the table during the build.
30+
--
31+
-- NOTHING IN THIS PACKAGE NEEDS python3, sh OR ANY OTHER TOOL. `build.mcpp` is
32+
-- C++ that mcpp compiles and runs, and it does every generated artifact:
33+
--
34+
-- pnp-id-table.c 2,583 lines, into the out dir
35+
-- src/libdisplay-info.cppm the module wrapper, 206 names
36+
--
37+
-- IT IS ALSO MORE CORRECT THAN UPSTREAM'S GENERATOR. pnp.ids stores
38+
-- `DemoPad<U+00A0>Software<U+00A0>Ltd`, and U+00A0 is the two bytes c2 a0.
39+
-- Upstream reads the file as TEXT and escapes the codepoint by ordinal —
40+
-- `\240`, a single byte that is not its UTF-8 encoding, so the string a
41+
-- consumer prints is invalid UTF-8. build.mcpp escapes BYTES. Diffed over the
42+
-- whole file: 2,583 lines, identical except for the handful of non-ASCII names,
43+
-- where this one is right.
44+
--
45+
-- THE MODULE IS GENERATED, not hand-written: 206 names read out of the public
46+
-- headers, so a version bump cannot silently drop one.
47+
--
48+
-- import freedesktop.displayinfo;
49+
--
50+
-- and that also removes a real burden — not one of the seven public headers has
51+
-- an `extern "C"` block, so a C++ TU that #includes them mangles every
52+
-- declaration and fails to link with `undefined reference to
53+
-- di_info_get_make(di_info const*)`. The module does that wrapping once, inside
54+
-- the module purview, so a consumer does not. (compat.libseat has the same
55+
-- upstream problem and no module, so there the consumer still wraps.)
3956
package = {
4057
spec = "1",
4158
namespace = "freedesktop",
@@ -49,10 +66,10 @@ package = {
4966
linux = {
5067
["0.2.0"] = {
5168
url = {
52-
GLOBAL = "https://github.com/mcpplibs/libdisplay-info/releases/download/v0.2.0/libdisplay-info-0.2.0-mcpp.tar.gz",
53-
CN = "https://gitcode.com/mcpp-res/libdisplay-info/releases/download/0.2.0/libdisplay-info-0.2.0-mcpp.tar.gz",
69+
GLOBAL = "https://github.com/mcpplibs/libdisplay-info/releases/download/v0.2.0/libdisplay-info-0.2.0-mcpp2.tar.gz",
70+
CN = "https://gitcode.com/mcpp-res/libdisplay-info/releases/download/0.2.0/libdisplay-info-0.2.0-mcpp2.tar.gz",
5471
},
55-
sha256 = "df065a6e040799536a6c93a0202f2766b8c3388b546d0ba4a43290a89aa33ccc",
72+
sha256 = "8df9a8064146b2b38378bd8b146894d084ffda43b88b43c485b954da073a7617",
5673
},
5774
},
5875
},

tests/examples/libdisplay-info/tests/libdisplay-info.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@
2424

2525
#ifdef __linux__
2626

27-
// WRAPPED, and it has to be: not one of libdisplay-info's seven public headers
28-
// contains an `extern "C"` block — zero occurrences, measured — so a C++
29-
// translation unit mangles every declaration and the link fails with
27+
// NO extern "C" WRAPPER, and that is the point of the module.
28+
//
29+
// Not one of libdisplay-info's seven public headers contains an `extern "C"`
30+
// block — zero occurrences, measured — so a C++ translation unit that
31+
// #includes them mangles every declaration and fails to link with
3032
// `undefined reference to di_info_get_make(di_info const*)`, naming a symbol
31-
// that is right there in the library. Same as compat.libseat.
32-
extern "C" {
33-
#include <libdisplay-info/info.h>
34-
#include <libdisplay-info/edid.h>
35-
}
33+
// that is right there in the library. This file did exactly that before the
34+
// module existed.
35+
//
36+
// `import freedesktop.displayinfo;` does the wrapping once, inside the module
37+
// purview. The module is GENERATED by the package's build.mcpp from the public
38+
// headers — 206 names — so it cannot fall behind them.
39+
import freedesktop.displayinfo;
3640

3741
#include <cstdio>
3842
#include <cstring>

0 commit comments

Comments
 (0)