xbintsc 0.5.31 → 0.5.32

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 (181) hide show
  1. package/README.md +16 -10
  2. package/dist/src/binder/references.js +14 -1
  3. package/dist/src/binder/references.js.map +1 -1
  4. package/dist/src/cli/help.d.ts +1 -1
  5. package/dist/src/codegen/generator/module.d.ts +1 -0
  6. package/dist/src/codegen/generator/module.js +54 -0
  7. package/dist/src/codegen/generator/module.js.map +1 -1
  8. package/dist/src/codegen/generator/statements/variables.js +6 -4
  9. package/dist/src/codegen/generator/statements/variables.js.map +1 -1
  10. package/dist/src/driver/version.d.ts +1 -1
  11. package/dist/src/driver/version.js +1 -1
  12. package/dist/src/extensions/gui/css.d.ts +26 -0
  13. package/dist/src/extensions/gui/css.js +100 -0
  14. package/dist/src/extensions/gui/css.js.map +1 -0
  15. package/dist/src/extensions/gui/html.js +9 -2
  16. package/dist/src/extensions/gui/html.js.map +1 -1
  17. package/dist/src/extensions/gui/index.js +16 -2
  18. package/dist/src/extensions/gui/index.js.map +1 -1
  19. package/dist/src/extensions/gui/three.d.ts +16 -0
  20. package/dist/src/extensions/gui/three.js +22 -0
  21. package/dist/src/extensions/gui/three.js.map +1 -0
  22. package/dist/src/extensions/media/index.d.ts +6 -5
  23. package/dist/src/extensions/media/index.js +12 -14
  24. package/dist/src/extensions/media/index.js.map +1 -1
  25. package/dist/tests/e2e/compile-builtins.test.js +24 -0
  26. package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
  27. package/dist/tests/e2e/compile-objects-classes.test.js +23 -0
  28. package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
  29. package/dist/tests/e2e/gui-browser.test.js +1 -1
  30. package/dist/tests/e2e/gui-browser.test.js.map +1 -1
  31. package/dist/tests/e2e/gui-effects.test.d.ts +6 -0
  32. package/dist/tests/e2e/gui-effects.test.js +262 -0
  33. package/dist/tests/e2e/gui-effects.test.js.map +1 -0
  34. package/dist/tests/e2e/gui-example-webgl.test.d.ts +10 -0
  35. package/dist/tests/e2e/gui-example-webgl.test.js +75 -0
  36. package/dist/tests/e2e/gui-example-webgl.test.js.map +1 -0
  37. package/dist/tests/e2e/gui-example-webgl2.test.d.ts +8 -0
  38. package/dist/tests/e2e/gui-example-webgl2.test.js +72 -0
  39. package/dist/tests/e2e/gui-example-webgl2.test.js.map +1 -0
  40. package/dist/tests/e2e/gui-layout.test.js +48 -0
  41. package/dist/tests/e2e/gui-layout.test.js.map +1 -1
  42. package/dist/tests/e2e/gui-media.test.js +5 -4
  43. package/dist/tests/e2e/gui-media.test.js.map +1 -1
  44. package/dist/tests/e2e/gui-webgl.test.d.ts +11 -0
  45. package/dist/tests/e2e/gui-webgl.test.js +179 -0
  46. package/dist/tests/e2e/gui-webgl.test.js.map +1 -0
  47. package/dist/tests/e2e/gui-webgl2.test.d.ts +10 -0
  48. package/dist/tests/e2e/gui-webgl2.test.js +238 -0
  49. package/dist/tests/e2e/gui-webgl2.test.js.map +1 -0
  50. package/dist/tests/extensions/gui.test.js +41 -0
  51. package/dist/tests/extensions/gui.test.js.map +1 -1
  52. package/dist/tests/extensions/media.test.js +7 -3
  53. package/dist/tests/extensions/media.test.js.map +1 -1
  54. package/doc/ai/extensions.md +29 -9
  55. package/doc/ai/troubleshooting.md +12 -8
  56. package/doc/ai/zh-CN/extensions.md +26 -8
  57. package/doc/ai/zh-CN/troubleshooting.md +10 -6
  58. package/doc/gui/api.md +3 -2
  59. package/doc/gui/build.md +72 -16
  60. package/doc/gui/canvas.md +11 -3
  61. package/doc/gui/dom.md +33 -18
  62. package/doc/gui/known-issues.md +57 -24
  63. package/doc/gui/layout.md +18 -0
  64. package/doc/gui/media.md +17 -13
  65. package/doc/gui/rendering.md +50 -3
  66. package/doc/gui/webgl.md +256 -0
  67. package/doc/gui.md +108 -17
  68. package/doc/npm-package.md +6 -4
  69. package/doc/requirements.md +18 -9
  70. package/doc/zh-CN/gui/api.md +3 -2
  71. package/doc/zh-CN/gui/build.md +64 -15
  72. package/doc/zh-CN/gui/canvas.md +9 -2
  73. package/doc/zh-CN/gui/dom.md +20 -7
  74. package/doc/zh-CN/gui/known-issues.md +45 -19
  75. package/doc/zh-CN/gui/layout.md +14 -0
  76. package/doc/zh-CN/gui/media.md +15 -11
  77. package/doc/zh-CN/gui/rendering.md +41 -4
  78. package/doc/zh-CN/gui/webgl.md +115 -0
  79. package/doc/zh-CN/gui.md +89 -14
  80. package/doc/zh-CN/npm-package.md +9 -6
  81. package/doc/zh-CN/requirements.md +12 -6
  82. package/llms.txt +2 -0
  83. package/package.json +1 -1
  84. package/runtime/ext_gui/browser.cpp +39 -13
  85. package/runtime/ext_gui/canvas.cpp +3 -18
  86. package/runtime/ext_gui/canvas_internal.h +10 -0
  87. package/runtime/ext_gui/canvas_raster.cpp +60 -0
  88. package/runtime/ext_gui/clip_values.cpp +246 -0
  89. package/runtime/ext_gui/css.cpp +94 -0
  90. package/runtime/ext_gui/css.h +22 -1
  91. package/runtime/ext_gui/css_match.cpp +3 -0
  92. package/runtime/ext_gui/css_selector.cpp +9 -0
  93. package/runtime/ext_gui/css_sheet.cpp +89 -45
  94. package/runtime/ext_gui/document.cpp +4 -1
  95. package/runtime/ext_gui/document.h +2 -0
  96. package/runtime/ext_gui/dom.h +16 -0
  97. package/runtime/ext_gui/dom_api.cpp +1 -0
  98. package/runtime/ext_gui/dom_api_canvas.cpp +17 -80
  99. package/runtime/ext_gui/dom_api_canvas_extra.cpp +130 -1
  100. package/runtime/ext_gui/dom_api_canvas_pending.cpp +41 -0
  101. package/runtime/ext_gui/dom_api_internal.h +259 -0
  102. package/runtime/ext_gui/dom_api_webgl.cpp +376 -0
  103. package/runtime/ext_gui/dom_api_webgl2.cpp +434 -0
  104. package/runtime/ext_gui/dom_api_webgl2_draw.cpp +269 -0
  105. package/runtime/ext_gui/dom_api_webgl_buffer.cpp +212 -0
  106. package/runtime/ext_gui/dom_api_webgl_rt.h +30 -0
  107. package/runtime/ext_gui/dom_api_webgl_shader.cpp +443 -0
  108. package/runtime/ext_gui/dom_api_webgl_state.cpp +444 -0
  109. package/runtime/ext_gui/dom_api_webgl_texture.cpp +445 -0
  110. package/runtime/ext_gui/effect_values.cpp +312 -0
  111. package/runtime/ext_gui/gradient_values.cpp +476 -0
  112. package/runtime/ext_gui/grid_values.cpp +230 -0
  113. package/runtime/ext_gui/gui_canvas.cpp +50 -2
  114. package/runtime/ext_gui/gui_engine.h +27 -0
  115. package/runtime/ext_gui/gui_events.cpp +4 -1
  116. package/runtime/ext_gui/gui_media.cpp +1 -1
  117. package/runtime/ext_gui/gui_webgl.cpp +83 -0
  118. package/runtime/ext_gui/layout.cpp +21 -0
  119. package/runtime/ext_gui/layout_flow.cpp +81 -4
  120. package/runtime/ext_gui/layout_flow_internal.h +31 -0
  121. package/runtime/ext_gui/layout_grid.cpp +374 -0
  122. package/runtime/ext_gui/media.h +1 -1
  123. package/runtime/ext_gui/media_api.h +2 -2
  124. package/runtime/ext_gui/media_query.cpp +211 -0
  125. package/runtime/ext_gui/paint.cpp +111 -77
  126. package/runtime/ext_gui/paint.h +33 -3
  127. package/runtime/ext_gui/paint_background.cpp +229 -0
  128. package/runtime/ext_gui/paint_clip.cpp +268 -0
  129. package/runtime/ext_gui/paint_effects.cpp +324 -0
  130. package/runtime/ext_gui/paint_internal.h +85 -0
  131. package/runtime/ext_gui/renderer.cpp +8 -31
  132. package/runtime/ext_gui/renderer_clip.cpp +196 -0
  133. package/runtime/ext_gui/renderer_image.cpp +13 -8
  134. package/runtime/ext_gui/renderer_internal.h +15 -8
  135. package/runtime/ext_gui/renderer_text.cpp +6 -31
  136. package/runtime/ext_gui/style.cpp +343 -20
  137. package/runtime/ext_gui/style.h +144 -3
  138. package/runtime/ext_gui/style_print.cpp +134 -1
  139. package/runtime/ext_gui/style_values.cpp +152 -126
  140. package/runtime/ext_gui/style_values_internal.h +35 -0
  141. package/runtime/ext_gui/webgl.h +466 -0
  142. package/runtime/ext_gui/webgl2_constants.h +274 -0
  143. package/runtime/ext_gui/webgl_buffer.cpp +565 -0
  144. package/runtime/ext_gui/webgl_constants.h +317 -0
  145. package/runtime/ext_gui/webgl_context.cpp +466 -0
  146. package/runtime/ext_gui/webgl_draw.cpp +495 -0
  147. package/runtime/ext_gui/webgl_glsl.h +125 -0
  148. package/runtime/ext_gui/webgl_glsl_compile.cpp +431 -0
  149. package/runtime/ext_gui/webgl_glsl_rewrite.cpp +349 -0
  150. package/runtime/ext_gui/webgl_glsl_scan.cpp +581 -0
  151. package/runtime/ext_gui/webgl_msl.cpp +62 -0
  152. package/runtime/ext_gui/webgl_msl.h +33 -0
  153. package/runtime/ext_gui/webgl_pipeline.cpp +274 -0
  154. package/runtime/ext_gui/webgl_program_internal.h +18 -0
  155. package/runtime/ext_gui/webgl_shader.cpp +582 -0
  156. package/runtime/ext_gui/webgl_texture.cpp +293 -0
  157. package/runtime/ext_gui/webgl_uniform.cpp +167 -0
  158. package/runtime/ext_gui/webgl_webgl2.cpp +224 -0
  159. package/runtime/ext_media/media.cpp +1 -1
  160. package/runtime/ext_media/media_bridge.c +9 -3
  161. package/runtime/rt_internal.h +1 -0
  162. package/runtime/xt_containers/access.inc +8 -0
  163. package/runtime/xt_regex/api.inc +2 -0
  164. package/runtime/xt_regex/matcher.inc +16 -3
  165. package/runtime/xt_regex/parser.inc +8 -2
  166. package/runtime/xt_regex/types.inc +3 -0
  167. package/runtime/xt_stdlib2/regexp-match.inc +60 -21
  168. package/runtime/xt_stdlib2/regexp.inc +1 -0
  169. package/runtime/xt_typed_array.c +1 -1
  170. package/scripts/build-gui.ts +90 -3
  171. package/scripts/build-media.ts +323 -58
  172. package/scripts/setup-vs-toolchain.ps1 +152 -0
  173. package/src/binder/references.ts +13 -1
  174. package/src/codegen/generator/module.ts +50 -0
  175. package/src/codegen/generator/statements/variables.ts +6 -3
  176. package/src/driver/version.ts +1 -1
  177. package/src/extensions/gui/css.ts +113 -0
  178. package/src/extensions/gui/html.ts +9 -2
  179. package/src/extensions/gui/index.ts +16 -2
  180. package/src/extensions/gui/three.ts +25 -0
  181. package/src/extensions/media/index.ts +13 -16
@@ -2,38 +2,53 @@
2
2
  /**
3
3
  * Build the media extension archive:
4
4
  *
5
- * runtime/lib/<os>-<arch>/media.a
5
+ * runtime/lib/<os>-<arch>/media.a (POSIX: ELF/Mach-O objects)
6
+ * runtime/lib/<os>-<arch>/media.lib (Windows: MSVC/COFF objects)
6
7
  *
7
- * The GUI engine (`gui.a`) deliberately contains no decoder. This archive adds
8
- * `<video>`/`<audio>` support: it bundles the FFmpeg-backed player from
9
- * `runtime/ext_media/media.cpp` together with a minimal static FFmpeg, and the
10
- * `media` extension links it only when the program asks for it. A program built
11
- * with `--ext gui` alone therefore stays FFmpeg-free.
8
+ * The GUI engine (`gui.a` / `gui.lib`) deliberately contains no decoder. This
9
+ * archive adds `<video>`/`<audio>` support: it bundles the FFmpeg-backed player
10
+ * from `runtime/ext_media/media.cpp` together with a minimal static FFmpeg, and
11
+ * the `media` extension links it only when the program asks for it. A program
12
+ * built with `--ext gui` alone therefore stays FFmpeg-free.
12
13
  *
13
14
  * Steps:
14
15
  * 1. fetch the pinned FFmpeg release tarball into `vendor/ffmpeg`,
15
16
  * 2. configure and build a minimal static FFmpeg into
16
17
  * `vendor/ffmpeg-build/dist` (reused on later runs),
17
18
  * 3. compile the player against those headers,
18
- * 4. merge the player object and the FFmpeg libraries into `media.a`
19
- * (libtool on macOS, `ar -M` elsewhere).
19
+ * 4. merge the player object and the FFmpeg libraries into the archive
20
+ * (libtool on macOS, `ar -M`/`llvm-ar -M` elsewhere).
21
+ *
22
+ * Windows uses FFmpeg's own MSVC toolchain mode: `configure --toolchain=msvc
23
+ * --cc=clang-cl` produces COFF objects compiled against the static MSVC CRT,
24
+ * which is the ABI `gui.lib`, the xbintsc runtime and the final link use. The
25
+ * compiler chain is entirely Visual Studio (clang-cl, cl.exe, lib.exe and
26
+ * llvm-ar); no additional C/C++ toolchain is involved.
27
+ *
28
+ * FFmpeg's `configure` is a POSIX shell script and its Makefiles require GNU
29
+ * make, so those two build drivers remain. The shell comes from Git for Windows
30
+ * (already required to clone SDL3), and make is a native GNU make on PATH or
31
+ * `xbintsc_MAKE`; no additional POSIX environment is required. Because native
32
+ * make cannot pass the MSVC `/showIncludes` awk pipeline through the Windows
33
+ * command line unchanged, the generated `SRC_PATH` is rewritten to a
34
+ * drive-letter path and dependency generation is skipped. Headers/libraries are
35
+ * copied into the prefix instead of running `make install`.
20
36
  *
21
37
  * Environment:
22
38
  * xbintsc_CXX C++ compiler override (default: clang++ next to clang)
23
39
  * xbintsc_AR archiver override (default: llvm-ar next to clang, then ar)
40
+ * xbintsc_SHELL POSIX shell override (Windows; default: Git for Windows bash)
41
+ * xbintsc_MAKE GNU make override (Windows; default: `make` on PATH)
24
42
  * FFMPEG_VERSION FFmpeg release (default: 7.1)
25
- *
26
- * Windows is not supported yet: FFmpeg needs its own `configure`/`make`, and an
27
- * MSVC-compatible build has not been produced (see `doc/gui/known-issues.md`).
28
43
  */
