xbintsc 0.6.22 → 0.6.23

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 (166) hide show
  1. package/AGENTS.md +5 -0
  2. package/dist/src/cli/help.d.ts +1 -1
  3. package/dist/src/driver/build-key.js +2 -1
  4. package/dist/src/driver/build-key.js.map +1 -1
  5. package/dist/src/driver/fingerprint.d.ts +11 -0
  6. package/dist/src/driver/fingerprint.js +25 -0
  7. package/dist/src/driver/fingerprint.js.map +1 -1
  8. package/dist/src/driver/link-features.js +36 -11
  9. package/dist/src/driver/link-features.js.map +1 -1
  10. package/dist/src/driver/paths.d.ts +10 -0
  11. package/dist/src/driver/paths.js +18 -0
  12. package/dist/src/driver/paths.js.map +1 -1
  13. package/dist/src/driver/runtime-objects.d.ts +1 -1
  14. package/dist/src/driver/runtime-objects.js +22 -6
  15. package/dist/src/driver/runtime-objects.js.map +1 -1
  16. package/dist/src/driver/toolchain.d.ts +1 -1
  17. package/dist/src/driver/toolchain.js +10 -1
  18. package/dist/src/driver/toolchain.js.map +1 -1
  19. package/dist/src/driver/version.d.ts +1 -1
  20. package/dist/src/driver/version.js +1 -1
  21. package/dist/src/extensions/node/http2/feature.d.ts +14 -0
  22. package/dist/src/extensions/node/http2/feature.js +28 -0
  23. package/dist/src/extensions/node/http2/feature.js.map +1 -0
  24. package/dist/src/extensions/node/http2/index.d.ts +5 -1
  25. package/dist/src/extensions/node/http2/index.js +6 -1
  26. package/dist/src/extensions/node/http2/index.js.map +1 -1
  27. package/dist/src/extensions/node/index.js +3 -1
  28. package/dist/src/extensions/node/index.js.map +1 -1
  29. package/dist/src/extensions/node/tls/feature.d.ts +12 -0
  30. package/dist/src/extensions/node/tls/feature.js +24 -0
  31. package/dist/src/extensions/node/tls/feature.js.map +1 -0
  32. package/dist/src/extensions/node/tls/index.d.ts +5 -1
  33. package/dist/src/extensions/node/tls/index.js +5 -1
  34. package/dist/src/extensions/node/tls/index.js.map +1 -1
  35. package/dist/src/extensions/node/zlib/compression.js +11 -6
  36. package/dist/src/extensions/node/zlib/compression.js.map +1 -1
  37. package/dist/src/extensions/registry.js +2 -1
  38. package/dist/src/extensions/registry.js.map +1 -1
  39. package/dist/src/extensions/storage.js +4 -3
  40. package/dist/src/extensions/storage.js.map +1 -1
  41. package/dist/src/extensions/tls.d.ts +26 -0
  42. package/dist/src/extensions/tls.js +46 -0
  43. package/dist/src/extensions/tls.js.map +1 -0
  44. package/dist/tests/driver/link-features.test.js +9 -0
  45. package/dist/tests/driver/link-features.test.js.map +1 -1
  46. package/dist/tests/e2e/fetch.test.js +3 -1
  47. package/dist/tests/e2e/fetch.test.js.map +1 -1
  48. package/dist/tests/e2e/http2.test.d.ts +7 -0
  49. package/dist/tests/e2e/http2.test.js +201 -0
  50. package/dist/tests/e2e/http2.test.js.map +1 -0
  51. package/dist/tests/e2e/net-helpers.d.ts +28 -0
  52. package/dist/tests/e2e/net-helpers.js +59 -0
  53. package/dist/tests/e2e/net-helpers.js.map +1 -0
  54. package/dist/tests/e2e/node-modules.test.js +3 -5
  55. package/dist/tests/e2e/node-modules.test.js.map +1 -1
  56. package/dist/tests/e2e/tls.test.d.ts +10 -0
  57. package/dist/tests/e2e/tls.test.js +197 -0
  58. package/dist/tests/e2e/tls.test.js.map +1 -0
  59. package/dist/tests/extensions/storage.test.js +3 -2
  60. package/dist/tests/extensions/storage.test.js.map +1 -1
  61. package/doc/ai/contributing.md +14 -0
  62. package/doc/ai/extensions.md +5 -3
  63. package/doc/ai/language-support.md +1 -1
  64. package/doc/ai/zh-CN/contributing.md +12 -0
  65. package/doc/ai/zh-CN/extensions.md +4 -2
  66. package/doc/ai/zh-CN/language-support.md +1 -1
  67. package/doc/gui/api.md +1 -1
  68. package/doc/gui/build.md +5 -3
  69. package/doc/gui/rendering.md +1 -1
  70. package/doc/gui.md +1 -1
  71. package/doc/implemented/async.md +1 -1
  72. package/doc/implemented/extensions.md +1 -0
  73. package/doc/implemented/fetch.md +19 -4
  74. package/doc/implemented/node/http2.md +51 -0
  75. package/doc/implemented/node/tls.md +56 -0
  76. package/doc/implemented/node.md +8 -0
  77. package/doc/implemented/storage.md +2 -1
  78. package/doc/implemented.md +2 -2
  79. package/doc/unimplemented/node/modules.md +6 -6
  80. package/doc/unimplemented/toolchain.md +1 -1
  81. package/doc/zh-CN/gui/api.md +1 -1
  82. package/doc/zh-CN/gui/build.md +4 -2
  83. package/doc/zh-CN/gui/rendering.md +1 -1
  84. package/doc/zh-CN/gui.md +1 -1
  85. package/doc/zh-CN/implemented/async.md +1 -1
  86. package/doc/zh-CN/implemented/extensions.md +1 -0
  87. package/doc/zh-CN/implemented/fetch.md +15 -3
  88. package/doc/zh-CN/implemented/node/http2.md +44 -0
  89. package/doc/zh-CN/implemented/node/tls.md +47 -0
  90. package/doc/zh-CN/implemented/node.md +7 -0
  91. package/doc/zh-CN/implemented/storage.md +2 -1
  92. package/doc/zh-CN/implemented.md +2 -2
  93. package/doc/zh-CN/unimplemented/node/modules.md +3 -3
  94. package/doc/zh-CN/unimplemented/toolchain.md +1 -1
  95. package/package.json +16 -8
  96. package/runtime/ext_node/http2/http2.c +25 -11
  97. package/runtime/ext_node/http2/http2_backend.c +48 -0
  98. package/runtime/ext_node/http2/http2_bridge.c +25 -0
  99. package/runtime/ext_node/http2/parts/api.inc +40 -0
  100. package/runtime/ext_node/http2/parts/client.inc +215 -0
  101. package/runtime/ext_node/http2/parts/common.inc +330 -0
  102. package/runtime/ext_node/http2/parts/events.inc +139 -0
  103. package/runtime/ext_node/http2/parts/server.inc +301 -0
  104. package/runtime/ext_node/http2/parts/streams.inc +254 -0
  105. package/runtime/ext_node/tls/parts/api.inc +38 -0
  106. package/runtime/ext_node/tls/parts/connect.inc +107 -0
  107. package/runtime/ext_node/tls/parts/helpers.inc +121 -0
  108. package/runtime/ext_node/tls/parts/server.inc +101 -0
  109. package/runtime/ext_node/tls/parts/socket.inc +171 -0
  110. package/runtime/ext_node/tls/tls.c +21 -13
  111. package/runtime/ext_node/tls/tls_backend.c +50 -0
  112. package/runtime/ext_node/zlib/{miniz/compression_bridge.c → compression_bridge.c} +1 -1
  113. package/runtime/xt_fetch/async.inc +19 -12
  114. package/runtime/xt_fetch/socket.inc +55 -0
  115. package/runtime/xt_fetch.c +3 -0
  116. package/runtime/xt_http2/nghttp2_compat.h +19 -0
  117. package/runtime/xt_http2/nghttp2_static.h +18 -0
  118. package/runtime/xt_http2_api.h +38 -0
  119. package/runtime/xt_node_tls_api.h +37 -0
  120. package/runtime/xt_protocol_registry.c +22 -0
  121. package/runtime/xt_storage/storage_internal.h +3 -3
  122. package/runtime/xt_tls/parts/api.inc +21 -0
  123. package/runtime/xt_tls/parts/client.inc +112 -0
  124. package/runtime/xt_tls/parts/io.inc +157 -0
  125. package/runtime/xt_tls/parts/server.inc +102 -0
  126. package/runtime/xt_tls/parts/setup.inc +146 -0
  127. package/runtime/xt_tls/tls_bridge.c +27 -0
  128. package/runtime/xt_tls/tls_core.c +39 -0
  129. package/runtime/xt_tls/tls_internal.h +73 -0
  130. package/runtime/xt_tls_api.h +73 -0
  131. package/scripts/build-gui.ts +8 -7
  132. package/scripts/build-tls.ts +248 -0
  133. package/scripts/check-file-length.ts +4 -25
  134. package/scripts/fetch-vendored.ts +244 -0
  135. package/scripts/package-release.ts +13 -3
  136. package/src/driver/build-key.ts +7 -1
  137. package/src/driver/fingerprint.ts +24 -0
  138. package/src/driver/link-features.ts +33 -11
  139. package/src/driver/paths.ts +20 -0
  140. package/src/driver/runtime-objects.ts +25 -6
  141. package/src/driver/toolchain.ts +11 -2
  142. package/src/driver/version.ts +1 -1
  143. package/src/extensions/node/http2/feature.ts +33 -0
  144. package/src/extensions/node/http2/index.ts +6 -1
  145. package/src/extensions/node/index.ts +3 -1
  146. package/src/extensions/node/tls/feature.ts +29 -0
  147. package/src/extensions/node/tls/index.ts +5 -1
  148. package/src/extensions/node/zlib/compression.ts +11 -6
  149. package/src/extensions/registry.ts +2 -1
  150. package/src/extensions/storage.ts +4 -3
  151. package/src/extensions/tls.ts +52 -0
  152. package/{runtime/ext_gui → vendor/stb}/stb_image.h +17 -1
  153. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz.c +0 -0
  154. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz.h +0 -0
  155. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_common.h +0 -0
  156. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_export.h +0 -0
  157. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tdef.c +0 -0
  158. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tdef.h +0 -0
  159. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tinfl.c +0 -0
  160. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tinfl.h +0 -0
  161. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_zip.h +0 -0
  162. /package/{runtime/ext_gui → vendor/nanosvg}/nanosvg.h +0 -0
  163. /package/{runtime/ext_gui → vendor/nanosvg}/nanosvgrast.h +0 -0
  164. /package/{runtime/xt_storage → vendor}/sqlite3/sqlite3.c +0 -0
  165. /package/{runtime/xt_storage → vendor}/sqlite3/sqlite3.h +0 -0
  166. /package/{runtime/ext_gui → vendor/stb}/stb_truetype.h +0 -0
