Repository navigation
Commit 3e42e5a
committed
fix(libgbm): make the backend repair invisible — stock <gbm.h> is the API
The first cut exposed `mcpp_gbm.h` and asked the consumer to call
`mcpp_gbm_use_sibling_backends()` before creating a device. That changed
the ordinary way to use libgbm, and it was not only a style problem: it
does not work for the consumers that matter.
libgbm is mostly called from INSIDE other libraries — SDL2's KMSDRM
backend, wlroots, ffmpeg's VAAPI hwcontext all call gbm_create_device()
from their own sources. None of them will ever call a helper of ours, so
an opt-in repair leaves exactly those callers as broken as they were,
while the package's own tests go green.
The API is now stock `#include <gbm.h>` and nothing else. GBM_BACKENDS_PATH
is wired from a CONSTRUCTOR in the package's own TU (priority 101, ahead of
default-priority constructors in case one creates a device). An inherited
value is still left alone — this is a default, not an override.
That is reliable because a dependency's objects enter the consumer's link
eagerly rather than being lazily selected; the emitted build.ninja names
the object on the link line directly, so the constructor cannot be dropped.
It is also what every other ecosystem does, and none of them use an API:
distros (Debian libgbm1, Fedora mesa-libgbm) split libgbm out of the mesa
SOURCE package so the compiled-in $libdir/gbm is right by construction;
relocated and sandboxed stacks set the environment variable instead —
Valve's pressure-vessel hit this exact bug when mesa 24.3 split the
backends out (steam-runtime#797) and answers with GBM_BACKENDS_PATH,
as do Nix, Conda and AppImage at activation time; and Mesa offers
-Dgbm-backends-path= for packagers who control the build. This package is
in the sandboxed case and cannot set a container-wide environment, so the
constructor is the in-process equivalent. Longer term the wiring belongs
in xim:mesa (build with -Dgbm-backends-path=, or declare lib/gbm/ into the
view as it already declares lib and include), and then this package would
carry no constructor at all; noted in the design doc.
mcpp_gbm.h stays, demoted to optional introspection for diagnostics and
for the tests, and says so in its own first line.
Tests now come in two binaries, and the split is the regression guard for
this very mistake:
* tests/stock_usage.cpp includes STOCK <gbm.h> and nothing else — no
mcpp_gbm.h, no helper declaration. If the repair ever goes back to
being opt-in, this fails while the fuller gbm.cpp could still pass.
* tests/gbm.cpp reads GBM_BACKENDS_PATH before calling anything at all,
and re-execs itself with the variable preset to prove an inherited
value survives the constructor — the only way to observe that rule,
since by the time main runs the constructor is finished.
Also drops the generated_files copy of the TU: install() is the only
writer, and the parser takes literals only so the two could not share one
source. Verified cold with the CI-pinned mcpp: 2 passed, 0 failed; both
binaries confirmed failable by removing dri_gbm.so from the farm.1 parent 865f2c0 commit 3e42e5a
7 files changed
Lines changed: 343 additions & 140 deletions
File tree
- .agents/docs
- docs
- zh
- pkgs/c
- tests/examples/libgbm
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
107 | 152 | | |
108 | 153 | | |
109 | 154 | | |
| |||
167 | 212 | | |
168 | 213 | | |
169 | 214 | | |
170 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
171 | 230 | | |
172 | 231 | | |
173 | 232 | | |
| |||
179 | 238 | | |
180 | 239 | | |
181 | 240 | | |
182 | | - | |
| 241 | + | |
| 242 | + | |
183 | 243 | | |
184 | 244 | | |
185 | 245 | | |
| |||
193 | 253 | | |
194 | 254 | | |
195 | 255 | | |
196 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
197 | 259 | | |
198 | | - | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
199 | 266 | | |
200 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
201 | 271 | | |
202 | 272 | | |
203 | 273 | | |
204 | 274 | | |
205 | | - | |
| 275 | + | |
206 | 276 | | |
207 | 277 | | |
208 | 278 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
0 commit comments