29
44
 
30
- import { existsSync, mkdirSync, renameSync, rmSync } from "node:fs";
45
+ import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
31
46
  import { availableParallelism } from "node:os";
32
47
  import { spawnSync, type SpawnSyncReturns } from "node:child_process";
33
48
  import { dirname, join, resolve } from "node:path";
34
49
  import { fileURLToPath } from "node:url";
35
50
  import { platformSlug } from "../src/driver/paths.js";
36
- import { probeClang, realRunner } from "../src/driver/toolchain.js";
51
+ import { isMsvcTarget, probeClang, realRunner } from "../src/driver/toolchain.js";
37
52
  import { resolveToolchain } from "../src/driver/toolchain-provider.js";
38
53
 
39
54
  const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
@@ -41,11 +56,16 @@ const runtimeDir = join(root, "runtime");
41
56
  const sourceDir = join(runtimeDir, "ext_media");
42
57
  const vendorDir = join(root, "vendor");
43
58
  const ffmpegSrc = join(vendorDir, "ffmpeg");
44
- const ffmpegBuild = join(vendorDir, "ffmpeg-build");
59
+ const isWindows = process.platform === "win32";
60
+ /* The MSVC configure/build tree is kept apart from the POSIX one: a shared tree
61
+ * would carry `CC=clang`/`CC=clang-cl` and a POSIX/Windows `SRC_PATH` from the
62
+ * other platform into the next configure. */
63
+ const ffmpegBuild = join(vendorDir, isWindows ? "ffmpeg-build-msvc" : "ffmpeg-build");
45
64
  const ffmpegInstall = join(ffmpegBuild, "dist");
46
65
  const objDir = join(root, "build", "media-obj");
47
66
  const outDir = join(runtimeDir, "lib", platformSlug());
48
- const output = join(outDir, "media.a");
67
+ const output = join(outDir, isWindows ? "media.lib" : "media.a");
68
+ const object = join(objDir, isWindows ? "media.obj" : "media.o");
49
69
 
50
70
  const FFMPEG_VERSION = process.env.FFMPEG_VERSION || "7.1";
51
71
  const FFMPEG_URL = `https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.xz`;