@@ -7,8 +7,9 @@
7
7
  * the runtime's C, C++, Rust and `#include`d `.inc` fragments plus shell
8
8
  * scripts, so *every* code file stays focused and small.
9
9
  *
10
- * Vendored third-party sources that must ship verbatim (notably the
11
- * single-header `stb_image.h`) are exempt: they are not ours to split.
10
+ * Third-party sources are fetched into `vendor/` instead of being committed
11
+ * (see `scripts/fetch-vendored.ts`), so the walk skips that directory: nothing
12
+ * vendored is ours to split, and it is not part of the tree this check owns.
12
13
  *
13
14
  * Run via `npm run lint` (or `tsx scripts/check-file-length.ts`).
14
15
  */
@@ -35,28 +36,6 @@ const IGNORED_DIRECTORIES = new Set([
35
36
  "vendor",
36
37
  ]);
37
38
 
38
- /** Vendored third-party sources that ship verbatim and are not ours to split. */
39
- const VENDORED_FILES = new Set([
40
- join("runtime", "ext_gui", "stb_image.h"),
41
- join("runtime", "ext_gui", "stb_truetype.h"),
42
- join("runtime", "ext_gui", "nanosvg.h"),
43
- join("runtime", "ext_gui", "nanosvgrast.h"),
44
- // miniz, the single-file DEFLATE library used by the `compression` link
45
- // feature (`node:zlib`), ships verbatim.
46
- join("runtime", "ext_node", "zlib", "miniz", "miniz.c"),
47
- join("runtime", "ext_node", "zlib", "miniz", "miniz.h"),
48
- join("runtime", "ext_node", "zlib", "miniz", "miniz_tdef.c"),
49
- join("runtime", "ext_node", "zlib", "miniz", "miniz_tdef.h"),
50
- join("runtime", "ext_node", "zlib", "miniz", "miniz_tinfl.c"),
51
- join("runtime", "ext_node", "zlib", "miniz", "miniz_tinfl.h"),
52
- join("runtime", "ext_node", "zlib", "miniz", "miniz_common.h"),
53
- join("runtime", "ext_node", "zlib", "miniz", "miniz_export.h"),
54
- // SQLite, the single-file amalgamation backing the `storage` extension
55
- // (localStorage / sessionStorage / indexedDB), ships verbatim.
56
- join("runtime", "xt_storage", "sqlite3", "sqlite3.c"),
57
- join("runtime", "xt_storage", "sqlite3", "sqlite3.h"),
58
- ]);
59
-
60
39
  /** Machine-generated files: they are reproduced from their sources by a script,
61
40
  * so their size is not a sign of a module that needs splitting. */
