xbintsc 0.6.20 → 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.
- package/AGENTS.md +5 -0
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/main.js +1 -0
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/driver/build-key.d.ts +3 -0
- package/dist/src/driver/build-key.js +5 -2
- package/dist/src/driver/build-key.js.map +1 -1
- package/dist/src/driver/compiler.js +11 -0
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/config.d.ts +12 -0
- package/dist/src/driver/config.js +22 -0
- package/dist/src/driver/config.js.map +1 -1
- package/dist/src/driver/fingerprint.d.ts +11 -0
- package/dist/src/driver/fingerprint.js +25 -0
- package/dist/src/driver/fingerprint.js.map +1 -1
- package/dist/src/driver/index.d.ts +2 -1
- package/dist/src/driver/index.js +1 -0
- package/dist/src/driver/index.js.map +1 -1
- package/dist/src/driver/link-features.js +36 -11
- package/dist/src/driver/link-features.js.map +1 -1
- package/dist/src/driver/options.d.ts +8 -1
- package/dist/src/driver/paths.d.ts +10 -0
- package/dist/src/driver/paths.js +18 -0
- package/dist/src/driver/paths.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +22 -6
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/storage.d.ts +34 -0
- package/dist/src/driver/storage.js +67 -0
- package/dist/src/driver/storage.js.map +1 -0
- package/dist/src/driver/toolchain.d.ts +1 -1
- package/dist/src/driver/toolchain.js +10 -1
- package/dist/src/driver/toolchain.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/gui/features.d.ts +1 -1
- package/dist/src/extensions/gui/features.js +2 -2
- package/dist/src/extensions/gui/features.js.map +1 -1
- package/dist/src/extensions/gui/index.js +3 -1
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/node/http2/feature.d.ts +14 -0
- package/dist/src/extensions/node/http2/feature.js +28 -0
- package/dist/src/extensions/node/http2/feature.js.map +1 -0
- package/dist/src/extensions/node/http2/index.d.ts +5 -1
- package/dist/src/extensions/node/http2/index.js +6 -1
- package/dist/src/extensions/node/http2/index.js.map +1 -1
- package/dist/src/extensions/node/index.js +3 -1
- package/dist/src/extensions/node/index.js.map +1 -1
- package/dist/src/extensions/node/tls/feature.d.ts +12 -0
- package/dist/src/extensions/node/tls/feature.js +24 -0
- package/dist/src/extensions/node/tls/feature.js.map +1 -0
- package/dist/src/extensions/node/tls/index.d.ts +5 -1
- package/dist/src/extensions/node/tls/index.js +5 -1
- package/dist/src/extensions/node/tls/index.js.map +1 -1
- package/dist/src/extensions/node/zlib/compression.js +11 -6
- package/dist/src/extensions/node/zlib/compression.js.map +1 -1
- package/dist/src/extensions/registry.d.ts +4 -1
- package/dist/src/extensions/registry.js +9 -2
- package/dist/src/extensions/registry.js.map +1 -1
- package/dist/src/extensions/storage.d.ts +22 -0
- package/dist/src/extensions/storage.js +51 -0
- package/dist/src/extensions/storage.js.map +1 -0
- package/dist/src/extensions/tls.d.ts +26 -0
- package/dist/src/extensions/tls.js +46 -0
- package/dist/src/extensions/tls.js.map +1 -0
- package/dist/tests/driver/config.test.js +31 -0
- package/dist/tests/driver/config.test.js.map +1 -1
- package/dist/tests/driver/link-features.test.js +13 -2
- package/dist/tests/driver/link-features.test.js.map +1 -1
- package/dist/tests/driver/storage.test.d.ts +1 -0
- package/dist/tests/driver/storage.test.js +29 -0
- package/dist/tests/driver/storage.test.js.map +1 -0
- package/dist/tests/e2e/fetch.test.js +3 -1
- package/dist/tests/e2e/fetch.test.js.map +1 -1
- package/dist/tests/e2e/http2.test.d.ts +7 -0
- package/dist/tests/e2e/http2.test.js +201 -0
- package/dist/tests/e2e/http2.test.js.map +1 -0
- package/dist/tests/e2e/net-helpers.d.ts +28 -0
- package/dist/tests/e2e/net-helpers.js +59 -0
- package/dist/tests/e2e/net-helpers.js.map +1 -0
- package/dist/tests/e2e/node-modules.test.js +3 -5
- package/dist/tests/e2e/node-modules.test.js.map +1 -1
- package/dist/tests/e2e/storage.test.d.ts +7 -0
- package/dist/tests/e2e/storage.test.js +86 -0
- package/dist/tests/e2e/storage.test.js.map +1 -0
- package/dist/tests/e2e/tls.test.d.ts +10 -0
- package/dist/tests/e2e/tls.test.js +197 -0
- package/dist/tests/e2e/tls.test.js.map +1 -0
- package/dist/tests/extensions/gui-features.test.js +1 -1
- package/dist/tests/extensions/gui-features.test.js.map +1 -1
- package/dist/tests/extensions/storage.test.d.ts +1 -0
- package/dist/tests/extensions/storage.test.js +51 -0
- package/dist/tests/extensions/storage.test.js.map +1 -0
- package/doc/ai/cli.md +2 -0
- package/doc/ai/contributing.md +14 -0
- package/doc/ai/extensions.md +31 -3
- package/doc/ai/language-support.md +1 -1
- package/doc/ai/zh-CN/cli.md +2 -0
- package/doc/ai/zh-CN/contributing.md +12 -0
- package/doc/ai/zh-CN/extensions.md +27 -2
- package/doc/ai/zh-CN/language-support.md +1 -1
- package/doc/gui/api.md +1 -1
- package/doc/gui/build.md +7 -5
- package/doc/gui/media.md +4 -4
- package/doc/gui/rendering.md +1 -1
- package/doc/gui.md +3 -3
- package/doc/implemented/async.md +1 -1
- package/doc/implemented/extensions.md +2 -1
- package/doc/implemented/fetch.md +19 -4
- package/doc/implemented/node/http2.md +51 -0
- package/doc/implemented/node/tls.md +56 -0
- package/doc/implemented/node.md +8 -0
- package/doc/implemented/storage.md +65 -0
- package/doc/implemented.md +4 -2
- package/doc/unimplemented/node/modules.md +6 -6
- package/doc/unimplemented/toolchain.md +1 -1
- package/doc/xbintsc.config.schema.json +16 -1
- package/doc/zh-CN/gui/api.md +1 -1
- package/doc/zh-CN/gui/build.md +6 -4
- package/doc/zh-CN/gui/media.md +3 -3
- package/doc/zh-CN/gui/rendering.md +1 -1
- package/doc/zh-CN/gui.md +3 -3
- package/doc/zh-CN/implemented/async.md +1 -1
- package/doc/zh-CN/implemented/extensions.md +2 -1
- package/doc/zh-CN/implemented/fetch.md +15 -3
- package/doc/zh-CN/implemented/node/http2.md +44 -0
- package/doc/zh-CN/implemented/node/tls.md +47 -0
- package/doc/zh-CN/implemented/node.md +7 -0
- package/doc/zh-CN/implemented/storage.md +52 -0
- package/doc/zh-CN/implemented.md +4 -2
- package/doc/zh-CN/unimplemented/node/modules.md +3 -3
- package/doc/zh-CN/unimplemented/toolchain.md +1 -1
- package/package.json +16 -8
- package/runtime/ext_gui/dom_api_form.cpp +10 -0
- package/runtime/ext_gui/gui_media.cpp +1 -1
- package/runtime/ext_gui/media.cpp +1 -1
- package/runtime/ext_gui/media_api.h +2 -2
- package/runtime/ext_node/http2/http2.c +25 -11
- package/runtime/ext_node/http2/http2_backend.c +48 -0
- package/runtime/ext_node/http2/http2_bridge.c +25 -0
- package/runtime/ext_node/http2/parts/api.inc +40 -0
- package/runtime/ext_node/http2/parts/client.inc +215 -0
- package/runtime/ext_node/http2/parts/common.inc +330 -0
- package/runtime/ext_node/http2/parts/events.inc +139 -0
- package/runtime/ext_node/http2/parts/server.inc +301 -0
- package/runtime/ext_node/http2/parts/streams.inc +254 -0
- package/runtime/ext_node/tls/parts/api.inc +38 -0
- package/runtime/ext_node/tls/parts/connect.inc +107 -0
- package/runtime/ext_node/tls/parts/helpers.inc +121 -0
- package/runtime/ext_node/tls/parts/server.inc +101 -0
- package/runtime/ext_node/tls/parts/socket.inc +171 -0
- package/runtime/ext_node/tls/tls.c +21 -13
- package/runtime/ext_node/tls/tls_backend.c +50 -0
- package/runtime/ext_node/zlib/{miniz/compression_bridge.c → compression_bridge.c} +1 -1
- package/runtime/xt_fetch/async.inc +19 -12
- package/runtime/xt_fetch/socket.inc +55 -0
- package/runtime/xt_fetch.c +3 -0
- package/runtime/xt_http2/nghttp2_compat.h +19 -0
- package/runtime/xt_http2/nghttp2_static.h +18 -0
- package/runtime/xt_http2_api.h +38 -0
- package/runtime/xt_node_tls_api.h +37 -0
- package/runtime/xt_protocol_registry.c +22 -0
- package/runtime/xt_storage/indexed_db.c +408 -0
- package/runtime/xt_storage/indexed_db_internal.h +26 -0
- package/runtime/xt_storage/indexed_db_store.c +305 -0
- package/runtime/xt_storage/storage.c +209 -0
- package/runtime/xt_storage/storage_internal.h +66 -0
- package/runtime/xt_tls/parts/api.inc +21 -0
- package/runtime/xt_tls/parts/client.inc +112 -0
- package/runtime/xt_tls/parts/io.inc +157 -0
- package/runtime/xt_tls/parts/server.inc +102 -0
- package/runtime/xt_tls/parts/setup.inc +146 -0
- package/runtime/xt_tls/tls_bridge.c +27 -0
- package/runtime/xt_tls/tls_core.c +39 -0
- package/runtime/xt_tls/tls_internal.h +73 -0
- package/runtime/xt_tls_api.h +73 -0
- package/scripts/build-gui.ts +9 -8
- package/scripts/build-media.ts +2 -2
- package/scripts/build-tls.ts +248 -0
- package/scripts/check-file-length.ts +4 -21
- package/scripts/fetch-vendored.ts +244 -0
- package/scripts/package-release.ts +13 -3
- package/src/cli/main.ts +1 -0
- package/src/driver/build-key.ts +13 -2
- package/src/driver/compiler.ts +13 -0
- package/src/driver/config.ts +35 -0
- package/src/driver/fingerprint.ts +24 -0
- package/src/driver/index.ts +8 -0
- package/src/driver/link-features.ts +33 -11
- package/src/driver/options.ts +8 -1
- package/src/driver/paths.ts +20 -0
- package/src/driver/runtime-objects.ts +25 -6
- package/src/driver/storage.ts +84 -0
- package/src/driver/toolchain.ts +11 -2
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/features.ts +2 -2
- package/src/extensions/gui/index.ts +3 -1
- package/src/extensions/node/http2/feature.ts +33 -0
- package/src/extensions/node/http2/index.ts +6 -1
- package/src/extensions/node/index.ts +3 -1
- package/src/extensions/node/tls/feature.ts +29 -0
- package/src/extensions/node/tls/index.ts +5 -1
- package/src/extensions/node/zlib/compression.ts +11 -6
- package/src/extensions/registry.ts +9 -2
- package/src/extensions/storage.ts +58 -0
- package/src/extensions/tls.ts +52 -0
- package/vendor/sqlite3/sqlite3.c +271131 -0
- package/vendor/sqlite3/sqlite3.h +14447 -0
- package/{runtime/ext_gui → vendor/stb}/stb_image.h +17 -1
- /package/runtime/{ext_media → xt_media}/decode_audio.cpp +0 -0
- /package/runtime/{ext_media → xt_media}/media.cpp +0 -0
- /package/runtime/{ext_media → xt_media}/media_bridge.c +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz.c +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz.h +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_common.h +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_export.h +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tdef.c +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tdef.h +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tinfl.c +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tinfl.h +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_zip.h +0 -0
- /package/{runtime/ext_gui → vendor/nanosvg}/nanosvg.h +0 -0
- /package/{runtime/ext_gui → vendor/nanosvg}/nanosvgrast.h +0 -0
- /package/{runtime/ext_gui → vendor/stb}/stb_truetype.h +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Low-level TLS transport used by the core `fetch` implementation and by the
|
|
3
|
+
* Node `tls` module.
|
|
4
|
+
*
|
|
5
|
+
* The mbedTLS backend is an optional *link feature*: its archive is only linked
|
|
6
|
+
* when a program may use TLS, so this table is the only thing the always-linked
|
|
7
|
+
* runtime knows about it. `xt_protocol_registry.c` owns the (initially NULL)
|
|
8
|
+
* table; the feature's bridge installs the implementation in a constructor
|
|
9
|
+
* before `main` runs. When the table is NULL, `https://` requests reject and
|
|
10
|
+
* `node:tls` reports that TLS is unavailable, instead of failing at link time.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
#ifndef XT_TLS_API_H
|
|
14
|
+
#define XT_TLS_API_H
|
|
15
|
+
|
|
16
|
+
#include <stddef.h>
|
|
17
|
+
|
|
18
|
+
#ifdef __cplusplus
|
|
19
|
+
extern "C" {
|
|
20
|
+
#endif
|
|
21
|
+
|
|
22
|
+
/** One established TLS connection (client or accepted server side). */
|
|
23
|
+
typedef struct xt_tls_conn xt_tls_conn;
|
|
24
|
+
|
|
25
|
+
/** Server credentials and verification policy, reusable across connections. */
|
|
26
|
+
typedef struct xt_tls_server_config xt_tls_server_config;
|
|
27
|
+
|
|
28
|
+
typedef struct xt_tls_api {
|
|
29
|
+
/**
|
|
30
|
+
* Connect a TCP socket and perform the TLS handshake, blocking until both
|
|
31
|
+
* complete. `verify` enables certificate verification; `ca_pem` replaces the
|
|
32
|
+
* system trust store when non-NULL. `cert_pem`/`key_pem` present a client
|
|
33
|
+
* certificate. `alpn` is a comma-separated protocol list. Returns NULL on
|
|
34
|
+
* failure and writes a human-readable reason into `err`.
|
|
35
|
+
*/
|
|
36
|
+
xt_tls_conn *(*client_connect)(const char *host, int port, const char *servername, int verify,
|
|
37
|
+
const char *ca_pem, const char *cert_pem, const char *key_pem,
|
|
38
|
+
const char *alpn, char *err, size_t errlen);
|
|
39
|
+
/** Build the server credentials/verification policy from PEM strings. */
|
|
40
|
+
xt_tls_server_config *(*server_config)(const char *cert_pem, const char *key_pem,
|
|
41
|
+
const char *ca_pem, int request_cert, int verify,
|
|
42
|
+
const char *alpn, char *err, size_t errlen);
|
|
43
|
+
/** Wrap an accepted socket (blocking handshake); NULL on failure. */
|
|
44
|
+
xt_tls_conn *(*server_accept)(xt_tls_server_config *config, int fd, char *err, size_t errlen);
|
|
45
|
+
/** Decrypted read: positive byte count, 0 on orderly EOF, negative on error. */
|
|
46
|
+
int (*read)(xt_tls_conn *conn, unsigned char *buffer, size_t capacity);
|
|
47
|
+
/** Encrypt and write all bytes; returns 0 on success. */
|
|
48
|
+
int (*write)(xt_tls_conn *conn, const unsigned char *data, size_t length);
|
|
49
|
+
/** Send close_notify (best effort) without closing the descriptor. */
|
|
50
|
+
void (*shutdown)(xt_tls_conn *conn);
|
|
51
|
+
/** Send close_notify, close the descriptor and free `conn`. */
|
|
52
|
+
void (*close)(xt_tls_conn *conn);
|
|
53
|
+
/** Free `conn` without touching the descriptor (already closed). */
|
|
54
|
+
void (*conn_free)(xt_tls_conn *conn);
|
|
55
|
+
void (*config_free)(xt_tls_server_config *config);
|
|
56
|
+
/** Negotiated ALPN protocol, or NULL. */
|
|
57
|
+
const char *(*alpn)(xt_tls_conn *conn);
|
|
58
|
+
/** Last error message for `conn`, or NULL. */
|
|
59
|
+
const char *(*error)(xt_tls_conn *conn);
|
|
60
|
+
/** The underlying socket descriptor. */
|
|
61
|
+
int (*fd)(xt_tls_conn *conn);
|
|
62
|
+
} XtTlsApi;
|
|
63
|
+
|
|
64
|
+
/** The installed backend, or NULL when the `tls` link feature is not linked. */
|
|
65
|
+
extern const XtTlsApi *xt_tls_core_api;
|
|
66
|
+
|
|
67
|
+
void xt_tls_core_register(const XtTlsApi *api);
|
|
68
|
+
|
|
69
|
+
#ifdef __cplusplus
|
|
70
|
+
}
|
|
71
|
+
#endif
|
|
72
|
+
|
|
73
|
+
#endif /* XT_TLS_API_H */
|
package/scripts/build-gui.ts
CHANGED
|
@@ -12,22 +12,17 @@
|
|
|
12
12
|
* Steps:
|
|
13
13
|
* 1. fetch the pinned SDL3 source into `vendor/SDL` (gitignored),
|
|
14
14
|
* 2. build `libSDL3.a` with CMake,
|
|
15
|
-
* 2a. fetch + build static HarfBuzz
|
|
16
|
-
*
|
|
17
|
-
* 2b. fetch + build static glslang (GLSL ES -> SPIR-V) and SPIRV-Cross
|
|
18
|
-
* (SPIR-V -> Metal Shading Language),
|
|
15
|
+
* 2a. fetch + build static HarfBuzz/FreeType (optional `shaping`) and
|
|
16
|
+
* glslang/SPIRV-Cross (GLSL ES -> SPIR-V -> Metal Shading Language),
|
|
19
17
|
* 3. compile the engine translation units,
|
|
20
18
|
* 4. merge everything into `gui.a` (libtool on macOS, `ar -M` elsewhere;
|
|
21
19
|
* `gui.lib` on Windows, built from MSVC-compatible COFF objects).
|
|
22
|
-
*
|
|
23
20
|
* Media decoding is *not* part of this archive: it is an optional link feature
|
|
24
|
-
* of the `gui` extension (`npm run media`, `runtime/
|
|
21
|
+
* of the `gui` extension (`npm run media`, `runtime/xt_media/`), so a program
|
|
25
22
|
* that only renders HTML/CSS never links FFmpeg.
|
|
26
|
-
*
|
|
27
23
|
* Every library and every engine object is compiled with function/data sections;
|
|
28
24
|
* SDL is configured without the subsystems the engine never calls. The linker's
|
|
29
25
|
* dead-section pass can then drop whatever a particular program does not reach.
|
|
30
|
-
*
|
|
31
26
|
* Environment:
|
|
32
27
|
* xbintsc_CXX C++ compiler override (default: clang++ next to the resolved clang)
|
|
33
28
|
* xbintsc_CMAKE CMake override (default: a vendored CMake, then `cmake`)
|
|
@@ -61,6 +56,7 @@ import {
|
|
|
61
56
|
SECTION_FLAGS,
|
|
62
57
|
} from "./gui-build-options.js";
|
|
63
58
|
import { ensureDeploymentTarget } from "./gui-build-cache.js";
|
|
59
|
+
import { ensureVendoredSources } from "./fetch-vendored.js";
|
|
64
60
|
|
|
65
61
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
66
62
|
const runtimeDir = join(root, "runtime");
|
|
@@ -106,6 +102,9 @@ const output = join(outDir, isWindows ? "gui.lib" : "gui.a");
|
|
|
106
102
|
* oldest supported macOS, not the build machine's version. */
|
|
107
103
|
applyMacosDeploymentTarget();
|
|
108
104
|
|
|
105
|
+
/* Fetch the stb/NanoSVG headers the engine's default text/image paths include. */
|
|
106
|
+
ensureVendoredSources(["stb", "nanosvg"]);
|
|
107
|
+
|
|
109
108
|
const SDL_TAG = process.env.SDL3_TAG || "release-3.2.10";
|
|
110
109
|
const FREETYPE_VERSION = process.env.FREETYPE_VERSION || "2.13.3";
|
|
111
110
|
const HARFBUZZ_VERSION = process.env.HARFBUZZ_VERSION || "10.1.0";
|
|
@@ -522,6 +521,8 @@ if (metalBackend) {
|
|
|
522
521
|
mkdirSync(objDir, { recursive: true });
|
|
523
522
|
const includeFlags = [
|
|
524
523
|
"-I", runtimeDir,
|
|
524
|
+
"-I", join(vendorDir, "stb"),
|
|
525
|
+
"-I", join(vendorDir, "nanosvg"),
|
|
525
526
|
"-I", join(sdlSrc, "include"),
|
|
526
527
|
"-I", join(freetypeSrc, "include"),
|
|
527
528
|
"-I", join(freetypeBuild, "include"),
|
package/scripts/build-media.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* The GUI engine (`gui.a` / `gui.lib`) deliberately contains no decoder. This
|
|
9
9
|
* archive adds `<video>`/`<audio>` support: it bundles the FFmpeg-backed player
|
|
10
|
-
* from `runtime/
|
|
10
|
+
* from `runtime/xt_media/media.cpp` together with a minimal static FFmpeg, and
|
|
11
11
|
* the `media` extension links it only when the program asks for it. A program
|
|
12
12
|
* built with `--ext gui` alone therefore stays FFmpeg-free.
|
|
13
13
|
*
|
|
@@ -56,7 +56,7 @@ import { cxxCompileFlags } from "./gui-build-options.js";
|
|
|
56
56
|
|
|
57
57
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
58
58
|
const runtimeDir = join(root, "runtime");
|
|
59
|
-
const sourceDir = join(runtimeDir, "
|
|
59
|
+
const sourceDir = join(runtimeDir, "xt_media");
|
|
60
60
|
const vendorDir = join(root, "vendor");
|
|
61
61
|
const ffmpegSrc = join(vendorDir, "ffmpeg");
|
|
62
62
|
const isWindows = process.platform === "win32";
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Build the archives behind the `tls` and `http2` link features:
|
|
4
|
+
*
|
|
5
|
+
* runtime/lib/<os>-<arch>/tls.{a,lib} mbedTLS (TLS 1.2/1.3, X.509, PSA)
|
|
6
|
+
* runtime/lib/<os>-<arch>/nghttp2.{a,lib} nghttp2 (HTTP/2 framing + HPACK)
|
|
7
|
+
*
|
|
8
|
+
* Both libraries are fetched as release tarballs into `vendor/` (gitignored,
|
|
9
|
+
* like SDL/FFmpeg for `gui`/`media`) and compiled with the same toolchain the
|
|
10
|
+
* driver uses, so the objects match the rest of the runtime:
|
|
11
|
+
*
|
|
12
|
+
* - Windows: MSVC-compatible COFF objects, merged by `llvm-ar` into `.lib`.
|
|
13
|
+
* - Linux/macOS: ELF/Mach-O objects, merged by `llvm-ar`/`ar` into `.a`.
|
|
14
|
+
*
|
|
15
|
+
* The C wrappers that *use* these archives (`runtime/xt_tls/tls_core.c`,
|
|
16
|
+
* `runtime/xt_node/tls/...`, `runtime/ext_node/http2/...`) are compiled on
|
|
17
|
+
* demand by the driver, so this script only produces the third-party half.
|
|
18
|
+
*
|
|
19
|
+
* Environment:
|
|
20
|
+
* xbintsc_TLS mbedTLS release tag (default 3.6.2)
|
|
21
|
+
* xbintsc_NGHTTP2 nghttp2 release tag (default 1.64.0)
|
|
22
|
+
* xbintsc_CLANG C compiler override
|
|
23
|
+
* xbintsc_AR archiver override
|
|
24
|
+
*
|
|
25
|
+
* Run `npm run tls` after changing either pin; the e2e suites that need the
|
|
26
|
+
* archives skip when they are absent.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
30
|
+
import { spawnSync } from "node:child_process";
|
|
31
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
32
|
+
import { fileURLToPath } from "node:url";
|
|
33
|
+
import { platformSlug } from "../src/driver/paths.js";
|
|
34
|
+
import { applyMacosDeploymentTarget } from "../src/driver/platform-support.js";
|
|
35
|
+
import { resolveToolchain } from "../src/driver/toolchain-provider.js";
|
|
36
|
+
import { RUNTIME_CFLAGS, sysrootFlags } from "../src/driver/toolchain.js";
|
|
37
|
+
|
|
38
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
39
|
+
const vendorDir = join(root, "vendor");
|
|
40
|
+
const outDir = join(root, "runtime", "lib", platformSlug());
|
|
41
|
+
const objRoot = join(root, "build", "tls-obj");
|
|
42
|
+
const isWindows = process.platform === "win32";
|
|
43
|
+
const archiveSuffix = isWindows ? ".lib" : ".a";
|
|
44
|
+
|
|
45
|
+
const MBEDTLS_VERSION = process.env.xbintsc_TLS ?? "3.6.2";
|
|
46
|
+
const NGHTTP2_VERSION = process.env.xbintsc_NGHTTP2 ?? "1.64.0";
|
|
47
|
+
|
|
48
|
+
applyMacosDeploymentTarget();
|
|
49
|
+
|
|
50
|
+
const toolchain = resolveToolchain();
|
|
51
|
+
const clang = toolchain.clang;
|
|
52
|
+
const childEnv = Object.assign({}, process.env, toolchain.env);
|
|
53
|
+
|
|
54
|
+
function fail(message: string): never {
|
|
55
|
+
console.error(`xbintsc: ${message}`);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function run(command: string, args: readonly string[]): void {
|
|
60
|
+
const result = spawnSync(command, [...args], { stdio: "inherit", env: childEnv });
|
|
61
|
+
if (result.error) fail(`failed to run ${command}: ${result.error.message}`);
|
|
62
|
+
if (result.status !== 0) fail(`${command} ${args.join(" ")} failed (${result.status})`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function isRunnable(candidate: string): boolean {
|
|
66
|
+
return !spawnSync(candidate, [], { encoding: "utf8" }).error;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function findArchiver(clangPath: string): string {
|
|
70
|
+
const dir = dirname(clangPath);
|
|
71
|
+
const exe = isWindows ? ".exe" : "";
|
|
72
|
+
const candidates = [
|
|
73
|
+
process.env.xbintsc_AR,
|
|
74
|
+
dir === "." ? undefined : join(dir, `llvm-ar${exe}`),
|
|
75
|
+
"llvm-ar",
|
|
76
|
+
isWindows ? undefined : "ar",
|
|
77
|
+
].filter((candidate): candidate is string => Boolean(candidate));
|
|
78
|
+
for (const candidate of candidates) {
|
|
79
|
+
if (isRunnable(candidate)) return candidate;
|
|
80
|
+
}
|
|
81
|
+
return fail("no archiver found; install llvm-ar or set xbintsc_AR to it");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Download a release tarball and extract it under `vendor/<name>`. */
|
|
85
|
+
function ensureSource(name: string, url: string, extractedName: string, marker: string): string {
|
|
86
|
+
const destination = join(vendorDir, name);
|
|
87
|
+
if (existsSync(join(destination, marker))) return destination;
|
|
88
|
+
const tarball = join(vendorDir, `${name}.tar.gz`);
|
|
89
|
+
console.log(`xbintsc: fetching ${name} from ${url}`);
|
|
90
|
+
mkdirSync(vendorDir, { recursive: true });
|
|
91
|
+
run("curl", ["-sSL", "--fail", "--max-time", "300", "-o", tarball, url]);
|
|
92
|
+
run("tar", ["-xzf", tarball, "-C", vendorDir]);
|
|
93
|
+
const extracted = join(vendorDir, extractedName);
|
|
94
|
+
if (!existsSync(extracted)) fail(`expected ${extractedName} after extracting ${name}`);
|
|
95
|
+
rmSync(destination, { recursive: true, force: true });
|
|
96
|
+
renameSync(extracted, destination);
|
|
97
|
+
rmSync(tarball, { force: true });
|
|
98
|
+
return destination;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
interface LibraryBuild {
|
|
102
|
+
readonly name: string;
|
|
103
|
+
readonly sources: readonly string[];
|
|
104
|
+
readonly includeDirs: readonly string[];
|
|
105
|
+
readonly defines: readonly string[];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Newest modification time of the inputs, used to reuse a fresh archive. */
|
|
109
|
+
function newestSource(sources: readonly string[], dirs: readonly string[]): number {
|
|
110
|
+
let newest = 0;
|
|
111
|
+
const visit = (path: string): void => {
|
|
112
|
+
const info = statSync(path);
|
|
113
|
+
if (info.isDirectory()) {
|
|
114
|
+
for (const entry of readdirSync(path)) visit(join(path, entry));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (info.mtimeMs > newest) newest = info.mtimeMs;
|
|
118
|
+
};
|
|
119
|
+
for (const source of sources) visit(source);
|
|
120
|
+
for (const dir of dirs) visit(dir);
|
|
121
|
+
return newest;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function archiveIsFresh(library: LibraryBuild, output: string): boolean {
|
|
125
|
+
if (!existsSync(output)) return false;
|
|
126
|
+
try {
|
|
127
|
+
return statSync(output).mtimeMs >= newestSource(library.sources, library.includeDirs);
|
|
128
|
+
} catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function compileLibrary(library: LibraryBuild, output: string, ar: string): void {
|
|
134
|
+
if (archiveIsFresh(library, output)) {
|
|
135
|
+
console.log(`xbintsc: reusing existing ${output}`);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const objDir = join(objRoot, library.name);
|
|
139
|
+
rmSync(objDir, { recursive: true, force: true });
|
|
140
|
+
mkdirSync(objDir, { recursive: true });
|
|
141
|
+
const objects: string[] = [];
|
|
142
|
+
library.sources.forEach((source, index) => {
|
|
143
|
+
const object = join(objDir, `${index}_${basename(source, ".c")}.o`);
|
|
144
|
+
const args = [
|
|
145
|
+
...RUNTIME_CFLAGS,
|
|
146
|
+
...sysrootFlags(toolchain.sdkRoot),
|
|
147
|
+
...library.defines,
|
|
148
|
+
...library.includeDirs.map((dir) => `-I${dir}`),
|
|
149
|
+
"-c",
|
|
150
|
+
source,
|
|
151
|
+
"-o",
|
|
152
|
+
object,
|
|
153
|
+
];
|
|
154
|
+
const result = spawnSync(clang, args, { stdio: ["ignore", "ignore", "pipe"], env: childEnv, encoding: "utf8" });
|
|
155
|
+
if (result.status !== 0) {
|
|
156
|
+
process.stderr.write(result.stderr ?? "");
|
|
157
|
+
fail(`failed to compile ${source}`);
|
|
158
|
+
}
|
|
159
|
+
objects.push(object);
|
|
160
|
+
});
|
|
161
|
+
mkdirSync(dirname(output), { recursive: true });
|
|
162
|
+
rmSync(output, { force: true });
|
|
163
|
+
run(ar, ["rcs", output, ...objects]);
|
|
164
|
+
console.log(`xbintsc: wrote ${output}`);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function cSources(dir: string): string[] {
|
|
168
|
+
return readdirSync(dir)
|
|
169
|
+
.filter((name) => name.endsWith(".c"))
|
|
170
|
+
.sort()
|
|
171
|
+
.map((name) => join(dir, name));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/* -- mbedTLS -------------------------------------------------------------- */
|
|
175
|
+
|
|
176
|
+
const mbedtlsDir = ensureSource(
|
|
177
|
+
"mbedtls",
|
|
178
|
+
`https://codeload.github.com/Mbed-TLS/mbedtls/tar.gz/refs/tags/mbedtls-${MBEDTLS_VERSION}`,
|
|
179
|
+
`mbedtls-mbedtls-${MBEDTLS_VERSION}`,
|
|
180
|
+
join("library", "ssl_tls.c"),
|
|
181
|
+
);
|
|
182
|
+
const mbedtlsLibrary: LibraryBuild = {
|
|
183
|
+
name: "tls",
|
|
184
|
+
// The backend wrapper is archived too: its bridge (`tls_bridge.c`) is what
|
|
185
|
+
// the driver compiles, so an installed npm package needs no vendor headers.
|
|
186
|
+
sources: [...cSources(join(mbedtlsDir, "library")), join(root, "runtime", "xt_tls", "tls_core.c")],
|
|
187
|
+
includeDirs: [join(mbedtlsDir, "include"), join(mbedtlsDir, "library"), join(root, "runtime")],
|
|
188
|
+
defines: [],
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/* -- nghttp2 -------------------------------------------------------------- */
|
|
192
|
+
|
|
193
|
+
const nghttp2Dir = ensureSource(
|
|
194
|
+
"nghttp2",
|
|
195
|
+
`https://codeload.github.com/nghttp2/nghttp2/tar.gz/refs/tags/v${NGHTTP2_VERSION}`,
|
|
196
|
+
`nghttp2-${NGHTTP2_VERSION}`,
|
|
197
|
+
join("lib", "nghttp2_session.c"),
|
|
198
|
+
);
|
|
199
|
+
/**
|
|
200
|
+
* nghttp2's public headers expect a generated `nghttp2ver.h`; generate it
|
|
201
|
+
* exactly as its autotools build does. The number is the 24-bit
|
|
202
|
+
* major/minor/patch representation (1.64.0 -> 0x014000).
|
|
203
|
+
*/
|
|
204
|
+
const versionParts = NGHTTP2_VERSION.split(".").map((part) => Number(part) || 0);
|
|
205
|
+
const ngHeader = join(nghttp2Dir, "lib", "includes", "nghttp2", "nghttp2ver.h");
|
|
206
|
+
const ngTemplate = join(nghttp2Dir, "lib", "includes", "nghttp2", "nghttp2ver.h.in");
|
|
207
|
+
const versionNum = `0x${versionParts
|
|
208
|
+
.map((part) => part.toString(16).padStart(2, "0"))
|
|
209
|
+
.join("")}`;
|
|
210
|
+
writeFileSync(
|
|
211
|
+
ngHeader,
|
|
212
|
+
readFileSync(ngTemplate, "utf8")
|
|
213
|
+
.replaceAll("@PACKAGE_VERSION@", NGHTTP2_VERSION)
|
|
214
|
+
.replaceAll("@PACKAGE_VERSION_NUM@", versionNum),
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
const nghttp2Library: LibraryBuild = {
|
|
218
|
+
name: "nghttp2",
|
|
219
|
+
// `nghttp2_alpn.c` only wraps NPN/ALPN helper callbacks for TLS backends; it
|
|
220
|
+
// is part of the public library surface, so keep it.
|
|
221
|
+
sources: [
|
|
222
|
+
...cSources(join(nghttp2Dir, "lib")),
|
|
223
|
+
join(root, "runtime", "ext_node", "http2", "http2_backend.c"),
|
|
224
|
+
],
|
|
225
|
+
includeDirs: [
|
|
226
|
+
join(nghttp2Dir, "lib", "includes"),
|
|
227
|
+
join(nghttp2Dir, "lib"),
|
|
228
|
+
join(root, "runtime"),
|
|
229
|
+
],
|
|
230
|
+
// nghttp2's public header uses POSIX `ssize_t`; MSVC/UCRT has none.
|
|
231
|
+
defines: [
|
|
232
|
+
"-DNGHTTP2_STATICLIB",
|
|
233
|
+
// `nghttp2_net.h` only includes `<arpa/inet.h>`/`<netinet/in.h>` when its
|
|
234
|
+
// generated `config.h` (which this build has none of) says the host has
|
|
235
|
+
// them. Without those includes `htonl`/`htons` are implicit, which clang
|
|
236
|
+
// 16 and newer reject in C99 mode; declare them on every POSIX host.
|
|
237
|
+
// Windows takes `nghttp2_net.h`'s `WIN32` branch, which defines the
|
|
238
|
+
// byte-order helpers inline.
|
|
239
|
+
...(isWindows ? [] : ["-DHAVE_ARPA_INET_H", "-DHAVE_NETINET_IN_H"]),
|
|
240
|
+
"-include",
|
|
241
|
+
join(root, "runtime", "xt_http2", "nghttp2_compat.h"),
|
|
242
|
+
],
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
console.log(`xbintsc: TLS toolchain ${clang} (${toolchain.source})`);
|
|
246
|
+
const ar = findArchiver(clang);
|
|
247
|
+
compileLibrary(mbedtlsLibrary, join(outDir, `tls${archiveSuffix}`), ar);
|
|
248
|
+
compileLibrary(nghttp2Library, join(outDir, `nghttp2${archiveSuffix}`), ar);
|
|
@@ -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
|
-
*
|
|
11
|
-
*
|
|
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,24 +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
|
-
]);
|
|
55
|
-
|
|
56
39
|
/** Machine-generated files: they are reproduced from their sources by a script,
|
|
57
40
|
* so their size is not a sign of a module that needs splitting. */
|
|
58
41
|
const GENERATED_FILES = new Set([join("runtime", "ext_gui", "renderer_shaders_data.h")]);
|
|
@@ -84,7 +67,7 @@ function collect(dir: string, offenses: Offense[]): void {
|
|
|
84
67
|
const dot = entry.name.lastIndexOf(".");
|
|
85
68
|
if (dot < 0 || !CODE_EXTENSIONS.has(entry.name.slice(dot))) continue;
|
|
86
69
|
const file = relative(root, full);
|
|
87
|
-
if (
|
|
70
|
+
if (GENERATED_FILES.has(file)) continue;
|
|
88
71
|
const lines = countLines(full);
|
|
89
72
|
if (lines > MAX_LINES) offenses.push({ file, lines });
|
|
90
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
|
+
}
|