@gjsify/gtk-runtime-win32-x64 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +133 -133
  2. package/gtk/bin/cairo-2.dll +0 -0
  3. package/gtk/bin/cairo-gobject-2.dll +0 -0
  4. package/gtk/bin/cairo-script-interpreter-2.dll +0 -0
  5. package/gtk/bin/epoxy-0.dll +0 -0
  6. package/gtk/bin/ffi-8.dll +0 -0
  7. package/gtk/bin/fontconfig-1.dll +0 -0
  8. package/gtk/bin/freetype-6.dll +0 -0
  9. package/gtk/bin/fribidi-0.dll +0 -0
  10. package/gtk/bin/gdk_pixbuf-2.0-0.dll +0 -0
  11. package/gtk/bin/gio-2.0-0.dll +0 -0
  12. package/gtk/bin/girepository-1.0-1.dll +0 -0
  13. package/gtk/bin/girepository-2.0-0.dll +0 -0
  14. package/gtk/bin/glib-2.0-0.dll +0 -0
  15. package/gtk/bin/gmodule-2.0-0.dll +0 -0
  16. package/gtk/bin/gobject-2.0-0.dll +0 -0
  17. package/gtk/bin/graphene-1.0-0.dll +0 -0
  18. package/gtk/bin/gtk-4-1.dll +0 -0
  19. package/gtk/bin/harfbuzz-cairo.dll +0 -0
  20. package/gtk/bin/harfbuzz-gobject.dll +0 -0
  21. package/gtk/bin/harfbuzz-gpu.dll +0 -0
  22. package/gtk/bin/harfbuzz-raster.dll +0 -0
  23. package/gtk/bin/harfbuzz-subset.dll +0 -0
  24. package/gtk/bin/harfbuzz-vector.dll +0 -0
  25. package/gtk/bin/harfbuzz.dll +0 -0
  26. package/gtk/bin/iconv.dll +0 -0
  27. package/gtk/bin/intl.dll +0 -0
  28. package/gtk/bin/jpeg62.dll +0 -0
  29. package/gtk/bin/libexpat.dll +0 -0
  30. package/gtk/bin/libpng16.dll +0 -0
  31. package/gtk/bin/pango-1.0-0.dll +0 -0
  32. package/gtk/bin/pangocairo-1.0-0.dll +0 -0
  33. package/gtk/bin/pangoft2-1.0-0.dll +0 -0
  34. package/gtk/bin/pangowin32-1.0-0.dll +0 -0
  35. package/gtk/bin/pcre2-8-0.dll +0 -0
  36. package/gtk/bin/pixman-1-0.dll +0 -0
  37. package/gtk/bin/tiff.dll +0 -0
  38. package/gtk/bin/zlib1.dll +0 -0
  39. package/gtk/girepository-1.0/Adw-1.typelib +0 -0
  40. package/gtk/girepository-1.0/DBus-1.0.typelib +0 -0
  41. package/gtk/girepository-1.0/DBusGLib-1.0.typelib +0 -0
  42. package/gtk/girepository-1.0/GIRepository-2.0.typelib +0 -0
  43. package/gtk/girepository-1.0/GIRepository-3.0.typelib +0 -0
  44. package/gtk/girepository-1.0/GL-1.0.typelib +0 -0
  45. package/gtk/girepository-1.0/GLib-2.0.typelib +0 -0
  46. package/gtk/girepository-1.0/GLibWin32-2.0.typelib +0 -0
  47. package/gtk/girepository-1.0/GModule-2.0.typelib +0 -0
  48. package/gtk/girepository-1.0/GObject-2.0.typelib +0 -0
  49. package/gtk/girepository-1.0/Gdk-4.0.typelib +0 -0
  50. package/gtk/girepository-1.0/GdkPixbuf-2.0.typelib +0 -0
  51. package/gtk/girepository-1.0/GdkPixdata-2.0.typelib +0 -0
  52. package/gtk/girepository-1.0/GdkWin32-4.0.typelib +0 -0
  53. package/gtk/girepository-1.0/Gio-2.0.typelib +0 -0
  54. package/gtk/girepository-1.0/GioWin32-2.0.typelib +0 -0
  55. package/gtk/girepository-1.0/Graphene-1.0.typelib +0 -0
  56. package/gtk/girepository-1.0/Gsk-4.0.typelib +0 -0
  57. package/gtk/girepository-1.0/Gtk-4.0.typelib +0 -0
  58. package/gtk/girepository-1.0/GtkSource-5.typelib +0 -0
  59. package/gtk/girepository-1.0/HarfBuzz-0.0.typelib +0 -0
  60. package/gtk/girepository-1.0/Pango-1.0.typelib +0 -0
  61. package/gtk/girepository-1.0/PangoCairo-1.0.typelib +0 -0
  62. package/gtk/girepository-1.0/PangoFT2-1.0.typelib +0 -0
  63. package/gtk/girepository-1.0/PangoFc-1.0.typelib +0 -0
  64. package/gtk/girepository-1.0/PangoOT-1.0.typelib +0 -0
  65. package/gtk/girepository-1.0/Rsvg-2.0.typelib +0 -0
  66. package/gtk/girepository-1.0/Vulkan-1.0.typelib +0 -0
  67. package/gtk/girepository-1.0/cairo-1.0.typelib +0 -0
  68. package/gtk/girepository-1.0/fontconfig-2.0.typelib +0 -0
  69. package/gtk/girepository-1.0/freetype2-2.0.typelib +0 -0
  70. package/gtk/girepository-1.0/libxml2-2.0.typelib +0 -0
  71. package/gtk/girepository-1.0/win32-1.0.typelib +0 -0
  72. package/gtk/girepository-1.0/xfixes-4.0.typelib +0 -0
  73. package/gtk/girepository-1.0/xft-2.0.typelib +0 -0
  74. package/gtk/girepository-1.0/xlib-2.0.typelib +0 -0
  75. package/gtk/girepository-1.0/xrandr-1.3.typelib +0 -0
  76. package/gtk/manifest.json +51 -0
  77. package/index.d.ts +11 -11
  78. package/index.js +27 -27
  79. package/package.json +1 -1
  80. package/scripts/build-gtk-runtime.mjs +446 -446