62
41
  const GENERATED_FILES = new Set([join("runtime", "ext_gui", "renderer_shaders_data.h")]);
@@ -88,7 +67,7 @@ function collect(dir: string, offenses: Offense[]): void {
88
67
  const dot = entry.name.lastIndexOf(".");
89
68
  if (dot < 0 || !CODE_EXTENSIONS.has(entry.name.slice(dot))) continue;
90
69
  const file = relative(root, full);
91
- if (VENDORED_FILES.has(file) || GENERATED_FILES.has(file)) continue;
70
+ if (GENERATED_FILES.has(file)) continue;
92
71
  const lines = countLines(full);
93
72
  if (lines > MAX_LINES) offenses.push({ file, lines });
94
73
  }
@@ -0,0 +1,244 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Fetch the third-party C sources that xbintsc compiles, into `vendor/`.
4
+ *
5
+ * Those libraries are vendored *by version*, not committed: the repository
6
+ * tracks neither their code nor their line count. Each entry pins an immutable
7
+ * upstream revision and the SHA-256 of the extracted file, so a changed pin is
8
+ * a reviewable change and a corrupted download can never reach a build.
9
+ *
10
+ * Layout (sibling of `runtime/`, so `findVendorDir()` can find it in a source
11
+ * checkout, an unpacked release and an npm install alike):
12
+ *
13
+ * vendor/stb/stb_image.h, stb_truetype.h
14
+ * vendor/nanosvg/nanosvg.h, nanosvgrast.h
15
+ * vendor/miniz/… the `compression` link feature
16
+ * vendor/sqlite3/sqlite3.{c,h} the `storage` link feature
17
+ *
18
+ * `build-gui.ts` fetches just `stb`/`nanosvg`; `npm test` fetches everything.
19
+ * CI caches the four directories keyed on this script.
20
+ *
21
+ * Note: miniz's upstream tree has no `miniz_export.h` (its CMake build generates
22
+ * one). The static-only shim below is written here rather than tracked.
23
+ *
24
+ * Run via `npm run vendor` (or `tsx scripts/fetch-vendored.ts`).
25
+ */
26
+
27
+ import { spawnSync } from "node:child_process";
28
+ import { createHash } from "node:crypto";
29
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
30
+ import { basename, dirname, join, resolve } from "node:path";
31
+ import { fileURLToPath, pathToFileURL } from "node:url";
32
+ import { downloadTarball } from "./fetch-tarball.js";
33
+
34
+ const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
35
+ export const vendorDir = join(root, "vendor");
36
+
37
+ /** The vendored packages, each a directory under `vendor/`. */
38
+ export const VENDOR_PACKAGES = ["stb", "nanosvg", "miniz", "sqlite3"] as const;
39
+ export type VendorPackage = (typeof VENDOR_PACKAGES)[number];
40
+
41
+ interface VendoredFile {
42
+ readonly package: Exclude<VendorPackage, "sqlite3">;
43
+ readonly name: string;
44
+ readonly url: string;
45
+ readonly sha256: string;
46
+ }
47
+
48
+ /* Pinned upstream revisions. STB and NanoSVG have no releases, so the commit
49
+ * is the version; miniz is pinned to the commit whose files this tree uses. */
50
+ const STB_IMAGE = "013ac3beddff3dbffafd5177e7972067cd2b5083";
51
+ const STB_TRUETYPE = "c0c982601f40183e74d84a61237e968dca08380e";
52
+ const NANOSVG = "239e102ec2c691f2902e20ace2ed36ee4a35cfe6";
53
+ const MINIZ = "2c50092b3a4010760df02e7842960abdc3f25ee3";
54
+
55
+ const RAW = "https://raw.githubusercontent.com";
56
+
57
+ const FILES: readonly VendoredFile[] = [
58
+ {
59
+ package: "stb",
60
+ name: "stb_image.h",
61
+ url: `${RAW}/nothings/stb/${STB_IMAGE}/stb_image.h`,
62
+ sha256: "594c2fe35d49488b4382dbfaec8f98366defca819d916ac95becf3e75f4200b3",
63
+ },
64
+ {
65
+ package: "stb",
66
+ name: "stb_truetype.h",
67
+ url: `${RAW}/nothings/stb/${STB_TRUETYPE}/stb_truetype.h`,
68
+ sha256: "a34d8d536ce7c11b9163ab2d524721c1f4df1452cce6595c4f11d3048384f925",
69
+ },
70
+ {
71
+ package: "nanosvg",
72
+ name: "nanosvg.h",
73
+ url: `${RAW}/memononen/nanosvg/${NANOSVG}/src/nanosvg.h`,
74
+ sha256: "e34fd5d084be106cea972d19ce5d27fd96d17ba89f8d06bdceee058420c8b2b0",
75
+ },
76
+ {
77
+ package: "nanosvg",
78
+ name: "nanosvgrast.h",
79
+ url: `${RAW}/memononen/nanosvg/${NANOSVG}/src/nanosvgrast.h`,
80
+ sha256: "79a9c5f4db19debf9f3a648a1589e96d92854f245a5cb4f3d823f263785234d8",
81
+ },
82
+ ...(
83
+ [
84
+ ["miniz.c", "29a0c08c4610d20ab18381cbf18190f91b4b41d05c242376364756061b631f1d"],
85
+ ["miniz.h", "2b9c48355793988f0d12b3cef357e52b741d744385157b59cb422237ea226501"],
86
+ ["miniz_common.h", "d0770cc478923e33bf22820fc51bbe22b6b99c3230ce4f5fc10eea3debc75623"],
87
+ ["miniz_tdef.c", "7b3baaa59f50116eb3e72a23302c505b76cb01cc456672f7957a74d9e7b44047"],
88
+ ["miniz_tdef.h", "123050e3c876519828d3934899e0b003ad13a98114919d94f1e06b4b9d02a925"],
89
+ ["miniz_tinfl.c", "7113a08a7722d671ce89b8de61fe6d02d0cadca0ff274ba357bf2a9dc85745ca"],
90
+ ["miniz_tinfl.h", "2c89615a4cbc5de4eac5b861051849392ec698264ee7dd399ea587c592cf68d1"],
91
+ ["miniz_zip.h", "43d09867f79993a9ba1627cb1f3bbd78d3bf5ee0c91cd6e7527aa9ca1e3aed44"],
92
+ ] as const
93
+ ).map(([name, sha256]) => ({
94
+ package: "miniz" as const,
95
+ name,
96
+ url: `${RAW}/richgel999/miniz/${MINIZ}/${name}`,
97
+ sha256,
98
+ })),
99
+ ];
100
+
101
+ /** miniz's static-build export shim (upstream generates it with CMake). */
102
+ const MINIZ_EXPORT_H =
103
+ "/* Minimal export macro for a static miniz build (no DLL import/export). */\n" +
104
+ "#ifndef MINIZ_EXPORT\n" +
105
+ "#define MINIZ_EXPORT\n" +
106
+ "#endif\n";
107
+
108
+ /* SQLite publishes one amalgamation zip per release; only the two files below
109
+ * are compiled. The zip itself is pinned as well: a truncated download is a
110
+ * download to retry, not an amalgamation to build. */
111
+ const SQLITE_PACKAGE = "sqlite-amalgamation-3540100";
112
+ const SQLITE_URL = `https://www.sqlite.org/2026/${SQLITE_PACKAGE}.zip`;
113
+ const SQLITE_ZIP_SHA256 = "0a9c8e34352dad46006aa82836d5383bff9dc6bc9ce5a60553c05aa30e6ad1f9";
114
+ const SQLITE_FILES = [
115
+ {
116
+ name: "sqlite3.c",
117
+ sha256: "0c657666d819f261cc4007526ad57e1669de9949df7a8ea847aa284a2bf0ee52",
118
+ },
119
+ {
120
+ name: "sqlite3.h",
121
+ sha256: "d6c84557261893439b341d2e6c35187ae3ea24fbfd843ad94616f72d89242b8c",
122
+ },
123
+ ] as const;
124
+
125
+ function sha256(file: string): string {
126
+ return createHash("sha256").update(readFileSync(file)).digest("hex");
127
+ }
128
+
129
+ function isPinned(file: string, digest: string): boolean {
130
+ return existsSync(file) && sha256(file) === digest;
131
+ }
132
+
133
+ /** Download one file, refusing to leave a mismatched (stale or corrupted) file. */
134
+ function ensureFile(file: VendoredFile): void {
135
+ const target = join(vendorDir, file.package, file.name);
136
+ if (isPinned(target, file.sha256)) return;
137
+ mkdirSync(dirname(target), { recursive: true });
138
+ rmSync(target, { force: true });
139
+ downloadTarball(target, file.url, `${file.package}/${file.name}`);
140
+ if (isPinned(target, file.sha256)) return;
141
+ const actual = sha256(target);
142
+ rmSync(target, { force: true });
143
+ throw new Error(
144
+ `${file.package}/${file.name}: expected sha256 ${file.sha256}, got ${actual}. ` +
145
+ "The upstream pin moved; update the URL and hash in scripts/fetch-vendored.ts deliberately.",
146
+ );
147
+ }
148
+
149
+ /** Write the generated miniz export shim (no upstream file to download). */
150
+ function ensureMinizExportHeader(): void {
151
+ const target = join(vendorDir, "miniz", "miniz_export.h");
152
+ if (existsSync(target) && readFileSync(target, "utf8") === MINIZ_EXPORT_H) return;
153
+ mkdirSync(dirname(target), { recursive: true });
154
+ writeFileSync(target, MINIZ_EXPORT_H);
155
+ }
156
+
157
+ /** Extract a zip archive; Windows' bsdtar and POSIX's unzip cover the hosts. */
158
+ function extractZip(zip: string, destination: string): void {
159
+ const attempts: readonly (readonly [string, readonly string[]])[] =
160
+ process.platform === "win32"
161
+ ? [
162
+ ["tar", ["-xf", zip, "-C", destination]],
163
+ ["unzip", ["-q", "-o", zip, "-d", destination]],
164
+ ]
165
+ : [
166
+ ["unzip", ["-q", "-o", zip, "-d", destination]],
167
+ ["tar", ["-xf", zip, "-C", destination]],
168
+ ];
169
+ for (const [command, args] of attempts) {
170
+ if (spawnSync(command, args, { stdio: "ignore" }).status === 0) return;
171
+ }
172
+ throw new Error(`cannot extract ${basename(zip)}; install unzip (or a tar that reads zip archives)`);
173
+ }
174
+
175
+ /** Fetch the pinned SQLite amalgamation and copy out its two sources. */
176
+ function ensureSqlite(): void {
177
+ const directory = join(vendorDir, "sqlite3");
178
+ if (SQLITE_FILES.every((file) => isPinned(join(directory, file.name), file.sha256))) return;
179
+
180
+ const cache = join(vendorDir, ".cache");
181
+ mkdirSync(cache, { recursive: true });
182
+ const zip = join(cache, `${SQLITE_PACKAGE}.zip`);
183
+ if (!isPinned(zip, SQLITE_ZIP_SHA256)) {
184
+ rmSync(zip, { force: true });
185
+ downloadTarball(zip, SQLITE_URL, `${SQLITE_PACKAGE}.zip`);
186
+ if (!isPinned(zip, SQLITE_ZIP_SHA256)) {
187
+ const actual = sha256(zip);
188
+ rmSync(zip, { force: true });
189
+ throw new Error(`${SQLITE_PACKAGE}.zip: expected sha256 ${SQLITE_ZIP_SHA256}, got ${actual}`);
190
+ }
191
+ }
192
+
193
+ const extracted = join(cache, SQLITE_PACKAGE);
194
+ rmSync(extracted, { recursive: true, force: true });
195
+ mkdirSync(extracted, { recursive: true });
196
+ extractZip(zip, extracted);
197
+ const sourceDir = join(extracted, SQLITE_PACKAGE);
198
+ if (!existsSync(join(sourceDir, "sqlite3.c"))) {
199
+ throw new Error(`expected ${SQLITE_PACKAGE}/sqlite3.c after extracting ${basename(zip)}`);
200
+ }
201
+
202
+ mkdirSync(directory, { recursive: true });
203
+ for (const file of SQLITE_FILES) {
204
+ const target = join(directory, file.name);
205
+ copyFileSync(join(sourceDir, file.name), target);
206
+ if (!isPinned(target, file.sha256)) {
207
+ const actual = sha256(target);
208
+ rmSync(target, { force: true });
209
+ throw new Error(`sqlite3/${file.name}: expected sha256 ${file.sha256}, got ${actual}`);
210
+ }
211
+ }
212
+ rmSync(extracted, { recursive: true, force: true });
213
+ rmSync(zip, { force: true });
214
+ }
215
+
216
+ /**
217
+ * Ensure the requested vendored packages exist and match their pins.
218
+ * Downloads only what is missing; everything else is a content check.
219
+ */
220
+ export function ensureVendoredSources(packages: readonly VendorPackage[] = VENDOR_PACKAGES): void {
221
+ for (const name of packages) {
222
+ if (name === "sqlite3") {
223
+ ensureSqlite();
224
+ continue;
225
+ }
226
+ for (const file of FILES) {
227
+ if (file.package === name) ensureFile(file);
228
+ }
229
+ if (name === "miniz") ensureMinizExportHeader();
230
+ }
231
+ }
232
+
233
+ const invokedDirectly =
234
+ process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href;
235
+
236
+ if (invokedDirectly) {
237
+ try {
238
+ ensureVendoredSources();
239
+ console.log("xbintsc: vendored sources are present and match their pins");
240
+ } catch (error) {
241
+ console.error(`xbintsc: ${error instanceof Error ? error.message : String(error)}`);
242
+ process.exit(1);
243
+ }
244
+ }
@@ -21,6 +21,7 @@
21
21
  * xbintsc-<os>-<arch>/
