A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(build): the generated native bindings include the headers where they are
yhhdc45d18d69eb
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex c0a2f5767..0c89cd7a0 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -110,6 +110,12 @@ jobs:- name: Check render-command boundary (DrawCommands built only by BatchBuilder)run: node tools/check-draw-command-boundary.mjs+ # The device build's codegen, without the device build: it needs no compiler+ # and takes a second, but nothing outside a release ran it — so a header that+ # moved cost a full Dawn build to find out about, twice.+ - name: Check native binding codegen (headers + the includes it generates)+ run: node tools/check-native-bindings.mjs+# Filtered so the SDK is checked by ITS OWN pinned TypeScript (the workspace# carries two majors — desktop is on 6.x); a bare root `pnpm exec tsc`# resolves an arbitrary compiler. Mirrors the repo's `verify` gate exactly.diff --git a/tools/check-native-bindings.mjs b/tools/check-native-bindings.mjsnew file mode 100644index 000000000..c3fc22544--- /dev/null+++ b/tools/check-native-bindings.mjs@@ -0,0 +1,75 @@+#!/usr/bin/env node+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+// =============================================================================+// Native binding codegen pre-flight.+//+// The device build generates its QuickJS entry-point wrappers from a list of+// headers, then compiles the result. Both halves can be wrong about where a+// header lives — the list, and the #include the generator writes into the file+// it emits — and both were, after a reorganisation moved four headers into+// bindings/modules/<name>/. Neither is reachable from any build but the release+// one, so each mistake cost a full Dawn build to discover, one at a time.+//+// The codegen itself needs no compiler and takes a second, so it runs here: the+// headers must exist, the generator must succeed, and every include it writes+// must resolve to a real file.+//+// Run: node tools/check-native-bindings.mjs (exit 1 on any of the three)+// =============================================================================++import { execFileSync } from 'node:child_process';+import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';+import path from 'node:path';+import { fileURLToPath } from 'node:url';++const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');+const SRC = path.join(ROOT, 'src');+const BINDINGS = path.join(SRC, 'esengine', 'bindings');++const { NATIVE_BINDING_HEADERS } = await import('../build-tools/tasks/native.js');++let failed = false;+const fail = (msg) => { console.error(msg); failed = true; };++// 1. Every listed header is where the list says it is.+const abs = NATIVE_BINDING_HEADERS.map((h) => path.join(BINDINGS, h));+for (const [i, p] of abs.entries()) {+ if (!existsSync(p)) fail(`missing header: src/esengine/bindings/${NATIVE_BINDING_HEADERS[i]}`);+}+if (failed) {+ console.error('\nThe list lives in build-tools/tasks/native.js, and its entries are paths under src/esengine/bindings.');+ process.exit(1);+}++// 2. The generator runs.+const out = mkdtempSync(path.join(tmpdir(), 'estella-nfb-'));+const generated = path.join(out, 'NativeFunctionBindings.generated.cpp');+const python = process.env.PYTHON || 'python';+try {+ execFileSync(python, [+ path.join(ROOT, 'tools', 'eht.py'),+ '--native-functions', ...abs,+ '--native-functions-output', generated,+ '--native-shim', 'esn_shim.hpp',+ ], { cwd: ROOT, stdio: 'pipe' });+} catch (e) {+ console.error('EHT failed to generate the native entry-point bindings:');+ console.error(String(e.stderr || e.stdout || e.message));+ rmSync(out, { recursive: true, force: true });+ process.exit(1);+}++// 3. Every engine include it wrote resolves. (Angle-bracket system headers and+// the shim are the toolchain's business, not ours.)+const text = readFileSync(generated, 'utf8');+const includes = [...text.matchAll(/^#include\s+"([^"]+)"/gm)].map((m) => m[1])+ .filter((inc) => inc.startsWith('esengine/'));+for (const inc of includes) {+ if (!existsSync(path.join(SRC, inc))) fail(`generated #include does not resolve: ${inc}`);+}+rmSync(out, { recursive: true, force: true });++if (failed) process.exit(1);+console.log(`native bindings OK: ${abs.length} headers, ${includes.length} generated include(s) resolve.`);diff --git a/tools/eht/__main__.py b/tools/eht/__main__.pyindex ed53b95a1..f6d076323 100644--- a/tools/eht/__main__.py+++ b/tools/eht/__main__.py@@ -21,8 +21,15 @@ def _emit_native_functions(args) -> int:if not path.is_file():print(f"[FAIL] --native-functions: no such header: {path}")return 1- # The generated TU includes the header the way the binding TUs do.- include = f'esengine/bindings/{path.name}'+ # The generated TU includes the header the way the binding TUs do: by its+ # path under src/. Deriving it (rather than pasting a basename onto a+ # fixed directory) is what lets a header move without the generated file+ # pointing at where it used to be.+ parts = path.resolve().parts+ if 'src' not in parts:+ print(f"[FAIL] --native-functions: {path} is not under src/, so its include cannot be derived")+ return 1+ include = '/'.join(parts[len(parts) - 1 - parts[::-1].index('src') + 1:])headers.append((include, path.read_text(encoding='utf-8')))gen = NativeFunctionsGenerator(headers, shim_header=args.native_shim)