@@ -74,7 +94,7 @@ function fail(message: string): never {
74
94
  function run(
75
95
  command: string,
76
96
  args: readonly string[],
77
- options: { input?: string; quietStderr?: boolean; cwd?: string } = {},
97
+ options: { input?: string; quietStderr?: boolean; cwd?: string; env?: NodeJS.ProcessEnv } = {},
78
98
  ): SpawnSyncReturns<string> {
79
99
  const quiet = options.quietStderr === true;
80
100
  const result = spawnSync(command, args, {
@@ -82,6 +102,7 @@ function run(
82
102
  encoding: "utf8",
83
103
  input: options.input,
84
104
  cwd: options.cwd,
105
+ env: options.env,
85
106
  });
86
107
  if (result.status !== 0) {
87
108
  if (quiet && result.stderr) process.stderr.write(result.stderr);
@@ -104,7 +125,7 @@ function firstAvailable(candidates: readonly (string | undefined)[]): string | u
104
125
  /** The tool that sits next to `clang` in the same LLVM installation. */
105
126
  function siblingTool(clangPath: string, name: string): string | undefined {
106
127
  if (!clangPath.includes("/") && !clangPath.includes("\\")) return undefined;
107
- const candidate = join(dirname(clangPath), `${name}.exe`);
128
+ const candidate = join(dirname(clangPath), `${name}${isWindows ? ".exe" : ""}`);
108
129
  if (existsSync(candidate)) return candidate;
109
130
  const bare = join(dirname(clangPath), name);
110
131
  return existsSync(bare) ? bare : undefined;
@@ -116,6 +137,12 @@ function findClangxx(clangPath: string): string {
116
137
  if (override) {
117
138
  const probe = probeClang(realRunner, override);
118
139
  if (!probe.responds) fail(`xbintsc_CXX ${override} does not respond to --version`);
140
+ if (isWindows && (probe.version === undefined || (probe.target !== undefined && !isMsvcTarget(probe.target)))) {
141
+ fail(
142
+ `xbintsc_CXX ${override} is not an MSVC-targeting clang++ (target ${probe.target ?? "unknown"}); ` +
143
+ "the Windows media build requires one, for example x86_64-pc-windows-msvc.",
144
+ );
145
+ }
119
146
  return override;
120
147
  }
121
148
  const sibling = siblingTool(clangPath, "clang++");
@@ -128,7 +155,9 @@ function findClangxx(clangPath: string): string {
128
155
  /** Resolve the archiver that matches the compiler, preferring LLVM's own. */
129
156
  function findArchiver(clangPath: string): string {
130
157
  const sibling = siblingTool(clangPath, "llvm-ar");
131
- const archiver = firstAvailable([process.env.xbintsc_AR, sibling, "llvm-ar", "ar"]);
158
+ /* Windows always uses llvm-ar: a non-LLVM `ar` there may write a different
159
+ * archive flavour than the COFF one the linker wants. */
160
+ const archiver = firstAvailable([process.env.xbintsc_AR, sibling, "llvm-ar", isWindows ? undefined : "ar"]);
132
161
  if (!archiver) fail("no archiver found; install llvm-ar or set xbintsc_AR");
133
162
  return archiver;
134
163
  }
@@ -161,47 +190,284 @@ function ffmpegStaticLibraries(): string[] | undefined {
161
190
  return libraries.every((library) => existsSync(library)) ? libraries : undefined;
162
191
  }
163
192
 
164
- if (process.platform === "win32") {
193
+ /** True when `dist` holds both the libraries and the installed headers. */
194
+ function ffmpegInstalled(): boolean {
195
+ return ffmpegStaticLibraries() !== undefined && existsSync(join(ffmpegInstall, "include", "libavutil", "avutil.h"));
196
+ }
197
+
198
+ /** Arguments shared by the POSIX and Windows FFmpeg configure runs. */
199
+ function ffmpegConfigureArgs(): string[] {
200
+ const prefix = isWindows ? ffmpegInstall.replace(/\\/g, "/") : ffmpegInstall;
201
+ const args = [
202
+ `--prefix=${prefix}`,
203
+ "--enable-static", "--disable-shared",
204
+ "--disable-programs", "--disable-doc",
205
+ "--disable-htmlpages", "--disable-manpages", "--disable-podpages", "--disable-txtpages",
206
+ "--disable-avdevice", "--disable-avfilter", "--disable-postproc",
207
+ "--disable-everything",
208
+ "--enable-avformat", "--enable-avcodec", "--enable-avutil", "--enable-swscale", "--enable-swresample",
209
+ "--disable-network", "--disable-autodetect", "--disable-x86asm", "--disable-debug",
210
+ ...FFMPEG_COMPONENTS,
211
+ ];
212
+ /* `-fPIC` is meaningless to the MSVC ABI; FFmpeg's msvc flag filter drops it,
213
+ * but omitting it keeps the configuration honest. */
214
+ if (!isWindows) args.splice(2, 0, "--enable-pic");
215
+ return args;
216
+ }
217
+
218
+ /* -- Windows: a POSIX shell + GNU make driving clang-cl -------------------- */
219
+
220
+ /** Drive-letter path in the `/d/dir/file` form the POSIX shell and configure use. */
221
+ function toPosixPath(path: string): string {
222
+ const absolute = resolve(path);
223
+ const match = /^([A-Za-z]):[\\/](.*)$/.exec(absolute);
224
+ if (!match) return absolute.replace(/\\/g, "/");
225
+ return `/${match[1].toLowerCase()}/${match[2].replace(/\\/g, "/")}`;
226
+ }
227
+
228
+ /** `D:\dir` form for the native make parser (it does not understand `/d/dir`). */
229
+ function toWindowsPath(path: string): string {
230
+ return resolve(path).replace(/\\/g, "/");
231
+ }
232
+
233
+ /** Quote one word for a POSIX shell command line built by hand. */
234
+ function shellQuote(word: string): string {
235
+ return `'${word.replace(/'/g, `'\\''`)}'`;
236
+ }
237
+
238
+ /** Git for Windows' bash, which supplies the POSIX shell FFmpeg's configure needs. */
239
+ function findPosixShell(): string {
240
+ const programFiles = process.env.ProgramFiles ?? "C:\\Program Files";
241
+ const localAppData = process.env.LOCALAPPDATA ?? "";
242
+ const git = resolveOnPath("git");
243
+ const candidates = [
244
+ process.env.xbintsc_SHELL,
245
+ git ? resolve(dirname(git), "..", "bin", "bash.exe") : undefined,
246
+ join(programFiles, "Git", "bin", "bash.exe"),
247
+ join(localAppData, "Programs", "Git", "bin", "bash.exe"),
248
+ join(programFiles, "Git", "usr", "bin", "bash.exe"),
249
+ ].filter((candidate): candidate is string => Boolean(candidate));
250
+ const shell = firstAvailable(candidates);
251
+ if (!shell) {
252
+ fail(
253
+ "the Windows media build needs a POSIX shell to run FFmpeg's configure; " +
254
+ "install Git for Windows (which also supplies git) or set xbintsc_SHELL.",
255
+ );
256
+ }
257
+ return shell;
258
+ }
259
+
260
+ /** First match for `name` on PATH, as an absolute path. */
261
+ function resolveOnPath(name: string): string | undefined {
262
+ const result = spawnSync("where.exe", [name], { encoding: "utf8" });
263
+ if (result.status !== 0) return undefined;
264
+ return result.stdout.split(/\r?\n/).map((line) => line.trim()).find((line) => line.length > 0);
265
+ }
266
+
267
+ /** Native GNU make to drive the FFmpeg build. */
268
+ function findWindowsMake(): string {
269
+ const candidates = [process.env.xbintsc_MAKE, resolveOnPath("make")].filter(
270
+ (candidate): candidate is string => Boolean(candidate),
271
+ );
272
+ for (const candidate of candidates) {
273
+ if (isRunnable(candidate)) return candidate;
274
+ }
275
+ fail(
276
+ "the Windows media build needs GNU make to run FFmpeg's Makefile; install it " +
277
+ "(`choco install make`) or set xbintsc_MAKE to a GNU make binary.",
278
+ );
279
+ }
280
+
281
+ /** Resolve `clang-cl` from the same LLVM as the driver's clang. */
282
+ function findClangCl(clangPath: string): string {
283
+ const sibling = siblingTool(clangPath, "clang-cl");
284
+ if (sibling) return sibling;
285
+ const onPath = resolveOnPath("clang-cl");
286
+ if (onPath) return onPath;
287
+ fail(
288
+ `no clang-cl found next to ${clangPath} or on PATH; the Windows media build needs the LLVM bundled ` +
289
+ "with Visual Studio (VC\\Tools\\Llvm\\<arch>\\bin\\clang-cl.exe) so FFmpeg can use the MSVC ABI.",
290
+ );
291
+ }
292
+
293
+ /** Installation path reported by `vswhere`, when it is available. */
294
+ function vswhereInstallation(): string | undefined {
295
+ const programFilesX86 = process.env["ProgramFiles(x86)"] ?? "C:\\Program Files (x86)";
296
+ const vswhere = join(programFilesX86, "Microsoft Visual Studio", "Installer", "vswhere.exe");
297
+ if (!existsSync(vswhere)) return undefined;
298
+ const result = spawnSync(
299
+ vswhere,
300
+ [
301
+ "-latest", "-products", "*",
302
+ "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
303
+ "-property", "installationPath",
304
+ ],
305
+ { encoding: "utf8" },
306
+ );
307
+ const root = result.status === 0 ? result.stdout.split(/\r?\n/)[0]?.trim() : undefined;
308
+ return root && existsSync(root) ? root : undefined;
309
+ }
310
+
311
+ /** Directory holding `cl.exe` (and `lib.exe`), which FFmpeg's msvc toolchain probes. */
312
+ function findMsvcBin(clangPath: string): string {
313
+ const roots = [process.env.ProgramFiles, process.env["ProgramFiles(x86)"], process.env.ProgramW6432]
314
+ .filter((root): root is string => Boolean(root));
315
+ /* A clang from Visual Studio's own LLVM names the installation it belongs to;
316
+ * vswhere covers a clang from a separate LLVM when VS is installed elsewhere. */
317
+ const fromClang = /^(.*[\\/]Microsoft Visual Studio[\\/]\d{4}[\\/][^\\/]+)[\\/]VC[\\/]Tools[\\/]Llvm[\\/]/i.exec(
318
+ clangPath,
319
+ )?.[1];
320
+ const fromVswhere = vswhereInstallation();
321
+ const msvcDirs: string[] = [];
322
+ for (const extra of [fromClang, fromVswhere]) {
323
+ if (extra) msvcDirs.push(join(extra, "VC", "Tools", "MSVC"));
324
+ }
325
+ for (const root of roots) {
326
+ for (const year of ["2022", "2019"]) {
327
+ for (const edition of ["BuildTools", "Community", "Professional", "Enterprise"]) {
328
+ msvcDirs.push(join(root, "Microsoft Visual Studio", year, edition, "VC", "Tools", "MSVC"));
329
+ }
330
+ }
331
+ }
332
+ const host = process.arch === "arm64" ? "Hostarm64" : "Hostx64";
333
+ const target = process.arch === "arm64" ? "arm64" : "x64";
334
+ for (const msvc of msvcDirs) {
335
+ if (!existsSync(msvc)) continue;
336
+ const versions = readdirSync(msvc).sort((a, b) => b.localeCompare(a, undefined, { numeric: true }));
337
+ for (const version of versions) {
338
+ const bin = join(msvc, version, "bin", host, target);
339
+ if (existsSync(join(bin, "cl.exe"))) return bin;
340
+ }
341
+ }
165
342
  fail(
166
- "the media extension is not available on Windows yet: FFmpeg needs a POSIX " +
167
- "configure/make build (see doc/gui/known-issues.md)",
343
+ "the Windows media build needs the MSVC C++ toolchain (FFmpeg's configure probes cl.exe/lib.exe); " +
344
+ "install the 'Desktop development with C++' workload in Visual Studio or the Build Tools.",
168
345
  );
169
346
  }
170
347
 
348
+ interface WindowsBuildTools {
349
+ readonly shell: string;
350
+ readonly make: string;
351
+ readonly env: NodeJS.ProcessEnv;
352
+ }
353
+
354
+ /** Environment for configure/make: the resolved clang-cl and MSVC tools first. */
355
+ function windowsBuildEnv(shell: string, clangCl: string, msvcBin: string): NodeJS.ProcessEnv {
356
+ const env: NodeJS.ProcessEnv = { ...process.env };
357
+ const pathKey = Object.keys(env).find((key) => key.toUpperCase() === "PATH") ?? "Path";
358
+ const usrBin = resolve(dirname(shell), "..", "usr", "bin");
359
+ const parts = [dirname(clangCl), msvcBin, existsSync(usrBin) ? usrBin : "", env[pathKey] ?? ""];
360
+ env[pathKey] = parts.filter((part) => part.length > 0).join(";");
361
+ return env;
362
+ }
363
+
364
+ /** Rewrite the POSIX `SRC_PATH` configure wrote so a native make can parse it. */
365
+ function patchNativeMakePaths(): void {
366
+ const posixSource = toPosixPath(ffmpegSrc);
367
+ const posixInstall = toPosixPath(ffmpegInstall);
368
+ for (const file of [join(ffmpegBuild, "Makefile"), join(ffmpegBuild, "ffbuild", "config.mak")]) {
369
+ if (!existsSync(file)) continue;
370
+ const patched = readFileSync(file, "utf8")
371
+ .split(posixSource).join(toWindowsPath(ffmpegSrc))
372
+ .split(posixInstall).join(toWindowsPath(ffmpegInstall));
373
+ writeFileSync(file, patched);
374
+ }
375
+ }
376
+
377
+ /** Copy every public `.h` under `source` into `destination`, recursively. */
378
+ function copyHeaders(source: string, destination: string): void {
379
+ mkdirSync(destination, { recursive: true });
380
+ for (const entry of readdirSync(source, { withFileTypes: true })) {
381
+ const from = join(source, entry.name);
382
+ const to = join(destination, entry.name);
383
+ if (entry.isDirectory()) {
384
+ copyHeaders(from, to);
385
+ } else if (entry.isFile() && entry.name.endsWith(".h")) {
386
+ copyFileSync(from, to);
387
+ }
388
+ }
389
+ }
390
+
391
+ /** Copy FFmpeg headers and static libraries into the `dist` prefix. */
392
+ function installFfmpegWindows(): void {
393
+ const includeDir = join(ffmpegInstall, "include");
394
+ for (const name of FFMPEG_LIBRARY_NAMES) {
395
+ const library = name.replace(/\.a$/, "");
396
+ copyHeaders(join(ffmpegSrc, library), join(includeDir, library));
397
+ }
398
+ /* Generated headers live in the build tree, not in the sources. */
399
+ for (const generated of ["avconfig.h", "ffversion.h"]) {
400
+ const from = join(ffmpegBuild, "libavutil", generated);
401
+ if (existsSync(from)) copyFileSync(from, join(includeDir, "libavutil", generated));
402
+ }
403
+ const libDir = join(ffmpegInstall, "lib");
404
+ mkdirSync(libDir, { recursive: true });
405
+ for (const name of FFMPEG_LIBRARY_NAMES) {
406
+ copyFileSync(join(ffmpegBuild, name.replace(/\.a$/, ""), name), join(libDir, name));
407
+ }
408
+ }
409
+
410
+ function buildFfmpegWindows(shell: string, clangCl: string, msvcBin: string): void {
411
+ const make = findWindowsMake();
412
+ const tools: WindowsBuildTools = {
413
+ shell,
414
+ make,
415
+ env: windowsBuildEnv(shell, clangCl, msvcBin),
416
+ };
417
+ console.log(`xbintsc: configuring FFmpeg ${FFMPEG_VERSION} for the MSVC ABI with clang-cl`);
418
+ mkdirSync(ffmpegBuild, { recursive: true });
419
+ run(tools.shell, [
420
+ toPosixPath(join(ffmpegSrc, "configure")),
421
+ "--toolchain=msvc",
422
+ "--cc=clang-cl", "--cxx=clang-cl", "--ld=clang-cl", "--ar=lib.exe",
423
+ ...ffmpegConfigureArgs(),
424
+ ], { cwd: ffmpegBuild, env: tools.env });
425
+
426
+ /* Native make cannot pass FFmpeg's `/showIncludes` awk pipeline (the MSVC
427
+ * backslash escapes are consumed by the Windows command line); the `.d` files
428
+ * only affect incremental rebuilds, so generation is skipped. The source path
429
+ * configure wrote is POSIX-shaped and is rewritten for native make. */
430
+ patchNativeMakePaths();
431
+ const depOverrides = " CCDEP=true CXXDEP=true ASDEP=true HOSTCCDEP=true";
432
+ console.log(`xbintsc: building minimal static FFmpeg ${FFMPEG_VERSION} with clang-cl`);
433
+ run(tools.shell, ["-lc", `${shellQuote(tools.make)} -j ${availableParallelism()}${depOverrides}`], {
434
+ cwd: ffmpegBuild,
435
+ env: tools.env,
436
+ });
437
+ installFfmpegWindows();
438
+ }
439
+
440
+ /* -- 1. FFmpeg source ------------------------------------------------------ */
441
+
442
+ ensureFfmpegSource();
443
+
171
444
  /* One toolchain for the player and FFmpeg: the same clang the driver uses, its
172
445
  * sibling clang++, and the matching llvm-ar. Mixing another C++ runtime or
173
446
  * object format would break the final link. */
174
447
  const clang = driverClang();
175
448
  const clangxx = findClangxx(clang);
176
449
  const archiver = findArchiver(clang);
177
-
178
- /* -- 1. FFmpeg source ------------------------------------------------------ */
179
-
180
- ensureFfmpegSource();
450
+ const windowsTools = isWindows
451
+ ? {
452
+ shell: findPosixShell(),
453
+ clangCl: findClangCl(clang),
454
+ msvcBin: findMsvcBin(clang),
455
+ }
456
+ : undefined;
181
457
 
182
458
  /* -- 2. minimal static FFmpeg --------------------------------------------- */
183
459
 
184
- let ffmpegLibraries = ffmpegStaticLibraries();
185
- if (!ffmpegLibraries) {
186
- console.log(`xbintsc: building minimal static FFmpeg ${FFMPEG_VERSION} with ${clang}`);
187
- mkdirSync(ffmpegBuild, { recursive: true });
188
- run(join(ffmpegSrc, "configure"), [
189
- `--prefix=${ffmpegInstall}`,
190
- "--enable-static", "--disable-shared",
191
- "--disable-programs", "--disable-doc",
192
- "--disable-htmlpages", "--disable-manpages", "--disable-podpages", "--disable-txtpages",
193
- "--disable-avdevice", "--disable-avfilter", "--disable-postproc",
194
- "--disable-everything",
195
- "--enable-avformat", "--enable-avcodec", "--enable-avutil", "--enable-swscale", "--enable-swresample",
196
- "--disable-network", "--disable-autodetect", "--disable-x86asm", "--disable-debug", "--enable-pic",
197
- `--cc=${clang}`,
198
- `--cxx=${clangxx}`,
199
- ...FFMPEG_COMPONENTS,
200
- ], { cwd: ffmpegBuild });
201
- run("make", ["-j", String(availableParallelism())], { cwd: ffmpegBuild });
202
- run("make", ["install"], { cwd: ffmpegBuild });
203
- ffmpegLibraries = ffmpegStaticLibraries();
204
- if (!ffmpegLibraries) fail("FFmpeg build did not produce the expected static libraries");
460
+ if (!ffmpegInstalled()) {
461
+ if (windowsTools) {
462
+ buildFfmpegWindows(windowsTools.shell, windowsTools.clangCl, windowsTools.msvcBin);
463
+ } else {
464
+ console.log(`xbintsc: building minimal static FFmpeg ${FFMPEG_VERSION} with ${clang}`);
465
+ mkdirSync(ffmpegBuild, { recursive: true });
466
+ run(join(ffmpegSrc, "configure"), ffmpegConfigureArgs(), { cwd: ffmpegBuild });
467
+ run("make", ["-j", String(availableParallelism())], { cwd: ffmpegBuild });
468
+ run("make", ["install"], { cwd: ffmpegBuild });
469
+ }
470
+ if (!ffmpegInstalled()) fail("FFmpeg build did not produce the expected static libraries");
205
471
  } else {
206
472
  console.log(`xbintsc: reusing existing ${ffmpegInstall}/lib`);
207
473
  }
@@ -212,30 +478,29 @@ if (!ffmpegLibraries) {
212
478
  * because the *source* root contains a file literally named `version` that
213
479
  * would shadow the C++ standard header for any `.cpp` that includes it. */
214
480
  mkdirSync(objDir, { recursive: true });
215
- const object = join(objDir, "media.o");
216
481
  const playerSource = join(sourceDir, "media.cpp");
217
482
  console.log("xbintsc: compiling media.cpp");
218
- run(clangxx, [
219
- "-std=c++17", "-O2", "-Wall", "-Wextra", "-fPIC",
220
- "-I", runtimeDir,
221
- "-I", join(ffmpegInstall, "include"),
222
- "-c", playerSource,
223
- "-o", object,
224
- ]);
483
+ const cxxFlags = ["-std=c++17", "-O2", "-Wall", "-Wextra", "-I", runtimeDir, "-I", join(ffmpegInstall, "include")];
484
+ /* The engine and the player are C++ with the static CRT (`libcpmt`), matching
485
+ * FFmpeg's clang-cl objects and the xbintsc runtime; see `scripts/build-gui.ts`. */
486
+ if (isWindows) cxxFlags.push("-Xclang", "--dependent-lib=libcpmt");
487
+ else cxxFlags.push("-fPIC");
488
+ run(clangxx, [...cxxFlags, "-c", playerSource, "-o", object]);
225
489
 
226
- /* -- 4. merge into media.a ------------------------------------------------- */
490
+ /* -- 4. merge into the archive -------------------------------------------- */
227
491
 
228
492
  mkdirSync(outDir, { recursive: true });
229
493
  rmSync(output, { force: true });
230
494
  if (process.platform === "darwin") {
231
- run("libtool", ["-static", "-o", output, object, ...ffmpegLibraries], { quietStderr: true });
495
+ run("libtool", ["-static", "-o", output, object, ...ffmpegStaticLibraries()!], { quietStderr: true });
232
496
  } else {
233
- /* `ar -M` (GNU/LLVM) merges archives through an MRI script. */
497
+ /* `ar -M` (GNU/LLVM) merges archives through an MRI script. Windows paths are
498
+ * normalised to `/` so the MRI parser does not read `\` as an escape. */
234
499
  const mri = (path: string): string => path.replace(/\\/g, "/");
235
500
  const script = [
236
501
  `create ${mri(output)}`,
237
502
  `addmod ${mri(object)}`,
238
- ...ffmpegLibraries.map((library) => `addlib ${mri(library)}`),
503
+ ...ffmpegStaticLibraries()!.map((library) => `addlib ${mri(library)}`),
239
504
  "save",
240
505
  "end",
241
506
  ].join("\n");
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env pwsh
2
+ <#
3
+ .SYNOPSIS
4
+ Select the Visual Studio MSVC + LLVM toolchain for a Windows build.
5
+
6
+ .DESCRIPTION
7
+ Finds the Visual Studio installation that owns the C++ build tools, imports
8
+ its `vcvarsall` environment (INCLUDE, LIB, PATH, ...), verifies the LLVM
9
+ bundled with that same installation (`clang`, `clang++`, `clang-cl`,
10
+ `llvm-ar`, `llvm-rc`) and exposes it as `xbintsc_CLANG`.
11
+
12
+ This is the toolchain a local build resolves and the one the prebuilt
13
+ `gui.lib` / `media.lib` archives are compiled with. GitHub Actions calls this
14
+ script from `.github/actions/vs-toolchain` instead of installing a separate
15
+ LLVM, so CI and local builds share one compiler chain.
16
+
17
+ Run it directly from a PowerShell prompt to use the same environment
18
+ interactively:
19
+
20
+ pwsh -File scripts/setup-vs-toolchain.ps1
21
+
22
+ In GitHub Actions it also appends the environment to `GITHUB_ENV` and the
23
+ LLVM bin directory to `GITHUB_PATH`, so later steps see it.
24
+
25
+ .PARAMETER InstallMake
26
+ Install GNU make through Chocolatey (the FFmpeg media build needs it). Only
27
+ used by CI; a local developer already has a native GNU make on PATH.
28
+ #>
29
+ [CmdletBinding()]
30
+ param(
31
+ [switch]$InstallMake
32
+ )
33
+
34
+ $ErrorActionPreference = "Stop"
35
+
36
+ function Write-GitHubEnv([string]$name, [string]$value) {
37
+ if ($env:GITHUB_ENV) {
38
+ "$name=$value" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
39
+ }
40
+ }
41
+
42
+ function Write-GitHubPath([string]$path) {
43
+ if ($env:GITHUB_PATH) {
44
+ $path | Out-File -FilePath $env:GITHUB_PATH -Append -Encoding utf8
45
+ }
46
+ }
47
+
48
+ # 1. Find Visual Studio with the C++ tools for this machine's architecture.
49
+ $arch = if ($env:RUNNER_ARCH -eq "ARM64" -or $env:PROCESSOR_ARCHITECTURE -eq "ARM64") { "arm64" } else { "x64" }
50
+ $llvmArch = if ($arch -eq "arm64") { "ARM64" } else { "x64" }
51
+ $component = if ($arch -eq "arm64") {
52
+ "Microsoft.VisualStudio.Component.VC.Tools.arm64"
53
+ } else {
54
+ "Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
55
+ }
56
+
57
+ $programFilesX86 = [Environment]::GetFolderPath("ProgramFilesX86")
58
+ $vswhere = Join-Path $programFilesX86 "Microsoft Visual Studio\Installer\vswhere.exe"
59
+ if (-not (Test-Path $vswhere)) {
60
+ $vswhere = Join-Path $env:ProgramFiles "Microsoft Visual Studio\Installer\vswhere.exe"
61
+ }
62
+ if (-not (Test-Path $vswhere)) {
63
+ throw "vswhere.exe not found; install Visual Studio with the C++ build tools."
64
+ }
65
+
66
+ $vsPath = (& $vswhere -latest -products * -requires $component -property installationPath |
67
+ Select-Object -First 1)
68
+ if ($vsPath) { $vsPath = $vsPath.Trim() }
69
+ if (-not $vsPath -or -not (Test-Path $vsPath)) {
70
+ throw "Visual Studio C++ build tools ($component) were not found."
71
+ }
72
+
73
+ # 2. Import the vcvarsall environment into this process and, in CI, the rest of
74
+ # the job. vcvarsall is locale-independent for KEY=VALUE output.
75
+ $vcvars = Join-Path $vsPath "VC\Auxiliary\Build\vcvarsall.bat"
76
+ if (-not (Test-Path $vcvars)) { throw "vcvarsall.bat not found at $vcvars" }
77
+ foreach ($line in (cmd /c "`"$vcvars`" $arch && set")) {
78
+ if ($line -match "^([^=]+)=(.*)$") {
79
+ $name = $matches[1]
80
+ $value = $matches[2]
81
+ Set-Item -Path "Env:$name" -Value $value
82
+ Write-GitHubEnv $name $value
83
+ }
84
+ }
85
+
86
+ # 3. Use the LLVM bundled with that Visual Studio installation. This is the
87
+ # same compiler the driver and the build scripts resolve locally; the
88
+ # fallback handles installations that put LLVM at the VC\Tools\Llvm root.
89
+ $llvmBin = Join-Path $vsPath "VC\Tools\Llvm\$llvmArch\bin"
90
+ if (-not (Test-Path (Join-Path $llvmBin "clang.exe"))) {
91
+ $llvmBin = Join-Path $vsPath "VC\Tools\Llvm\bin"
92
+ }
93
+ $clang = Join-Path $llvmBin "clang.exe"
94
+ if (-not (Test-Path $clang)) {
95
+ throw @"
96
+ Visual Studio at $vsPath has no LLVM at $llvmBin.
97
+ Install the "C++ Clang tools for Windows" component (Microsoft.VisualStudio.Component.VC.Llvm.Clang).
98
+ "@
99
+ }
100
+
101
+ $versionOutput = & $clang --version
102
+ if ($LASTEXITCODE -ne 0) { throw "$clang --version failed." }
103
+ $versionLine = ($versionOutput | Select-Object -First 1).Trim()
104
+ if ($versionLine -notmatch "clang version (\d+)\.") {
105
+ throw "$clang did not report a clang version: $versionLine"
106
+ }
107
+ $major = [int]$matches[1]
108
+ if ($major -lt 16) {
109
+ throw "Visual Studio's clang is $versionLine; xbintsc requires clang 16 or newer."
110
+ }
111
+ $targetLine = $versionOutput | Where-Object { $_ -match "^Target:" } | Select-Object -First 1
112
+ if (-not $targetLine -or $targetLine -notmatch "windows-msvc") {
113
+ throw "Visual Studio's clang targets '$targetLine', not the MSVC ABI."
114
+ }
115
+ $expectedTarget = if ($arch -eq "arm64") { "aarch64-pc-windows-msvc" } else { "x86_64-pc-windows-msvc" }
116
+ if ($targetLine -notmatch [regex]::Escape($expectedTarget)) {
117
+ throw "Visual Studio's clang targets '$targetLine'; this runner is $arch (expected $expectedTarget)."
118
+ }
119
+
120
+ # 4. Put it in front of PATH and tell the driver exactly which clang to use.
121
+ $env:xbintsc_CLANG = $clang
122
+ $env:Path = "$llvmBin;$env:Path"
123
+ Write-GitHubEnv "xbintsc_CLANG" $clang
124
+ Write-GitHubPath $llvmBin
125
+
126
+ # 5. Optional: GNU make for FFmpeg's configure (media archive only).
127
+ if ($InstallMake) {
128
+ if ($env:GITHUB_ACTIONS) {
129
+ choco install make --no-progress -y
130
+ if ($LASTEXITCODE -ne 0) { throw "choco install make failed" }
131
+ $makePath = "C:\ProgramData\chocolatey\bin\make.exe"
132
+ if (-not (Test-Path $makePath)) { throw "GNU make was not installed at $makePath" }
133
+ } else {
134
+ $makeCommand = Get-Command make -ErrorAction SilentlyContinue
135
+ if (-not $makeCommand) {
136
+ throw "GNU make not found; install it (choco install make) or run without -InstallMake."
137
+ }
138
+ $makePath = $makeCommand.Source
139
+ }
140
+ $env:xbintsc_MAKE = $makePath
141
+ Write-GitHubEnv "xbintsc_MAKE" $makePath
142
+ $makeVersion = (& $makePath --version | Select-Object -First 1).Trim()
143
+ if ($makeVersion -notmatch "GNU Make") {
144
+ throw "$makePath is not GNU make: $makeVersion"
145
+ }
146
+ Write-Host "make : $makePath ($makeVersion)"
147
+ }
148
+
149
+ Write-Host "Visual Studio: $vsPath"
150
+ Write-Host "MSVC arch : $arch"
151
+ Write-Host "clang : $clang ($versionLine)"
152
+ Write-Host "target : $targetLine"
@@ -510,7 +510,19 @@ export const referenceMethods: ReferenceMethods = {
510
510
  this.symbolOfIdentifier.set(identifier, symbol);
511
511
  // Functions, classes and type-only names are resolved to their
512
512
  // declaration sites by codegen; they are never captured as values.
513
- if (symbol.fn !== this.current && isCapturable(symbol.kind)) this.markCaptured(symbol);
513
+ // A *function declaration* reached from a nested function is the
514
+ // exception: the closure value belongs to the declaring function's
515
+ // frame (it may itself capture parameters), so thread it through the
516
+ // environment instead of rebuilding it at the call site with the
517
+ // caller's slots. Module-scope functions keep their global handling.
518
+ if (symbol.kind === SymbolKind.Function) {
519
+ /* Module-scope functions are reached through their globals; a
520
+ * function declared inside a function travels with the closure
521
+ * environment because its own captures belong to that frame. */
522
+ if (symbol.fn !== this.current && !symbol.fn.isModule) this.markCaptured(symbol);
523
+ } else if (symbol.fn !== this.current && isCapturable(symbol.kind)) {
524
+ this.markCaptured(symbol);
525
+ }
514
526
  return;
515
527
  }
516
528
  current = current.parent;