@@ -1,446 +1,446 @@
1
- // SPDX-License-Identifier: MIT
2
- // Collect a standalone, batteries-included GTK/GObject-Introspection runtime
3
- // bundle for Windows x64 — so @gjsify/node-gi loads gi:// namespaces with NO
4
- // gvsbuild/system GTK on the host (the Windows sibling of the darwin-arm64 bundle).
5
- //
6
- // node scripts/build-gtk-runtime.mjs [--out <dir>] [--prefix <gvsbuild GTK prefix>] [--windowing]
7
- //
8
- // Two closures, one bundle dir:
9
- // • DEFAULT (display-free) — the loadable DLLs + typelibs the DISPLAY-FREE
10
- // conformance needs (GLib/GObject/Gio/cairo/Pango/Graphene/Gdk). Unchanged.
11
- // • --windowing (SUPERSET) — everything above PLUS the runtime data a REAL GTK
12
- // WINDOW needs on Windows: the gdk-pixbuf loaders + `loaders.cache`, compiled
13
- // GSettings schemas (`gschemas.compiled`), the Adwaita/hicolor icon themes +
14
- // `icon-theme.cache`, and the Fontconfig config/cache. The extra image-loader
15
- // backing DLLs (librsvg/png/…) are walked into `bin/` too. node-gi's loader
16
- // (gtk-runtime.js) detects the windowing data (the `gschemas.compiled` marker)
17
- // and wires the env (GSETTINGS_SCHEMA_DIR / GDK_PIXBUF_MODULE_FILE /
18
- // XDG_DATA_DIRS / FONTCONFIG_*) so the SAME loader serves both — the display-free
19
- // path is byte-unchanged when the windowing data is absent.
20
- //
21
- // Runs ONLY on win32/x64 with a build-time gvsbuild GTK4 stack extracted at
22
- // --prefix (env GTK_PREFIX, the closure *source*, not shipped — the same tree the
23
- // node-gi.yml windows jobs cache at C:\gtk-build\gtk\x64\release). gvsbuild bundles
24
- // the tools this needs (gdk-pixbuf-query-loaders / glib-compile-schemas /
25
- // gtk4-update-icon-cache / fc-cache) in <prefix>/bin.
26
- //
27
- // CRUCIAL DIFFERENCE FROM macOS: there is NO relocation step (no install_name_tool,
28
- // no @rpath, no codesign). Windows resolves a DLL's imports by SEARCH PATH at
29
- // LoadLibrary time, so a bundle is "portable" the moment its DLLs sit in one dir —
30
- // node-gi just prepends <out>/bin to PATH before the addon loads. The runtime DATA
31
- // (loaders/schemas/icons/fonts) is likewise resolved by env vars set at load time,
32
- // no baked absolute paths (the caches are rewritten to bundle-relative).
33
- //
34
- // Reference: GJS ships no relocation; gvsbuild ships the MSVC-ABI GTK4 stack whose
35
- // DLLs load into stock (MSVC-ABI) Node.
36
- import { execFileSync } from 'node:child_process';
37
- import {
38
- copyFileSync,
39
- cpSync,
40
- existsSync,
41
- mkdirSync,
42
- readdirSync,
43
- rmSync,
44
- statSync,
45
- writeFileSync,
46
- } from 'node:fs';
47
- import { basename, dirname, join } from 'node:path';
48
- import { fileURLToPath } from 'node:url';
49
-
50
- const pkgRoot = dirname(dirname(fileURLToPath(import.meta.url)));
51
-
52
- // --- args ------------------------------------------------------------------
53
- function argValue(flag) {
54
- const i = process.argv.indexOf(flag);
55
- return i >= 0 && i + 1 < process.argv.length ? process.argv[i + 1] : undefined;
56
- }
57
- const OUT = argValue('--out') ?? join(pkgRoot, 'gtk');
58
- const PREFIX = argValue('--prefix') ?? process.env.GTK_PREFIX;
59
- // The full-windowing SUPERSET: also collect the runtime data a real GTK window needs.
60
- const WINDOWING = process.argv.includes('--windowing');
61
-
62
- if (process.platform !== 'win32' || process.arch !== 'x64') {
63
- console.error(`build-gtk-runtime: only supported on win32/x64, not ${process.platform}/${process.arch}`);
64
- process.exit(2);
65
- }
66
- if (!PREFIX) {
67
- console.error('build-gtk-runtime: no GTK prefix — pass --prefix or set GTK_PREFIX (e.g. C:\\gtk-build\\gtk\\x64\\release)');
68
- process.exit(1);
69
- }
70
-
71
- const gtkBin = join(PREFIX, 'bin');
72
- const gtkTypelibs = join(PREFIX, 'lib', 'girepository-1.0');
73
- if (!existsSync(gtkBin)) {
74
- console.error(`build-gtk-runtime: ${gtkBin} not found — extract the gvsbuild GTK4 stack first`);
75
- process.exit(1);
76
- }
77
-
78
- const sh = (bin, args, opts) => execFileSync(bin, args, { encoding: 'utf8', ...opts });
79
-
80
- // The seed DLLs of the DISPLAY-FREE conformance closure. Liberal, version-agnostic
81
- // patterns matched against <prefix>/bin (gvsbuild's suffixes drift: glib-2.0-0.dll,
82
- // girepository-2.0-0.dll, cairo-2.dll, pango-1.0-0.dll, gdk_pixbuf-2.0-0.dll,
83
- // gtk-4-1.dll, harfbuzz.dll, …). The recursive dumpbin walk pulls every transitive
84
- // gvsbuild dep (harfbuzz, fribidi, fontconfig, freetype, pixman, png, intl, pcre2,
85
- // ffi, epoxy, zlib, …). gtk-4 is seeded because it backs the Gdk typelib the
86
- // conformance's struct-construct loads (Gdk/Graphene) and transitively pulls
87
- // pango/graphene/gdk-pixbuf/cairo/harfbuzz.
88
- const SEED_PATTERNS = [
89
- /^glib-2\.0-.*\.dll$/i,
90
- /^gobject-2\.0-.*\.dll$/i,
91
- /^gio-2\.0-.*\.dll$/i,
92
- /^gmodule-2\.0-.*\.dll$/i,
93
- /^girepository-[12]\.0-.*\.dll$/i, // girepository-2.0 (merged API) on modern gvsbuild
94
- /^cairo(-gobject|-script-interpreter)?-?\d*\.dll$/i,
95
- /^pango(cairo|ft2|win32)?-1\.0-.*\.dll$/i,
96
- /^graphene-1\.0-.*\.dll$/i,
97
- /^gdk[-_]pixbuf-2\.0-.*\.dll$/i,
98
- /^gtk-4-.*\.dll$/i, // provides the Gdk typelib's backing library
99
- /^harfbuzz.*\.dll$/i,
100
- ];
101
-
102
- // Extra seeds for the WINDOWING superset: libadwaita (the Adw-1 typelib's backing
103
- // DLL — a real Adw.Application/ApplicationWindow needs it; the display-free
104
- // conformance never touches Adwaita, so it is NOT in the base seeds), the GL backing
105
- // a GSK GL renderer picks (ANGLE libEGL/libGLESv2 + epoxy — the cairo renderer needs
106
- // none, but a real window may negotiate GL), and librsvg (the SVG gdk-pixbuf loader
107
- // that renders the Adwaita symbolic icons). Most GL/rsvg deps are pulled transitively
108
- // by the loaders below; naming them keeps the closure complete even if a loader is
109
- // missing. (Gdk/Gsk/Gtk are all in gtk-4-*.dll, already a base seed.)
110
- const WINDOWING_SEED_PATTERNS = [
111
- /^(lib)?adwaita-1.*\.dll$/i, // gvsbuild leaf: adwaita-1-0.dll (backs the Adw-1 typelib)
112
- /^libEGL.*\.dll$/i,
113
- /^libGLESv2.*\.dll$/i,
114
- /^epoxy.*\.dll$/i,
115
- /^rsvg.*\.dll$/i,
116
- /^libxml2.*\.dll$/i,
117
- ];
118
-
119
- // Locate an MSVC/gvsbuild tool: env override, then the gvsbuild <prefix>/bin
120
- // (gvsbuild ships gdk-pixbuf-query-loaders / glib-compile-schemas /
121
- // gtk4-update-icon-cache / fc-cache there), then PATH. Null when absent.
122
- function findTool(leaf, envVar) {
123
- const envd = envVar && process.env[envVar];
124
- if (envd && existsSync(envd)) return envd;
125
- const inBin = join(gtkBin, leaf);
126
- if (existsSync(inBin)) return inBin;
127
- try {
128
- const p = sh('where', [leaf.replace(/\.exe$/i, '')]).split(/\r?\n/).map((s) => s.trim()).filter(Boolean)[0];
129
- if (p && existsSync(p)) return p;
130
- } catch {
131
- // not on PATH
132
- }
133
- return null;
134
- }
135
-
136
- // Locate dumpbin (MSVC): env override, then PATH (a dev-cmd/vcvars job), then
137
- // vswhere's -find glob into the VC toolchain. Null when unavailable → the caller
138
- // falls back to copying the whole bin/ DLL set.
139
- function findDumpbin() {
140
- const envd = process.env.DUMPBIN;
141
- if (envd && existsSync(envd)) return envd;
142
- try {
143
- const p = sh('where', ['dumpbin']).split(/\r?\n/).map((s) => s.trim()).filter(Boolean)[0];
144
- if (p && existsSync(p)) return p;
145
- } catch {
146
- // not on PATH
147
- }
148
- const vswhere = join(
149
- process.env['ProgramFiles(x86)'] || 'C:\\Program Files (x86)',
150
- 'Microsoft Visual Studio',
151
- 'Installer',
152
- 'vswhere.exe',
153
- );
154
- if (existsSync(vswhere)) {
155
- try {
156
- const out = sh(vswhere, ['-latest', '-products', '*', '-find', '**\\Hostx64\\x64\\dumpbin.exe']);
157
- const p = out.split(/\r?\n/).map((s) => s.trim()).filter(Boolean)[0];
158
- if (p && existsSync(p)) return p;
159
- } catch {
160
- // vswhere present but no match
161
- }
162
- }
163
- return null;
164
- }
165
-
166
- // Parse `dumpbin /dependents <dll>` into the list of imported DLL leaf names (both
167
- // normal + delay-load sections; stop at the Summary). Exit-tolerant: dumpbin can
168
- // print the section then exit non-zero on some inputs — capture the attached stdout.
169
- function dumpbinDeps(dumpbin, dllPath) {
170
- let out;
171
- try {
172
- out = sh(dumpbin, ['/nologo', '/dependents', dllPath]);
173
- } catch (error) {
174
- out = typeof error?.stdout === 'string' ? error.stdout : '';
175
- }
176
- const deps = [];
177
- let inDeps = false;
178
- for (const raw of out.split(/\r?\n/)) {
179
- const line = raw.replace(/\s+$/, '');
180
- if (/following (delay load )?dependencies:/i.test(line)) {
181
- inDeps = true;
182
- continue;
183
- }
184
- if (/^\s*Summary/i.test(line)) break;
185
- if (inDeps) {
186
- const m = line.match(/^\s+([A-Za-z0-9_.+-]+\.dll)\s*$/i);
187
- if (m) deps.push(m[1]);
188
- }
189
- }
190
- return deps;
191
- }
192
-
193
- // --- 1. discover the closure ----------------------------------------------
194
- console.log(`build-gtk-runtime: gvsbuild prefix ${PREFIX}${WINDOWING ? ' (windowing superset)' : ' (display-free)'}`);
195
- // leaf(lower) -> actual on-disk filename in <prefix>/bin
196
- const binFiles = new Map();
197
- for (const f of readdirSync(gtkBin)) {
198
- if (f.toLowerCase().endsWith('.dll')) binFiles.set(f.toLowerCase(), f);
199
- }
200
- if (binFiles.size === 0) {
201
- console.error(`build-gtk-runtime: no DLLs under ${gtkBin} — is the GTK stack extracted?`);
202
- process.exit(1);
203
- }
204
-
205
- const seedPatterns = WINDOWING ? [...SEED_PATTERNS, ...WINDOWING_SEED_PATTERNS] : SEED_PATTERNS;
206
- const seeds = [...binFiles.values()].filter((f) => seedPatterns.some((re) => re.test(f)));
207
- if (seeds.length === 0) {
208
- console.error('build-gtk-runtime: no seed DLLs matched — check the gvsbuild layout / SEED_PATTERNS');
209
- process.exit(1);
210
- }
211
-
212
- // Windowing: the gdk-pixbuf loaders (SVG/PNG/… image decoders GTK dlopen's for
213
- // icons) live OUTSIDE bin/ — their backing libs (librsvg, …) must still land in
214
- // bin/, so seed the closure walk with each loader DLL so its dumpbin walk pulls them.
215
- const gdkPixbufLoaderDir = join(PREFIX, 'lib', 'gdk-pixbuf-2.0', '2.10.0', 'loaders');
216
- const loaderSeeds = [];
217
- if (WINDOWING && existsSync(gdkPixbufLoaderDir)) {
218
- for (const f of readdirSync(gdkPixbufLoaderDir)) {
219
- if (f.toLowerCase().endsWith('.dll')) loaderSeeds.push(join(gdkPixbufLoaderDir, f));
220
- }
221
- }
222
- console.log(`build-gtk-runtime: ${seeds.length} seed DLLs${loaderSeeds.length ? ` + ${loaderSeeds.length} pixbuf loaders` : ''}`);
223
-
224
- const dumpbin = findDumpbin();
225
- // leaf(lower) -> actual filename (source in <prefix>/bin); '\0loader:'-prefixed keys
226
- // are walked-but-not-bin-copied loader sentinels.
227
- const bundled = new Map();
228
- if (dumpbin) {
229
- console.log(`build-gtk-runtime: walking the DLL closure with ${dumpbin}`);
230
- // Seed with bin/ seeds (leaf names) + external loader DLLs (full paths) so THEIR
231
- // deps are walked into bin/ even though the loaders live outside bin/.
232
- const queue = [...seeds, ...loaderSeeds];
233
- while (queue.length) {
234
- const entry = queue.shift();
235
- const isPath = entry.includes('\\') || entry.includes('/');
236
- const leaf = isPath ? basename(entry) : entry;
237
- const lower = leaf.toLowerCase();
238
- const src = isPath ? entry : binFiles.get(lower);
239
- if (!src) continue; // system / non-gvsbuild dep — leave as OS-provided
240
- if (!isPath) {
241
- if (bundled.has(lower)) continue;
242
- bundled.set(lower, src);
243
- } else if (bundled.has('\0loader:' + lower)) {
244
- continue;
245
- } else {
246
- bundled.set('\0loader:' + lower, null); // walked, not bin-copied (copied below)
247
- }
248
- // dumpbin needs the ABSOLUTE path: a bin/ entry's `src` is a bare filename
249
- // (leaf), so resolve it under <prefix>/bin; a loader entry's `src` is already
250
- // a full path. Passing the bare leaf made dumpbin find nothing → the closure
251
- // never grew past the seeds → the transitive DLLs (ffi/intl/pcre2/zlib/…)
252
- // were dropped and the addon failed to dlopen.
253
- const walkPath = isPath ? src : join(gtkBin, src);
254
- for (const dep of dumpbinDeps(dumpbin, walkPath)) {
255
- const dl = dep.toLowerCase();
256
- if (!bundled.has(dl) && binFiles.has(dl)) queue.push(dep);
257
- }
258
- }
259
- } else {
260
- console.warn(
261
- 'build-gtk-runtime: WARNING — dumpbin not found (no MSVC / vswhere); falling back to copying the FULL bin/*.dll set (a complete but larger superset).',
262
- );
263
- for (const [lower, src] of binFiles) bundled.set(lower, src);
264
- }
265
- // Real bin/ DLLs only (drop the walked-loader sentinels).
266
- const binDlls = new Map([...bundled].filter(([k, v]) => v !== null && !k.startsWith('\0loader:')));
267
- console.log(`build-gtk-runtime: closure = ${binDlls.size} DLLs`);
268
-
269
- // --- 2. copy DLLs (no relocation — Windows resolves by search path) -------
270
- const binOut = join(OUT, 'bin');
271
- rmSync(OUT, { recursive: true, force: true });
272
- mkdirSync(binOut, { recursive: true });
273
- for (const src of binDlls.values()) {
274
- copyFileSync(join(gtkBin, src), join(binOut, src));
275
- }
276
- console.log(`build-gtk-runtime: copied ${binDlls.size} DLLs -> ${binOut}`);
277
-
278
- // --- 3. typelibs -----------------------------------------------------------
279
- const typelibOut = join(OUT, 'girepository-1.0');
280
- mkdirSync(typelibOut, { recursive: true });
281
- let typelibCount = 0;
282
- if (existsSync(gtkTypelibs)) {
283
- for (const f of readdirSync(gtkTypelibs)) {
284
- if (f.endsWith('.typelib')) {
285
- copyFileSync(join(gtkTypelibs, f), join(typelibOut, f));
286
- typelibCount++;
287
- }
288
- }
289
- }
290
- console.log(`build-gtk-runtime: copied ${typelibCount} typelibs`);
291
-
292
- // --- 4. WINDOWING data (loaders / schemas / icons / fonts) ----------------
293
- // Each step is independent + defensive: a missing tree/tool WARNS + continues so a
294
- // partial gvsbuild layout still produces the DLL+typelib bundle. The DATA marker
295
- // node-gi keys on is gschemas.compiled; if that step fails the loader treats the
296
- // bundle as display-free (no windowing env wired).
297
- const windowing = { pixbufLoaders: 0, schemas: false, iconThemes: [], fontconfig: false };
298
- if (WINDOWING) {
299
- // 4a. gdk-pixbuf loaders + a bundle-relative loaders.cache. The cache maps each
300
- // decoder DLL to its mime/extensions; gdk-pixbuf resolves the DLL paths in it
301
- // relative to GDK_PIXBUF_MODULEDIR when set (node-gi sets it), so we rewrite the
302
- // absolute build paths the query tool emits down to leaf names.
303
- if (existsSync(gdkPixbufLoaderDir)) {
304
- const loadersOut = join(OUT, 'lib', 'gdk-pixbuf-2.0', '2.10.0', 'loaders');
305
- mkdirSync(loadersOut, { recursive: true });
306
- for (const f of readdirSync(gdkPixbufLoaderDir)) {
307
- if (f.toLowerCase().endsWith('.dll')) {
308
- copyFileSync(join(gdkPixbufLoaderDir, f), join(loadersOut, f));
309
- windowing.pixbufLoaders++;
310
- }
311
- }
312
- const queryTool = findTool('gdk-pixbuf-query-loaders.exe', 'GDK_PIXBUF_QUERY_LOADERS');
313
- const cacheOut = join(OUT, 'lib', 'gdk-pixbuf-2.0', '2.10.0', 'loaders.cache');
314
- if (queryTool && windowing.pixbufLoaders > 0) {
315
- const loaderPaths = readdirSync(loadersOut)
316
- .filter((f) => f.toLowerCase().endsWith('.dll'))
317
- .map((f) => join(loadersOut, f));
318
- let cache = '';
319
- try {
320
- cache = sh(queryTool, loaderPaths);
321
- } catch (error) {
322
- cache = typeof error?.stdout === 'string' ? error.stdout : '';
323
- }
324
- // A loader header line is a quoted absolute path; strip it to the leaf so
325
- // GDK_PIXBUF_MODULEDIR resolves it in the consumer's bundle.
326
- const rel = cache.replace(/^"(.*[\\/])?([^"\\/]+\.dll)"\s*$/gim, '"$2"');
327
- writeFileSync(cacheOut, rel);
328
- console.log(`build-gtk-runtime: wrote loaders.cache (${windowing.pixbufLoaders} loaders, bundle-relative)`);
329
- } else {
330
- console.warn('build-gtk-runtime: WARNING — gdk-pixbuf-query-loaders not found; loaders.cache NOT generated (SVG/PNG icons may not load)');
331
- }
332
- } else {
333
- console.warn(`build-gtk-runtime: WARNING — ${gdkPixbufLoaderDir} missing; no gdk-pixbuf loaders bundled`);
334
- }
335
-
336
- // 4b. Compiled GSettings schemas (GTK/Adwaita read org.gnome.desktop.interface
337
- // etc. at startup). Copy every schema found (GTK's own + gsettings-desktop-
338
- // schemas if gvsbuild shipped it) and (re)compile gschemas.compiled.
339
- const schemasSrc = join(PREFIX, 'share', 'glib-2.0', 'schemas');
340
- if (existsSync(schemasSrc)) {
341
- const schemasOut = join(OUT, 'share', 'glib-2.0', 'schemas');
342
- mkdirSync(schemasOut, { recursive: true });
343
- for (const f of readdirSync(schemasSrc)) {
344
- if (f.endsWith('.xml') || f.endsWith('.gschema.override') || f === 'gschemas.compiled') {
345
- copyFileSync(join(schemasSrc, f), join(schemasOut, f));
346
- }
347
- }
348
- const compileTool = findTool('glib-compile-schemas.exe', 'GLIB_COMPILE_SCHEMAS');
349
- if (compileTool) {
350
- try {
351
- sh(compileTool, [schemasOut]);
352
- } catch (error) {
353
- console.warn(`build-gtk-runtime: WARNING — glib-compile-schemas failed: ${error?.message ?? error}`);
354
- }
355
- }
356
- windowing.schemas = existsSync(join(schemasOut, 'gschemas.compiled'));
357
- console.log(`build-gtk-runtime: GSettings schemas ${windowing.schemas ? 'compiled' : 'copied (no gschemas.compiled!)'}`);
358
- } else {
359
- console.warn(`build-gtk-runtime: WARNING — ${schemasSrc} missing; GSettings schemas NOT bundled (GTK settings reads will fail)`);
360
- }
361
-
362
- // 4c. Icon themes (Adwaita for symbolic icons + hicolor fallback) + caches. The
363
- // theme is loaded from XDG_DATA_DIRS/icons/<theme>/ (node-gi prepends <bundle>/share).
364
- const updateIconCache = findTool('gtk4-update-icon-cache.exe', 'GTK4_UPDATE_ICON_CACHE')
365
- ?? findTool('gtk-update-icon-cache.exe', 'GTK_UPDATE_ICON_CACHE');
366
- for (const theme of ['Adwaita', 'hicolor']) {
367
- const themeSrc = join(PREFIX, 'share', 'icons', theme);
368
- if (!existsSync(themeSrc)) continue;
369
- const themeOut = join(OUT, 'share', 'icons', theme);
370
- cpSync(themeSrc, themeOut, { recursive: true });
371
- if (updateIconCache) {
372
- try {
373
- sh(updateIconCache, ['-q', '-t', '-f', themeOut]);
374
- } catch {
375
- // an existing icon-theme.cache from the copy is a usable fallback
376
- }
377
- }
378
- windowing.iconThemes.push(theme);
379
- }
380
- console.log(
381
- windowing.iconThemes.length
382
- ? `build-gtk-runtime: icon themes ${windowing.iconThemes.join(', ')}${updateIconCache ? ' (cache refreshed)' : ' (no update-icon-cache tool — copied caches)'}`
383
- : 'build-gtk-runtime: WARNING — no Adwaita/hicolor icon theme found under share/icons (symbolic icons may be blank)',
384
- );
385
-
386
- // 4d. Fontconfig config + cache. GTK4-on-Windows text usually goes through the
387
- // DirectWrite/pangowin32 backend (no fontconfig), but gvsbuild's pango can be
388
- // fontconfig-backed; ship etc/fonts + a cache when present so either path works.
389
- const fontsSrc = join(PREFIX, 'etc', 'fonts');
390
- if (existsSync(fontsSrc)) {
391
- const fontsOut = join(OUT, 'etc', 'fonts');
392
- cpSync(fontsSrc, fontsOut, { recursive: true });
393
- const fcCache = findTool('fc-cache.exe', 'FC_CACHE');
394
- if (fcCache) {
395
- try {
396
- sh(fcCache, ['-f', fontsOut], { env: { ...process.env, FONTCONFIG_PATH: fontsOut } });
397
- } catch {
398
- // best-effort — Pango's win32 backend does not need the cache
399
- }
400
- }
401
- windowing.fontconfig = true;
402
- console.log('build-gtk-runtime: fontconfig config bundled');
403
- } else {
404
- console.log('build-gtk-runtime: no etc/fonts (pango uses the win32/DirectWrite backend) — skipping fontconfig');
405
- }
406
- }
407
-
408
- // --- manifest + size -------------------------------------------------------
409
- function dirSize(dir) {
410
- if (!existsSync(dir)) return 0;
411
- let total = 0;
412
- for (const f of readdirSync(dir, { withFileTypes: true })) {
413
- const p = join(dir, f.name);
414
- total += f.isDirectory() ? dirSize(p) : statSync(p).size;
415
- }
416
- return total;
417
- }
418
- const binBytes = dirSize(binOut);
419
- const typelibBytes = dirSize(typelibOut);
420
- const dataBytes = WINDOWING ? dirSize(join(OUT, 'lib')) + dirSize(join(OUT, 'share')) + dirSize(join(OUT, 'etc')) : 0;
421
- const manifest = {
422
- platform: 'win32-x64',
423
- windowing: WINDOWING,
424
- generatedFrom: PREFIX,
425
- walkedWith: dumpbin ? 'dumpbin' : 'copy-all-fallback',
426
- dlls: binDlls.size,
427
- typelibs: typelibCount,
428
- binBytes,
429
- typelibBytes,
430
- dataBytes,
431
- totalBytes: binBytes + typelibBytes + dataBytes,
432
- dllList: [...binDlls.values()].map((f) => basename(f)).sort((a, b) => a.localeCompare(b)),
433
- ...(WINDOWING ? { windowingData: windowing } : {}),
434
- };
435
- writeFileSync(join(OUT, 'manifest.json'), JSON.stringify(manifest, null, 2));
436
-
437
- const mb = (n) => (n / 1024 / 1024).toFixed(1);
438
- console.log(
439
- `build-gtk-runtime: DONE -> ${OUT}\n` +
440
- ` DLLs: ${binDlls.size} (${mb(binBytes)} MiB)\n` +
441
- ` typelibs: ${typelibCount} (${mb(typelibBytes)} MiB)\n` +
442
- (WINDOWING
443
- ? ` data: loaders=${windowing.pixbufLoaders} schemas=${windowing.schemas} icons=[${windowing.iconThemes.join(',')}] fontconfig=${windowing.fontconfig} (${mb(dataBytes)} MiB)\n`
444
- : '') +
445
- ` total: ${mb(manifest.totalBytes)} MiB`,
446
- );
1
+ // SPDX-License-Identifier: MIT
2
+ // Collect a standalone, batteries-included GTK/GObject-Introspection runtime
3
+ // bundle for Windows x64 — so @gjsify/node-gi loads gi:// namespaces with NO
4
+ // gvsbuild/system GTK on the host (the Windows sibling of the darwin-arm64 bundle).
5
+ //
6
+ // node scripts/build-gtk-runtime.mjs [--out <dir>] [--prefix <gvsbuild GTK prefix>] [--windowing]
7
+ //
8
+ // Two closures, one bundle dir:
9
+ // • DEFAULT (display-free) — the loadable DLLs + typelibs the DISPLAY-FREE
10
+ // conformance needs (GLib/GObject/Gio/cairo/Pango/Graphene/Gdk). Unchanged.
11
+ // • --windowing (SUPERSET) — everything above PLUS the runtime data a REAL GTK
12
+ // WINDOW needs on Windows: the gdk-pixbuf loaders + `loaders.cache`, compiled
13
+ // GSettings schemas (`gschemas.compiled`), the Adwaita/hicolor icon themes +
14
+ // `icon-theme.cache`, and the Fontconfig config/cache. The extra image-loader
15
+ // backing DLLs (librsvg/png/…) are walked into `bin/` too. node-gi's loader
16
+ // (gtk-runtime.js) detects the windowing data (the `gschemas.compiled` marker)
17
+ // and wires the env (GSETTINGS_SCHEMA_DIR / GDK_PIXBUF_MODULE_FILE /
18
+ // XDG_DATA_DIRS / FONTCONFIG_*) so the SAME loader serves both — the display-free
19
+ // path is byte-unchanged when the windowing data is absent.
20
+ //
21
+ // Runs ONLY on win32/x64 with a build-time gvsbuild GTK4 stack extracted at
22
+ // --prefix (env GTK_PREFIX, the closure *source*, not shipped — the same tree the
23
+ // node-gi.yml windows jobs cache at C:\gtk-build\gtk\x64\release). gvsbuild bundles
24
+ // the tools this needs (gdk-pixbuf-query-loaders / glib-compile-schemas /
25
+ // gtk4-update-icon-cache / fc-cache) in <prefix>/bin.
26
+ //
27
+ // CRUCIAL DIFFERENCE FROM macOS: there is NO relocation step (no install_name_tool,
28
+ // no @rpath, no codesign). Windows resolves a DLL's imports by SEARCH PATH at
29
+ // LoadLibrary time, so a bundle is "portable" the moment its DLLs sit in one dir —
30
+ // node-gi just prepends <out>/bin to PATH before the addon loads. The runtime DATA
31
+ // (loaders/schemas/icons/fonts) is likewise resolved by env vars set at load time,
32
+ // no baked absolute paths (the caches are rewritten to bundle-relative).
33
+ //
34
+ // Reference: GJS ships no relocation; gvsbuild ships the MSVC-ABI GTK4 stack whose
35
+ // DLLs load into stock (MSVC-ABI) Node.
36
+ import { execFileSync } from 'node:child_process';
37
+ import {
38
+ copyFileSync,
39
+ cpSync,
40
+ existsSync,
41
+ mkdirSync,
42
+ readdirSync,
43
+ rmSync,
44
+ statSync,
45
+ writeFileSync,
46
+ } from 'node:fs';
47
+ import { basename, dirname, join } from 'node:path';
48
+ import { fileURLToPath } from 'node:url';
49
+
50
+ const pkgRoot = dirname(dirname(fileURLToPath(import.meta.url)));
51
+
52
+ // --- args ------------------------------------------------------------------
53
+ function argValue(flag) {
54
+ const i = process.argv.indexOf(flag);
55
+ return i >= 0 && i + 1 < process.argv.length ? process.argv[i + 1] : undefined;
56
+ }
57
+ const OUT = argValue('--out') ?? join(pkgRoot, 'gtk');
58
+ const PREFIX = argValue('--prefix') ?? process.env.GTK_PREFIX;
59
+ // The full-windowing SUPERSET: also collect the runtime data a real GTK window needs.
60
+ const WINDOWING = process.argv.includes('--windowing');
61
+
62
+ if (process.platform !== 'win32' || process.arch !== 'x64') {
63
+ console.error(`build-gtk-runtime: only supported on win32/x64, not ${process.platform}/${process.arch}`);
64
+ process.exit(2);
65
+ }
66
+ if (!PREFIX) {
67
+ console.error('build-gtk-runtime: no GTK prefix — pass --prefix or set GTK_PREFIX (e.g. C:\\gtk-build\\gtk\\x64\\release)');
68
+ process.exit(1);
69
+ }
70
+
71
+ const gtkBin = join(PREFIX, 'bin');
72
+ const gtkTypelibs = join(PREFIX, 'lib', 'girepository-1.0');
73
+ if (!existsSync(gtkBin)) {
74
+ console.error(`build-gtk-runtime: ${gtkBin} not found — extract the gvsbuild GTK4 stack first`);
75
+ process.exit(1);
76
+ }
77
+
78
+ const sh = (bin, args, opts) => execFileSync(bin, args, { encoding: 'utf8', ...opts });
79
+
80
+ // The seed DLLs of the DISPLAY-FREE conformance closure. Liberal, version-agnostic
81
+ // patterns matched against <prefix>/bin (gvsbuild's suffixes drift: glib-2.0-0.dll,
82
+ // girepository-2.0-0.dll, cairo-2.dll, pango-1.0-0.dll, gdk_pixbuf-2.0-0.dll,
83
+ // gtk-4-1.dll, harfbuzz.dll, …). The recursive dumpbin walk pulls every transitive
84
+ // gvsbuild dep (harfbuzz, fribidi, fontconfig, freetype, pixman, png, intl, pcre2,
85
+ // ffi, epoxy, zlib, …). gtk-4 is seeded because it backs the Gdk typelib the
86
+ // conformance's struct-construct loads (Gdk/Graphene) and transitively pulls
87
+ // pango/graphene/gdk-pixbuf/cairo/harfbuzz.
88
+ const SEED_PATTERNS = [
89
+ /^glib-2\.0-.*\.dll$/i,
90
+ /^gobject-2\.0-.*\.dll$/i,
91
+ /^gio-2\.0-.*\.dll$/i,
92
+ /^gmodule-2\.0-.*\.dll$/i,
93
+ /^girepository-[12]\.0-.*\.dll$/i, // girepository-2.0 (merged API) on modern gvsbuild
94
+ /^cairo(-gobject|-script-interpreter)?-?\d*\.dll$/i,
95
+ /^pango(cairo|ft2|win32)?-1\.0-.*\.dll$/i,
96
+ /^graphene-1\.0-.*\.dll$/i,
97
+ /^gdk[-_]pixbuf-2\.0-.*\.dll$/i,
98
+ /^gtk-4-.*\.dll$/i, // provides the Gdk typelib's backing library
99
+ /^harfbuzz.*\.dll$/i,
100
+ ];
101
+
102
+ // Extra seeds for the WINDOWING superset: libadwaita (the Adw-1 typelib's backing
103
+ // DLL — a real Adw.Application/ApplicationWindow needs it; the display-free
104
+ // conformance never touches Adwaita, so it is NOT in the base seeds), the GL backing
105
+ // a GSK GL renderer picks (ANGLE libEGL/libGLESv2 + epoxy — the cairo renderer needs
106
+ // none, but a real window may negotiate GL), and librsvg (the SVG gdk-pixbuf loader
107
+ // that renders the Adwaita symbolic icons). Most GL/rsvg deps are pulled transitively
108
+ // by the loaders below; naming them keeps the closure complete even if a loader is
109
+ // missing. (Gdk/Gsk/Gtk are all in gtk-4-*.dll, already a base seed.)
110
+ const WINDOWING_SEED_PATTERNS = [
111
+ /^(lib)?adwaita-1.*\.dll$/i, // gvsbuild leaf: adwaita-1-0.dll (backs the Adw-1 typelib)
112
+ /^libEGL.*\.dll$/i,
113
+ /^libGLESv2.*\.dll$/i,
114
+ /^epoxy.*\.dll$/i,
115
+ /^rsvg.*\.dll$/i,
116
+ /^libxml2.*\.dll$/i,
117
+ ];
118
+
119
+ // Locate an MSVC/gvsbuild tool: env override, then the gvsbuild <prefix>/bin
120
+ // (gvsbuild ships gdk-pixbuf-query-loaders / glib-compile-schemas /
121
+ // gtk4-update-icon-cache / fc-cache there), then PATH. Null when absent.
122
+ function findTool(leaf, envVar) {
123
+ const envd = envVar && process.env[envVar];
124
+ if (envd && existsSync(envd)) return envd;
125
+ const inBin = join(gtkBin, leaf);
126
+ if (existsSync(inBin)) return inBin;
127
+ try {
128
+ const p = sh('where', [leaf.replace(/\.exe$/i, '')]).split(/\r?\n/).map((s) => s.trim()).filter(Boolean)[0];
129
+ if (p && existsSync(p)) return p;
130
+ } catch {
131
+ // not on PATH
132
+ }
133
+ return null;
134
+ }
135
+
136
+ // Locate dumpbin (MSVC): env override, then PATH (a dev-cmd/vcvars job), then
137
+ // vswhere's -find glob into the VC toolchain. Null when unavailable → the caller
138
+ // falls back to copying the whole bin/ DLL set.
139
+ function findDumpbin() {
140
+ const envd = process.env.DUMPBIN;
141
+ if (envd && existsSync(envd)) return envd;
142
+ try {
143
+ const p = sh('where', ['dumpbin']).split(/\r?\n/).map((s) => s.trim()).filter(Boolean)[0];
144
+ if (p && existsSync(p)) return p;
145
+ } catch {
146
+ // not on PATH
147
+ }
148
+ const vswhere = join(
149
+ process.env['ProgramFiles(x86)'] || 'C:\\Program Files (x86)',
150
+ 'Microsoft Visual Studio',
151
+ 'Installer',
152
+ 'vswhere.exe',
153
+ );
154
+ if (existsSync(vswhere)) {
155
+ try {
156
+ const out = sh(vswhere, ['-latest', '-products', '*', '-find', '**\\Hostx64\\x64\\dumpbin.exe']);
157
+ const p = out.split(/\r?\n/).map((s) => s.trim()).filter(Boolean)[0];
158
+ if (p && existsSync(p)) return p;
159
+ } catch {
160
+ // vswhere present but no match
161
+ }
162
+ }
163
+ return null;
164
+ }
165
+
166
+ // Parse `dumpbin /dependents <dll>` into the list of imported DLL leaf names (both
167
+ // normal + delay-load sections; stop at the Summary). Exit-tolerant: dumpbin can
168
+ // print the section then exit non-zero on some inputs — capture the attached stdout.
169
+ function dumpbinDeps(dumpbin, dllPath) {
170
+ let out;
171
+ try {
172
+ out = sh(dumpbin, ['/nologo', '/dependents', dllPath]);
173
+ } catch (error) {
174
+ out = typeof error?.stdout === 'string' ? error.stdout : '';
175
+ }
176
+ const deps = [];
177
+ let inDeps = false;
178
+ for (const raw of out.split(/\r?\n/)) {
179
+ const line = raw.replace(/\s+$/, '');
180
+ if (/following (delay load )?dependencies:/i.test(line)) {
181
+ inDeps = true;
182
+ continue;
183
+ }
184
+ if (/^\s*Summary/i.test(line)) break;
185
+ if (inDeps) {
186
+ const m = line.match(/^\s+([A-Za-z0-9_.+-]+\.dll)\s*$/i);
187
+ if (m) deps.push(m[1]);
188
+ }
189
+ }
190
+ return deps;
191
+ }
192
+
193
+ // --- 1. discover the closure ----------------------------------------------
194
+ console.log(`build-gtk-runtime: gvsbuild prefix ${PREFIX}${WINDOWING ? ' (windowing superset)' : ' (display-free)'}`);
195
+ // leaf(lower) -> actual on-disk filename in <prefix>/bin
196
+ const binFiles = new Map();
197
+ for (const f of readdirSync(gtkBin)) {
198
+ if (f.toLowerCase().endsWith('.dll')) binFiles.set(f.toLowerCase(), f);
199
+ }
200
+ if (binFiles.size === 0) {
201
+ console.error(`build-gtk-runtime: no DLLs under ${gtkBin} — is the GTK stack extracted?`);
202
+ process.exit(1);
203
+ }
204
+
205
+ const seedPatterns = WINDOWING ? [...SEED_PATTERNS, ...WINDOWING_SEED_PATTERNS] : SEED_PATTERNS;
206
+ const seeds = [...binFiles.values()].filter((f) => seedPatterns.some((re) => re.test(f)));
207
+ if (seeds.length === 0) {
208
+ console.error('build-gtk-runtime: no seed DLLs matched — check the gvsbuild layout / SEED_PATTERNS');
209
+ process.exit(1);
210
+ }
211
+
212
+ // Windowing: the gdk-pixbuf loaders (SVG/PNG/… image decoders GTK dlopen's for
213
+ // icons) live OUTSIDE bin/ — their backing libs (librsvg, …) must still land in
214
+ // bin/, so seed the closure walk with each loader DLL so its dumpbin walk pulls them.
215
+ const gdkPixbufLoaderDir = join(PREFIX, 'lib', 'gdk-pixbuf-2.0', '2.10.0', 'loaders');
216
+ const loaderSeeds = [];
217
+ if (WINDOWING && existsSync(gdkPixbufLoaderDir)) {
218
+ for (const f of readdirSync(gdkPixbufLoaderDir)) {
219
+ if (f.toLowerCase().endsWith('.dll')) loaderSeeds.push(join(gdkPixbufLoaderDir, f));
220
+ }
221
+ }
222
+ console.log(`build-gtk-runtime: ${seeds.length} seed DLLs${loaderSeeds.length ? ` + ${loaderSeeds.length} pixbuf loaders` : ''}`);
223
+
224
+ const dumpbin = findDumpbin();
225
+ // leaf(lower) -> actual filename (source in <prefix>/bin); '\0loader:'-prefixed keys
226
+ // are walked-but-not-bin-copied loader sentinels.
227
+ const bundled = new Map();
228
+ if (dumpbin) {
229
+ console.log(`build-gtk-runtime: walking the DLL closure with ${dumpbin}`);
230
+ // Seed with bin/ seeds (leaf names) + external loader DLLs (full paths) so THEIR
231
+ // deps are walked into bin/ even though the loaders live outside bin/.
232
+ const queue = [...seeds, ...loaderSeeds];
233
+ while (queue.length) {
234
+ const entry = queue.shift();
235
+ const isPath = entry.includes('\\') || entry.includes('/');
236
+ const leaf = isPath ? basename(entry) : entry;
237
+ const lower = leaf.toLowerCase();
238
+ const src = isPath ? entry : binFiles.get(lower);
239
+ if (!src) continue; // system / non-gvsbuild dep — leave as OS-provided
240
+ if (!isPath) {
241
+ if (bundled.has(lower)) continue;
242
+ bundled.set(lower, src);
243
+ } else if (bundled.has('\0loader:' + lower)) {
244
+ continue;
245
+ } else {
246
+ bundled.set('\0loader:' + lower, null); // walked, not bin-copied (copied below)
247
+ }
248
+ // dumpbin needs the ABSOLUTE path: a bin/ entry's `src` is a bare filename
249
+ // (leaf), so resolve it under <prefix>/bin; a loader entry's `src` is already
250
+ // a full path. Passing the bare leaf made dumpbin find nothing → the closure
251
+ // never grew past the seeds → the transitive DLLs (ffi/intl/pcre2/zlib/…)
252
+ // were dropped and the addon failed to dlopen.
253
+ const walkPath = isPath ? src : join(gtkBin, src);
254
+ for (const dep of dumpbinDeps(dumpbin, walkPath)) {
255
+ const dl = dep.toLowerCase();
256
+ if (!bundled.has(dl) && binFiles.has(dl)) queue.push(dep);
257
+ }
258
+ }
259
+ } else {
260
+ console.warn(
261
+ 'build-gtk-runtime: WARNING — dumpbin not found (no MSVC / vswhere); falling back to copying the FULL bin/*.dll set (a complete but larger superset).',
262
+ );
263
+ for (const [lower, src] of binFiles) bundled.set(lower, src);
264
+ }
265
+ // Real bin/ DLLs only (drop the walked-loader sentinels).
266
+ const binDlls = new Map([...bundled].filter(([k, v]) => v !== null && !k.startsWith('\0loader:')));
267
+ console.log(`build-gtk-runtime: closure = ${binDlls.size} DLLs`);
268
+
269
+ // --- 2. copy DLLs (no relocation — Windows resolves by search path) -------
270
+ const binOut = join(OUT, 'bin');
271
+ rmSync(OUT, { recursive: true, force: true });
272
+ mkdirSync(binOut, { recursive: true });
273
+ for (const src of binDlls.values()) {
274
+ copyFileSync(join(gtkBin, src), join(binOut, src));
275
+ }
276
+ console.log(`build-gtk-runtime: copied ${binDlls.size} DLLs -> ${binOut}`);
277
+
278
+ // --- 3. typelibs -----------------------------------------------------------
279
+ const typelibOut = join(OUT, 'girepository-1.0');
280
+ mkdirSync(typelibOut, { recursive: true });
281
+ let typelibCount = 0;
282
+ if (existsSync(gtkTypelibs)) {
283
+ for (const f of readdirSync(gtkTypelibs)) {
284
+ if (f.endsWith('.typelib')) {
285
+ copyFileSync(join(gtkTypelibs, f), join(typelibOut, f));
286
+ typelibCount++;
287
+ }
288
+ }
289
+ }
290
+ console.log(`build-gtk-runtime: copied ${typelibCount} typelibs`);
291
+
292
+ // --- 4. WINDOWING data (loaders / schemas / icons / fonts) ----------------
293
+ // Each step is independent + defensive: a missing tree/tool WARNS + continues so a
294
+ // partial gvsbuild layout still produces the DLL+typelib bundle. The DATA marker
295
+ // node-gi keys on is gschemas.compiled; if that step fails the loader treats the
296
+ // bundle as display-free (no windowing env wired).
297
+ const windowing = { pixbufLoaders: 0, schemas: false, iconThemes: [], fontconfig: false };
298
+ if (WINDOWING) {
299
+ // 4a. gdk-pixbuf loaders + a bundle-relative loaders.cache. The cache maps each
300
+ // decoder DLL to its mime/extensions; gdk-pixbuf resolves the DLL paths in it
301
+ // relative to GDK_PIXBUF_MODULEDIR when set (node-gi sets it), so we rewrite the
302
+ // absolute build paths the query tool emits down to leaf names.
303
+ if (existsSync(gdkPixbufLoaderDir)) {
304
+ const loadersOut = join(OUT, 'lib', 'gdk-pixbuf-2.0', '2.10.0', 'loaders');
305
+ mkdirSync(loadersOut, { recursive: true });
306
+ for (const f of readdirSync(gdkPixbufLoaderDir)) {
307
+ if (f.toLowerCase().endsWith('.dll')) {
308
+ copyFileSync(join(gdkPixbufLoaderDir, f), join(loadersOut, f));
309
+ windowing.pixbufLoaders++;
310
+ }
311
+ }
312
+ const queryTool = findTool('gdk-pixbuf-query-loaders.exe', 'GDK_PIXBUF_QUERY_LOADERS');
313
+ const cacheOut = join(OUT, 'lib', 'gdk-pixbuf-2.0', '2.10.0', 'loaders.cache');
314
+ if (queryTool && windowing.pixbufLoaders > 0) {
315
+ const loaderPaths = readdirSync(loadersOut)
316
+ .filter((f) => f.toLowerCase().endsWith('.dll'))
317
+ .map((f) => join(loadersOut, f));
318
+ let cache = '';
319
+ try {
320
+ cache = sh(queryTool, loaderPaths);
321
+ } catch (error) {
322
+ cache = typeof error?.stdout === 'string' ? error.stdout : '';
323
+ }
324
+ // A loader header line is a quoted absolute path; strip it to the leaf so
325
+ // GDK_PIXBUF_MODULEDIR resolves it in the consumer's bundle.
326
+ const rel = cache.replace(/^"(.*[\\/])?([^"\\/]+\.dll)"\s*$/gim, '"$2"');
327
+ writeFileSync(cacheOut, rel);
328
+ console.log(`build-gtk-runtime: wrote loaders.cache (${windowing.pixbufLoaders} loaders, bundle-relative)`);
329
+ } else {
330
+ console.warn('build-gtk-runtime: WARNING — gdk-pixbuf-query-loaders not found; loaders.cache NOT generated (SVG/PNG icons may not load)');
331
+ }
332
+ } else {
333
+ console.warn(`build-gtk-runtime: WARNING — ${gdkPixbufLoaderDir} missing; no gdk-pixbuf loaders bundled`);
334
+ }
335
+
336
+ // 4b. Compiled GSettings schemas (GTK/Adwaita read org.gnome.desktop.interface
337
+ // etc. at startup). Copy every schema found (GTK's own + gsettings-desktop-
338
+ // schemas if gvsbuild shipped it) and (re)compile gschemas.compiled.
339
+ const schemasSrc = join(PREFIX, 'share', 'glib-2.0', 'schemas');
340
+ if (existsSync(schemasSrc)) {
341
+ const schemasOut = join(OUT, 'share', 'glib-2.0', 'schemas');
342
+ mkdirSync(schemasOut, { recursive: true });
343
+ for (const f of readdirSync(schemasSrc)) {
344
+ if (f.endsWith('.xml') || f.endsWith('.gschema.override') || f === 'gschemas.compiled') {
345
+ copyFileSync(join(schemasSrc, f), join(schemasOut, f));
346
+ }
347
+ }
348
+ const compileTool = findTool('glib-compile-schemas.exe', 'GLIB_COMPILE_SCHEMAS');
349
+ if (compileTool) {
350
+ try {
351
+ sh(compileTool, [schemasOut]);
352
+ } catch (error) {
353
+ console.warn(`build-gtk-runtime: WARNING — glib-compile-schemas failed: ${error?.message ?? error}`);
354
+ }
355
+ }
356
+ windowing.schemas = existsSync(join(schemasOut, 'gschemas.compiled'));
357
+ console.log(`build-gtk-runtime: GSettings schemas ${windowing.schemas ? 'compiled' : 'copied (no gschemas.compiled!)'}`);
358
+ } else {
359
+ console.warn(`build-gtk-runtime: WARNING — ${schemasSrc} missing; GSettings schemas NOT bundled (GTK settings reads will fail)`);
360
+ }
361
+
362
+ // 4c. Icon themes (Adwaita for symbolic icons + hicolor fallback) + caches. The
363
+ // theme is loaded from XDG_DATA_DIRS/icons/<theme>/ (node-gi prepends <bundle>/share).
364
+ const updateIconCache = findTool('gtk4-update-icon-cache.exe', 'GTK4_UPDATE_ICON_CACHE')
365
+ ?? findTool('gtk-update-icon-cache.exe', 'GTK_UPDATE_ICON_CACHE');
366
+ for (const theme of ['Adwaita', 'hicolor']) {
367
+ const themeSrc = join(PREFIX, 'share', 'icons', theme);
368
+ if (!existsSync(themeSrc)) continue;
369
+ const themeOut = join(OUT, 'share', 'icons', theme);
370
+ cpSync(themeSrc, themeOut, { recursive: true });
371
+ if (updateIconCache) {
372
+ try {
373
+ sh(updateIconCache, ['-q', '-t', '-f', themeOut]);
374
+ } catch {
375
+ // an existing icon-theme.cache from the copy is a usable fallback
376
+ }
377
+ }
378
+ windowing.iconThemes.push(theme);
379
+ }
380
+ console.log(
381
+ windowing.iconThemes.length
382
+ ? `build-gtk-runtime: icon themes ${windowing.iconThemes.join(', ')}${updateIconCache ? ' (cache refreshed)' : ' (no update-icon-cache tool — copied caches)'}`
383
+ : 'build-gtk-runtime: WARNING — no Adwaita/hicolor icon theme found under share/icons (symbolic icons may be blank)',
384
+ );
385
+
386
+ // 4d. Fontconfig config + cache. GTK4-on-Windows text usually goes through the
387
+ // DirectWrite/pangowin32 backend (no fontconfig), but gvsbuild's pango can be
388
+ // fontconfig-backed; ship etc/fonts + a cache when present so either path works.
389
+ const fontsSrc = join(PREFIX, 'etc', 'fonts');
390
+ if (existsSync(fontsSrc)) {
391
+ const fontsOut = join(OUT, 'etc', 'fonts');
392
+ cpSync(fontsSrc, fontsOut, { recursive: true });
393
+ const fcCache = findTool('fc-cache.exe', 'FC_CACHE');
394
+ if (fcCache) {
395
+ try {
396
+ sh(fcCache, ['-f', fontsOut], { env: { ...process.env, FONTCONFIG_PATH: fontsOut } });
397
+ } catch {
398
+ // best-effort — Pango's win32 backend does not need the cache
399
+ }
400
+ }
401
+ windowing.fontconfig = true;
402
+ console.log('build-gtk-runtime: fontconfig config bundled');
403
+ } else {
404
+ console.log('build-gtk-runtime: no etc/fonts (pango uses the win32/DirectWrite backend) — skipping fontconfig');
405
+ }
406
+ }
407
+
408
+ // --- manifest + size -------------------------------------------------------
409
+ function dirSize(dir) {
410
+ if (!existsSync(dir)) return 0;
411
+ let total = 0;
412
+ for (const f of readdirSync(dir, { withFileTypes: true })) {
413
+ const p = join(dir, f.name);
414
+ total += f.isDirectory() ? dirSize(p) : statSync(p).size;
415
+ }
416
+ return total;
417
+ }
418
+ const binBytes = dirSize(binOut);
419
+ const typelibBytes = dirSize(typelibOut);
420
+ const dataBytes = WINDOWING ? dirSize(join(OUT, 'lib')) + dirSize(join(OUT, 'share')) + dirSize(join(OUT, 'etc')) : 0;
421
+ const manifest = {
422
+ platform: 'win32-x64',
423
+ windowing: WINDOWING,
424
+ generatedFrom: PREFIX,
425
+ walkedWith: dumpbin ? 'dumpbin' : 'copy-all-fallback',
426
+ dlls: binDlls.size,
427
+ typelibs: typelibCount,
428
+ binBytes,
429
+ typelibBytes,
430
+ dataBytes,
431
+ totalBytes: binBytes + typelibBytes + dataBytes,
432
+ dllList: [...binDlls.values()].map((f) => basename(f)).sort((a, b) => a.localeCompare(b)),
433
+ ...(WINDOWING ? { windowingData: windowing } : {}),
434
+ };
435
+ writeFileSync(join(OUT, 'manifest.json'), JSON.stringify(manifest, null, 2));
436
+
437
+ const mb = (n) => (n / 1024 / 1024).toFixed(1);
438
+ console.log(
439
+ `build-gtk-runtime: DONE -> ${OUT}\n` +
440
+ ` DLLs: ${binDlls.size} (${mb(binBytes)} MiB)\n` +
441
+ ` typelibs: ${typelibCount} (${mb(typelibBytes)} MiB)\n` +
442
+ (WINDOWING
443
+ ? ` data: loaders=${windowing.pixbufLoaders} schemas=${windowing.schemas} icons=[${windowing.iconThemes.join(',')}] fontconfig=${windowing.fontconfig} (${mb(dataBytes)} MiB)\n`
444
+ : '') +
445
+ ` total: ${mb(manifest.totalBytes)} MiB`,
446
+ );