22
22
  * bin/xbintsc[.exe] the self-hosted compiler
23
23
  * runtime/ C runtime sources + prebuilt runtime/lib/<slug>
24
+ * vendor/ pinned third-party sources (fetched, not committed)
24
25
  * README.md
25
26
  *
26
27
  * The compiler locates `runtime/` relative to its own executable (see
@@ -108,13 +109,22 @@ console.log("xbintsc: copying runtime/ into the staging tree");
108
109
  cpSync(findRuntimeDir(), join(stage, "runtime"), { recursive: true });
109
110
  console.log("xbintsc: packaged runtime/");
110
111
 
111
- // 3. Human-facing notes.
112
+ // 3. Vendored sources the driver compiles on demand (SQLite for `storage`,
113
+ // miniz for `compression`). They are fetched by `npm run vendor`, not committed.
114
+ for (const name of ["stb", "nanosvg", "miniz", "sqlite3"]) {
115
+ const source = join(root, "vendor", name);
116
+ if (!existsSync(source)) fail(`missing vendor/${name}; run \`npm run vendor\` before packaging`);
117
+ cpSync(source, join(stage, "vendor", name), { recursive: true });
118
+ }
119
+ console.log("xbintsc: packaged vendor/");
120
+
121
+ // 4. Human-facing notes.
112
122
  for (const name of ["README.md", "LICENSE"]) {
113
123
  const source = join(root, name);
114
124
  if (existsSync(source)) copyFileSync(source, join(stage, name));
115
125
  }
116
126
 
117
- // 4. Archive it. Prefer zstd when available, otherwise gzip.
127
+ // 5. Archive it. Prefer zstd when available, otherwise gzip.
118
128
  const hasZstd = !spawnSync("zstd", ["--version"], { stdio: "ignore" }).error;
119
129
  const extension = releaseArchiveExtension(hasZstd);
120
130
  const archive = join(releaseRoot, `${archiveBase}${extension}`);
@@ -128,7 +138,7 @@ const tar = spawnSync("tar", tarArgs, { stdio: "inherit" });
128
138
  if (tar.error) fail(`failed to run tar: ${tar.error.message}`);
129
139
  if (tar.status !== 0) fail(`tar exited with ${tar.status}`);
130
140
 
131
- // 5. Checksum, so users can verify the download.
141
+ // 6. Checksum, so users can verify the download.
132
142
  const digest = createHash("sha256").update(readFileSync(archive)).digest("hex");
133
143
  writeFileSync(`${archive}.sha256`, `${digest} ${basename(archive)}\n`);
134
144
 
@@ -11,7 +11,12 @@
11
11
  import type { ExtensionRegistry } from "../extensions/registry.js";
12
12
  import { hashParts } from "./cache.js";
13
13
  import type { AppConfig } from "./config.js";
14
- import { compilerFingerprint, registryFingerprint, runtimeFingerprint } from "./fingerprint.js";
14
+ import {
15
+ compilerFingerprint,
16
+ registryFingerprint,
17
+ runtimeFingerprint,
18
+ vendoredRuntimeFingerprint,
19
+ } from "./fingerprint.js";
15
20
  import { COMPILER_VERSION } from "./version.js";
16
21
  import type { IconInfo } from "./icon.js";
17
22
  import type { ResolvedStorage } from "./storage.js";
@@ -50,6 +55,7 @@ export function buildCacheKey(input: CacheKeyInput): string {
50
55
  process.platform,
51
56
  registryFingerprint(input.registry),
52
57
  runtimeFingerprint(input.runtimeDir),
58
+ vendoredRuntimeFingerprint(input.runtimeDir),
53
59
  icon ? hashParts(["icon", icon.format, Buffer.from(icon.bytes).toString("base64")]) : "",
54
60
  app.name ?? "",
55
61
  String(app.bundle ?? false),
@@ -34,6 +34,30 @@ export function runtimeFingerprint(runtimeDir: string): string {
34
34
  return hashParts(parts);
35
35
  }
36
36
 
37
+ /**
38
+ * Content hash of the vendored C sources a link feature compiles into the
39
+ * program (`vendor/miniz` for `compression`, `vendor/sqlite3` for `storage`).
40
+ *
41
+ * They live outside `runtime/` — the tree is fetched, not committed — so
42
+ * {@link runtimeFingerprint} cannot see them, yet changing one changes the
43
+ * linked binary. Only the two packages compiled at program-build time are
44
+ * hashed: `stb`/`nanosvg` are baked into `gui.a`, whose content the registry
45
+ * fingerprint already covers.
46
+ */
47
+ export function vendoredRuntimeFingerprint(runtimeDir: string): string {
48
+ const vendorDir = resolve(runtimeDir, "..", "vendor");
49
+ const parts: string[] = [];
50
+ for (const name of ["miniz", "sqlite3"]) {
51
+ const dir = join(vendorDir, name);
52
+ if (!existsSync(dir)) continue;
53
+ for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
54
+ if (!entry.isFile()) continue;
55
+ parts.push(name, entry.name, readFileSync(join(dir, entry.name)).toString("base64"));
56
+ }
57
+ }
58
+ return hashParts(parts);
59
+ }
60
+
37
61
  /**
38
62
  * Content hash of the compiler's own TypeScript sources, when they are present.
39
63
  *
@@ -94,33 +94,55 @@ export function resolveLinkFeatures(
94
94
  }
95
95
  if (specificallyForced || (forceAll && !specificallyBlocked)) forced.add(feature.name);
96
96
  }
97
- let changed = true;
98
- while (changed) {
99
- changed = false;
100
- for (const { feature } of declarations) {
101
- if (!forced.has(feature.name)) continue;
97
+ /* `strict` records the features whose absence is an error: everything the
98
+ * user asked for, plus its `requires` closure. An auto-detected feature is
99
+ * allowed to be unavailable (the driver warns), but a feature the user named
100
+ * must either link or fail the build. */
101
+ const strict = new Set(forced);
102
+ const expand = (target: Set<string>, roots: readonly string[]): void => {
103
+ const queue = [...roots];
104
+ while (queue.length > 0) {
105
+ const name = queue.pop()!;
106
+ const feature = byName.get(name);
107
+ if (feature === undefined) continue;
102
108
  for (const dependency of feature.requires ?? []) {
103
109
  if (!byName.has(dependency)) {
104
110
  diagnostics.error(
105
111
  DiagnosticCode.LinkFeatureUnavailable,
106
- `link feature '${feature.name}' requires unknown feature '${dependency}'`,
112
+ `link feature '${name}' requires unknown feature '${dependency}'`,
107
113
  );
108
114
  continue;
109
115
  }
110
116
  if (disabled.has(dependency)) {
111
117
  diagnostics.error(
112
118
  DiagnosticCode.LinkFeatureUnavailable,
113
- `link feature '${feature.name}' requires '${dependency}', which --no-feature disables`,
119
+ `link feature '${name}' requires '${dependency}', which --no-feature disables`,
114
120
  );
115
121
  continue;
116
122
  }
117
- if (!forced.has(dependency)) {
118
- forced.add(dependency);
119
- changed = true;
123
+ if (!target.has(dependency)) {
124
+ target.add(dependency);
125
+ queue.push(dependency);
120
126
  }
121
127
  }
122
128
  }
129
+ };
130
+ expand(strict, [...strict]);
131
+ for (const name of strict) forced.add(name);
132
+
133
+ /* Select the program's auto-detected features and pull in `requires`
134
+ * transitively. Dependencies are resolved for every selected feature, not
135
+ * just the explicitly forced ones: `node:tls` is auto-detected from the
136
+ * import, and the transport it builds on (`tls`) must be linked with it. */
137
+ const autoRoots: string[] = [];
138
+ for (const { feature } of declarations) {
139
+ if (forced.has(feature.name) || disabled.has(feature.name)) continue;
140
+ if (disableAll && !requested.has(feature.name)) continue;
141
+ if (!feature.used(usage)) continue;
142
+ forced.add(feature.name);
143
+ autoRoots.push(feature.name);
123
144
  }
145
+ expand(forced, autoRoots);
124
146
  if (diagnostics.hasErrors) return [];
125
147
 
126
148
  const resolved: ResolvedLinkFeature[] = [];
@@ -139,7 +161,7 @@ export function resolveLinkFeatures(
139
161
  nativeObjects = feature.nativeObjects?.() ?? [];
140
162
  } catch (error) {
141
163
  const message = error instanceof Error ? error.message : String(error);
142
- if (forcedHere) {
164
+ if (strict.has(feature.name)) {
143
165
  diagnostics.error(DiagnosticCode.LinkFeatureUnavailable, message);
144
166
  } else {
145
167
  diagnostics.warning(
@@ -22,6 +22,26 @@ export function findRuntimeDir(): string {
22
22
  throw new Error("Unable to locate the xbintsc runtime directory (missing runtime/rt.h)");
23
23
  }
24
24
 
25
+ /**
26
+ * Directory holding the third-party sources fetched by `npm run vendor`
27
+ * (`vendor/` next to `runtime/`).
28
+ *
29
+ * They are not committed: the tree is rebuilt from pinned upstream releases by
30
+ * `scripts/fetch-vendored.ts`. `runtime/xt_storage` and the `compression`
31
+ * feature resolve their C sources here, so a build that needs them fails with
32
+ * the command to run when the directory is missing.
33
+ */
34
+ export function findVendorDir(): string {
35
+ const candidate = resolve(findRuntimeDir(), "..", "vendor");
36
+ const markers = [join("sqlite3", "sqlite3.c"), join("miniz", "miniz.c")];
37
+ if (markers.some((marker) => existsSync(join(candidate, marker)))) return candidate;
38
+ throw new Error(
39
+ "Unable to locate the xbintsc vendor directory (missing vendor/miniz/miniz.c or " +
40
+ "vendor/sqlite3/sqlite3.c); run `npm run vendor` in a source checkout, or reinstall " +
41
+ "xbintsc so the package's vendored sources are present.",
42
+ );
43
+ }
44
+
25
45
  /** Platform-architecture slug, e.g. `darwin-arm64`, `linux-x64`, `win32-x64`. */
26
46
  export function platformSlug(): string {
27
47
  return `${process.platform}-${process.arch}`;
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  import { existsSync, readFileSync, readdirSync } from "node:fs";
10
- import { basename, join, resolve } from "node:path";
10
+ import { basename, join, resolve, sep } from "node:path";
11
11
  import type { ExtensionRegistry } from "../extensions/registry.js";
12
12
  import type { ResolvedLinkFeature } from "./link-features.js";
13
13
  import { hashParts } from "./cache.js";
@@ -46,6 +46,7 @@ export const RUNTIME_SOURCES = [
46
46
  "xt_url_object.c",
47
47
  "xt_array_buffer.c",
48
48
  "xt_io.c",
49
+ "xt_protocol_registry.c",
49
50
  ] as const;
50
51
 
51
52
  export interface RuntimeObjects {
@@ -109,15 +110,24 @@ export function ensureRuntimeObjects(options: RuntimeObjectsOptions): RuntimeObj
109
110
  }
110
111
  };
111
112
  collectHeaders(runtimeDir);
113
+ /* The link features compile vendors from `vendor/`, so their headers must
114
+ * invalidate objects just like the runtime's own (the packages are sibling to
115
+ * `runtime/`, and absent in a checkout that has not run `npm run vendor`). */
116
+ const vendorDir = resolve(runtimeDir, "..", "vendor");
117
+ for (const name of ["miniz", "sqlite3"]) {
118
+ const dir = join(vendorDir, name);
119
+ if (existsSync(dir)) collectHeaders(dir);
120
+ }
112
121
  const headerStamp = hashParts(headerParts);
113
122
 
114
- const compileOne = (sourcePath: string, tag: string): string => {
123
+ const compileOne = (sourcePath: string, tag: string, includeDirs: readonly string[]): string => {
115
124
  const body = readFileSync(sourcePath, "utf8");
116
125
  const key = hashParts([
117
126
  "runtime",
118
127
  COMPILER_VERSION,
119
128
  RUNTIME_CFLAGS.join(" "),
120
129
  compileFlags.join(" "),
130
+ includeDirs.join(";"),
121
131
  tag,
122
132
  headerStamp,
123
133
  body,
@@ -126,15 +136,16 @@ export function ensureRuntimeObjects(options: RuntimeObjectsOptions): RuntimeObj
126
136
  ]);
127
137
  const objectPath = join(cacheDir, `${tag}-${key}.o`);
128
138
  if (!existsSync(objectPath)) {
129
- compileC(runner, clang, sourcePath, objectPath, runtimeDir, env, compileFlags);
139
+ compileC(runner, clang, sourcePath, objectPath, includeDirs, env, compileFlags);
130
140
  }
131
141
  return objectPath;
132
142
  };
133
143
 
144
+ const runtimeInclude = [runtimeDir];
134
145
  const coreArchive = preferPrebuilt ? findRuntimeLibrary("core", options.runtimeLibDirs) : undefined;
135
146
  const runtimeObjects = coreArchive
136
147
  ? [coreArchive]
137
- : RUNTIME_SOURCES.map((source) => compileOne(join(runtimeDir, source), basename(source, ".c")));
148
+ : RUNTIME_SOURCES.map((source) => compileOne(join(runtimeDir, source), basename(source, ".c"), runtimeInclude));
138
149
 
139
150
  /** Prebuilt archives this link uses; the driver retries without them. */
140
151
  const prebuiltArchives: string[] = coreArchive ? [coreArchive] : [];
@@ -156,12 +167,20 @@ export function ensureRuntimeObjects(options: RuntimeObjectsOptions): RuntimeObj
156
167
  const dedupeKey = resolve(sourcePath);
157
168
  if (seen.has(dedupeKey)) continue;
158
169
  seen.add(dedupeKey);
159
- extensionObjects.push(compileOne(sourcePath, `ext_${extensionObjects.length}_${basename(sourcePath, ".c")}`));
170
+ extensionObjects.push(
171
+ compileOne(sourcePath, `ext_${extensionObjects.length}_${basename(sourcePath, ".c")}`, runtimeInclude),
172
+ );
160
173
  }
161
174
  }
162
175
  // A native archive may be shared by several manifests; link each once.
163
176
  const featureObjects: string[] = [];
164
177
  for (const feature of options.features ?? []) {
178
+ /* A feature that compiles a vendored library needs `vendor/` on the include
179
+ * path for its bridge (`sqlite3/sqlite3.h`, `miniz/miniz.h`). */
180
+ const usesVendor = feature.runtimeSources.some((sourcePath) =>
181
+ resolve(sourcePath).startsWith(`${vendorDir}${sep}`),
182
+ );
183
+ const featureInclude = usesVendor ? [runtimeDir, vendorDir] : runtimeInclude;
165
184
  /* Feature bridges are always compiled: they are not part of any prebuilt
166
185
  * archive, and their references are what make the linker extract the
167
186
  * feature's implementation. */
@@ -170,7 +189,7 @@ export function ensureRuntimeObjects(options: RuntimeObjectsOptions): RuntimeObj
170
189
  if (seen.has(dedupeKey)) continue;
171
190
  seen.add(dedupeKey);
172
191
  extensionObjects.push(
173
- compileOne(sourcePath, `feature_${feature.name}_${basename(sourcePath, ".c")}`),
192
+ compileOne(sourcePath, `feature_${feature.name}_${basename(sourcePath, ".c")}`, featureInclude),
174
193
  );
175
194
  }
176
195
  featureObjects.push(...feature.nativeObjects);
@@ -495,13 +495,22 @@ export function compileC(
495
495
  clang: string,
496
496
  sourcePath: string,
497
497
  objectPath: string,
498
- includeDir: string,
498
+ includeDir: string | readonly string[],
499
499
  env?: Record<string, string>,
500
500
  extraFlags: readonly string[] = [],
501
501
  ): void {
502
+ const includeDirs = typeof includeDir === "string" ? [includeDir] : includeDir;
502
503
  const result = runner.run(
503
504
  clang,
504
- [...RUNTIME_CFLAGS, ...extraFlags, "-c", sourcePath, "-o", objectPath, `-I${includeDir}`],
505
+ [
506
+ ...RUNTIME_CFLAGS,
507
+ ...extraFlags,
508
+ "-c",
509
+ sourcePath,
510
+ "-o",
511
+ objectPath,
512
+ ...includeDirs.map((dir) => `-I${dir}`),
513
+ ],
505
514
  { env },
506
515
  );
507
516
  if (result.status !== 0) throw new ToolchainError(`${clang} ${sourcePath}`, result.status, result.stderr);
@@ -9,4 +9,4 @@
9
9
  * `main`/`master` only (see `.githooks/pre-commit`), so feature branches never
10
10
  * change this line and merging two of them cannot conflict here.
11
11
  */
12
- export const COMPILER_VERSION = "0.6.22";
12
+ export const COMPILER_VERSION = "0.6.23";
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The `http2` link feature: nghttp2-backed `node:http2`.
3
+ *
4
+ * HTTP/2 framing and HPACK come from the vendored nghttp2 archive; TLS (and
5
+ * therefore ALPN) comes from the `tls` feature, and the JavaScript object
6
+ * surface reuses `node-tls`'s server wrapper for `createSecureServer`. The
7
+ * always-linked `http2` module forwards to the dispatch table this feature
8
+ * installs, so a checkout without the archive still compiles and reports a
9
+ * clear runtime error instead of failing to link.
10
+ */
11
+
12
+ import type { LinkFeature, ProgramUsage } from "../../link-feature.js";
13
+ import { resolveFrom } from "../module.js";
14
+ import { requireRuntimeLibrary } from "../../tls.js";
15
+
16
+ /** True when the bundled program imports `http2` or uses its server API. */
17
+ export function mentionsHttp2(usage: ProgramUsage): boolean {
18
+ return (
19
+ usage.strings.includes("http2") ||
20
+ usage.strings.includes("node:http2") ||
21
+ usage.identifiers.has("createSecureServer") ||
22
+ usage.identifiers.has("Http2Session")
23
+ );
24
+ }
25
+
26
+ export const http2Feature: LinkFeature = {
27
+ name: "http2",
28
+ description: "node:http2 client and server using nghttp2 over TLS or cleartext",
29
+ requires: ["tls", "node-tls"],
30
+ runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/http2/http2_bridge.c")],
31
+ nativeObjects: () => [requireRuntimeLibrary("nghttp2", "npm run tls")],
32
+ used: mentionsHttp2,
33
+ };