Skip to content

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.

refactor(eht): the engine API is the core's surface, not every module's

yhh54c04c458866
diff --git a/build-tools/tasks/native.js b/build-tools/tasks/native.js
index 24f984fda..927eb8d9f 100644
--- a/build-tools/tasks/native.js
+++ b/build-tools/tasks/native.js
@@ -34,11 +34,18 @@ async function generateNativeBindings(rootDir, genDir, python) {
return out;
}
-// The binding headers whose entry points a native host gets, and the ONE list of
-// them: the QuickJS wrappers and the TS surface the SDK calls
-// (sdk/src/ecs/nativeEngineApi.generated.ts) are both generated from these, so
-// adding a subsystem to a device is adding its header here.
-export const NATIVE_BINDING_HEADERS = [
+// The binding headers whose entry points a native host gets. Two lists, because the
+// boundary has two halves:
+//
+// ENGINE — the core the SDK drives through `engineApi(app)`. Their entry points ARE
+// the engine API, so they generate the committed TS surface as well.
+// MODULE — the optional subsystems, acquired through `app.sideModules` (physics,
+// the video decoder). They are compiled into the host binary rather than
+// fetched as wasm side modules, so the host needs their wrappers; the SDK
+// reaches them by their own module interface, not the engine API.
+//
+// Adding a subsystem to a device is adding its header to the right list.
+export const ENGINE_BINDING_HEADERS = [
'RendererBindings.hpp',
'UIBindings.hpp',
'ResourceManagerBindings.hpp',
@@ -47,33 +54,39 @@ export const NATIVE_BINDING_HEADERS = [
'GeometryBindings.hpp',
'ImmediateDrawBindings.hpp',
'AnimationBindings.hpp',
- // Physics: a C module compiled into the host, not a wasm side module.
+];
+
+export const MODULE_BINDING_HEADERS = [
'PhysicsBindings.hpp',
- // The engine's own MPEG-1 decoder, likewise compiled in.
'VideoBindings.hpp',
];
+export const NATIVE_BINDING_HEADERS = [...ENGINE_BINDING_HEADERS, ...MODULE_BINDING_HEADERS];
+
// Generate the QuickJS wrappers for the engine's binding ENTRY POINTS — the same
// declarations embind registers on the web, so the SDK reaches the engine by the
// same names on both platforms and nothing is bound twice by hand. The bodies are
// the binding TUs themselves, which this build compiles (see ESEngineSources).
async function generateNativeFunctionBindings(rootDir, genDir, python) {
const out = path.join(genDir, 'NativeFunctionBindings.generated.cpp');
- // Every binding TU the native build compiles (see cmake/ESEngineSources.cmake).
- // ResourceManagerBindings is the texture surface the asset pipeline uploads
- // through: the host used to hand-write a second copy of it. Tilemap and
- // post-process declarations sit behind their ES_ENABLE_* gates, which the
- // generator carries into the wrapper, so a build without them still compiles.
- const headers = NATIVE_BINDING_HEADERS.map(
- (h) => path.join(rootDir, 'src', 'esengine', 'bindings', h));
+ const abs = (h) => path.join(rootDir, 'src', 'esengine', 'bindings', h);
+ const eht = path.join(rootDir, 'tools', 'eht.py');
+ // The wrappers: every module the host compiles in. Declarations behind an
+ // ES_ENABLE_* gate carry it into the wrapper, so a build without them still
+ // compiles.
await runCommand(python, [
- path.join(rootDir, 'tools', 'eht.py'),
- '--native-functions', ...headers,
+ eht,
+ '--native-functions', ...NATIVE_BINDING_HEADERS.map(abs),
'--native-functions-output', out,
- // The TS half is committed (the SDK compiles without running EHT), so it is
- // refreshed here rather than left to be updated by hand: after a native
- // build, a surface that moved shows up as a diff instead of as a call the
- // device silently does not answer.
+ '--native-shim', 'esn_shim.hpp',
+ ], { cwd: rootDir });
+ // The TS engine surface: the CORE headers only. It is committed (the SDK compiles
+ // without running EHT), so it is refreshed here rather than updated by hand —
+ // after a native build, a surface that moved shows up as a diff instead of as a
+ // call the device silently does not answer.
+ await runCommand(python, [
+ eht,
+ '--native-functions', ...ENGINE_BINDING_HEADERS.map(abs),
'--native-functions-ts', path.join(rootDir, 'sdk', 'src', 'ecs', 'nativeEngineApi.generated.ts'),
'--native-shim', 'esn_shim.hpp',
], { cwd: rootDir });
diff --git a/tools/eht/__main__.py b/tools/eht/__main__.py
index c73463a82..5f1ca2ccd 100644
--- a/tools/eht/__main__.py
+++ b/tools/eht/__main__.py
@@ -26,11 +26,12 @@ def _emit_native_functions(args) -> int:
headers.append((include, path.read_text(encoding='utf-8')))
gen = NativeFunctionsGenerator(headers, shim_header=args.native_shim)
- content = gen.generate()
- args.native_functions_output.parent.mkdir(parents=True, exist_ok=True)
- print(f"Generating: {args.native_functions_output}")
- args.native_functions_output.write_text(content, encoding='utf-8')
- print(f" {len(gen.emitted)} entry point(s) bound")
+ if args.native_functions_output is not None:
+ content = gen.generate()
+ args.native_functions_output.parent.mkdir(parents=True, exist_ok=True)
+ print(f"Generating: {args.native_functions_output}")
+ args.native_functions_output.write_text(content, encoding='utf-8')
+ print(f" {len(gen.emitted)} entry point(s) bound")
# The TS half: the same entry points as the object the SDK's plugins call, so
# a plugin reaches whichever core is present without knowing which. Committed
# (the SDK builds from source without running EHT), unlike the C++ wrappers.
@@ -100,8 +101,9 @@ def main() -> int:
# Function wrappers are parsed from declarations, not component reflection —
# emit them before (and independently of) the component pass.
if args.native_functions:
- if args.native_functions_output is None:
- print("[FAIL] --native-functions requires --native-functions-output.")
+ if args.native_functions_output is None and args.native_functions_ts is None:
+ print("[FAIL] --native-functions needs --native-functions-output and/or "
+ "--native-functions-ts.")
return 1
code = _emit_native_functions(args)
if code != 0 or args.native_output is None: