Skip to content

Commit 1b08426

Browse files
committed
docs: the README was written before wayland-util and the module layer existed
1 parent c9e9994 commit 1b08426

1 file changed

Lines changed: 79 additions & 21 deletions

File tree

README.mcpp.md

Lines changed: 79 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,104 @@
11
# mcpplibs/wayland
22

33
[Wayland](https://gitlab.freedesktop.org/wayland/wayland) 1.26.0 with mcpp build
4-
support, consumed from [mcpp-index](https://github.com/mcpplibs/mcpp-index) as
5-
three packages:
4+
support. Consumed from [mcpp-index](https://github.com/mcpplibs/mcpp-index) as
5+
four packages, all out of this one tarball:
66

77
| package | output |
88
|---|---|
99
| `freedesktop.wayland-scanner` | `wayland-scanner`, the protocol code generator |
10-
| `freedesktop.wayland` | `libwayland-client.so.0` |
11-
| `freedesktop.wayland-server` | `libwayland-server.so.0` |
10+
| `freedesktop.wayland` | `libwayland-client.so.0` + `import wayland.client;` |
11+
| `freedesktop.wayland-server` | `libwayland-server.so.0` + `import wayland.server;` |
12+
| `freedesktop.wayland-util` | `import wayland.util;` — the macros, as entities |
1213

1314
```bash
1415
mcpp build --workspace
1516
```
1617

18+
## The module wrappers add no API
19+
20+
`import wayland.client;` replaces `#include <wayland-client.h>` and changes
21+
nothing else. Every exported name is upstream's, spelled upstream's way, with
22+
upstream's semantics — there are no wrapper types, no RAII, no renaming — so
23+
code written against the C headers ports by swapping one line.
24+
25+
The export lists are **generated from the public headers** rather than kept by
26+
hand, so a version bump cannot quietly drop a name.
27+
28+
## Macros are the one thing that could not cross
29+
30+
`export` names entities, and a macro is not one. Wayland's public surface has
31+
fourteen, so `wayland.util` maps each to what it actually is:
32+
33+
| macro | in the module |
34+
|---|---|
35+
| `WL_MARSHAL_FLAG_DESTROY` | `inline constexpr` — the spelling survives intact |
36+
| `wl_container_of(p, sample, member)` | `wl_container_of<&T::member>(p)` |
37+
| `wl_list_for_each(p, head, member)` | `for (T *p : wl_list_each<&T::member>(head))` |
38+
| `wl_list_for_each_safe` / `_reverse` / `_reverse_safe` | the matching `wl_list_each_*` ranges |
39+
| `wl_array_for_each(p, array)` | `for (T *p : wl_array_each<T>(array))` |
40+
41+
The `_safe` variants keep upstream's guarantee — the successor is latched
42+
before the body runs, so the current element may be removed or freed — and the
43+
package's test exercises exactly that. It links nothing: the list is wired up by
44+
hand so a package of templates keeps zero dependencies.
45+
46+
## Why this is a fork and not an index descriptor
47+
48+
Wayland is mostly **generated**. `protocol/wayland.xml` describes every
49+
interface and `wayland-scanner` emits ~13,000 lines from it — most of both
50+
libraries. The generator is a C program in this same tree, so it has to be
51+
**compiled before it can run**.
52+
53+
An mcpp-index descriptor cannot express that: it has no build step, and an
54+
`install()` hook cannot do it either, because mcpp compiles a package's sources
55+
at *consumer-build* time — no package binary exists while another package is
56+
installing. `build.mcpp` is the mechanism for exactly this, and it only exists
57+
for a real mcpp project. Same reason [grpc-m](https://github.com/mcpplibs/grpc-m)
58+
exists.
59+
60+
A host `wayland-scanner` is not a substitute. 1.22 rejects 1.26's
61+
`protocol/wayland.xml` outright — it does not know the `deprecated-since`
62+
attribute — so reaching for whatever is on PATH either fails or, worse, emits
63+
code for a different protocol revision than the headers describe. Asking for it
64+
with `tools = ["wayland-scanner"]` makes the generator's version the
65+
dependency's version, so that mismatch is not expressible.
66+
67+
## Why four packages rather than one
68+
69+
`libwayland-client.so.0` and `libwayland-server.so.0` are distinct SONAMEs, and
70+
Mesa's `libEGL_mesa` carries DT_NEEDED on **both** — so they must be two files
71+
with disjoint contents. mcpp compiles a package's sources once and links every
72+
library target against all of them; there is no per-target source list, and a
73+
feature-gated second target still receives the feature's objects (measured).
74+
mcpp's own diagnostic names the remedy: *"for config that must affect shared
75+
code, split into a workspace member."*
76+
77+
Each library package carries its C library **and** its module, so there is one
78+
package per library rather than a C one and a module one beside it.
79+
1780
## What was added
1881

19-
Nothing upstream was patched. The fork adds:
82+
Nothing upstream was patched:
2083

2184
```
22-
config.h the probe results meson's configure_file() writes,
23-
for linux/glibc (wayland-os.c says "../config.h")
85+
config.h the probe results meson's configure_file() writes, for
86+
linux/glibc (wayland-os.c says "../config.h", so it is
87+
at the tree root)
2488
mcpp/include/ wayland-version.h, substituted from src/wayland-version.h.in
25-
mcpp/scanner/ manifest for the generator
26-
mcpp/client/ manifest + build.mcpp for libwayland-client
27-
mcpp/server/ manifest + build.mcpp for libwayland-server
89+
mcpp/scanner/ the generator
90+
mcpp/util/ the macro mappings + their test
91+
mcpp/client/ libwayland-client + wayland.client, and build.mcpp
92+
mcpp/server/ libwayland-server + wayland.server, and build.mcpp
2893
mcpp.toml the workspace root
2994
```
3095

3196
`build.mcpp` declares the wayland-scanner invocations as build-graph edges, so
32-
they re-run exactly when `protocol/wayland.xml` changes.
33-
34-
## Why the scanner is a package of its own
35-
36-
A host `wayland-scanner` is not interchangeable. 1.22 rejects 1.23's
37-
`wayland.xml` outright — it does not know the `deprecated-since` attribute — so
38-
reaching for whatever is on PATH either fails or, worse, emits code for a
39-
different protocol revision than the headers describe. Asking for it with
40-
`tools = ["wayland-scanner"]` makes the generator's version the dependency's
41-
version, so that mismatch is not expressible.
97+
they re-run exactly when `protocol/wayland.xml` changes and a failure is
98+
attributed to the edge rather than to "build.mcpp exited 1".
4299

43100
## Upstream
44101

45102
Tracking wayland 1.26.0. Upstream sources, `protocol/`, `tests/` and the meson
46-
build are untouched, so `meson setup build && ninja -C build` still works.
103+
build are untouched — CI builds the tree with `meson setup && ninja` on every
104+
run, so "no upstream file is patched" has a test rather than a promise.

0 commit comments

Comments
 (0)