Skip to content

Commit 3361902

Browse files
committed
modules: the protocol wrappers cross the boundary, via the purview
clang rejected the first attempt and was right: error: using declaration referring to 'wl_surface_attach' with internal linkage cannot be exported wayland-scanner emits the protocol wrappers `static inline`, and C++ forbids exporting an entity with internal linkage. GCC accepted it, which is why the first green was meaningless — mcpp-index's llvm leg caught it. Same-name forwarders in module purview do not work either (they clash with the global-module declarations), and neither does giving them external linkage while the originals are still visible. What does work is not declaring the originals at all in this translation unit: the global module fragment includes only wayland-<side>-core.h, and a copy of the generated protocol header with `static inline` -> `inline` is included INSIDE the module purview. Every declaration in it is inside `extern "C"`, so it keeps C language linkage, is not attached to the module, and still matches wayland-protocol.c's definitions. What still cannot cross is now exact rather than approximate: the `static inline` helpers in the GMF headers themselves — wl_fixed_* (4) and wl_signal_* (5). A consumer needing those includes the header next to the import, which the README states. Both toolchains build all four members, and CI re-runs the generator and diffs so the wrappers cannot drift from the headers.
1 parent 327e511 commit 3361902

7 files changed

Lines changed: 13360 additions & 479 deletions

File tree

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ jobs:
130130
done
131131
echo "generated code matches wayland.xml and this scanner"
132132
133+
- name: the module wrappers match the generator
134+
run: |
135+
# The .cppm files and the -module.h copies are generated from the
136+
# public headers. Checked in, so they can drift; this stops it.
137+
python3 mcpp/tools/genmod.py .
138+
if ! git diff --quiet; then
139+
echo "::error::module wrappers are out of date — run mcpp/tools/genmod.py ."
140+
git diff --stat
141+
exit 1
142+
fi
143+
echo "module wrappers match"
144+
133145
- name: every module produced an interface
134146
run: |
135147
for m in wayland.client wayland.server wayland.util; do

README.mcpp.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ code written against the C headers ports by swapping one line.
2525
The export lists are **generated from the public headers** rather than kept by
2626
hand, so a version bump cannot quietly drop a name.
2727

28+
## What crosses the module boundary, and what does not
29+
30+
`export` names entities, and it cannot name one with **internal linkage**. That
31+
rule decides the whole layout here:
32+
33+
- **Types, `wl_proxy_*` / `wl_display_*` / `wl_resource_*`, the interface
34+
objects, the enums** — external linkage, re-exported with `using ::name;`.
35+
- **The protocol wrappers** (`wl_surface_attach`, `wl_data_device_send_drop`, …)
36+
— wayland-scanner emits them `static inline`. A copy of the generated header
37+
with `static inline` changed to `inline` is included *inside the module
38+
purview*, which gives them external linkage; everything in it sits inside
39+
`extern "C"`, so it keeps C language linkage and still matches
40+
`wayland-protocol.c`'s definitions. GCC accepts the naive `using ::name;`
41+
here and clang rejects it — clang is right, and CI runs both.
42+
- **`wl_fixed_to_double` and friends, `wl_signal_*`**`static inline` in
43+
`wayland-util.h` / `wayland-server-core.h`, which the module includes in its
44+
global module fragment. Those cannot be reached, so a consumer that needs them
45+
includes the header next to the import. Four and five names respectively.
46+
- **Macros** — not entities at all; see below.
47+
2848
## Macros are the one thing that could not cross
2949

3050
`export` names entities, and a macro is not one. Wayland's public surface has

0 commit comments

Comments
 (0)