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.

build(eht): refuse a field type the boundary cannot carry

esengine0e19d1387caf
diff --git a/tools/eht/__main__.py b/tools/eht/__main__.py
index eaccc141f..736013750 100644
--- a/tools/eht/__main__.py
+++ b/tools/eht/__main__.py
@@ -5,6 +5,7 @@ import argparse
from pathlib import Path
from .parser import CppParser
+from .type_system import TypeSystem
from .abi import compute_abi_hash
from .entity_layout import parse_entity_layout, generate_ts as generate_entity_ts
from .constants import parse_constants, canonical as const_canonical, generate_ts as generate_consts_ts
@@ -148,6 +149,19 @@ def main() -> int:
print(f"[FAIL] {len(cpp_parser.errors)} annotation error(s); aborting before codegen.")
return 1
+ # A type no generator recognises is emitted VERBATIM by each of them, so an
+ # ES_PROPERTY the boundary cannot marshal used to compile and then fail when a
+ # scene added the component ("unbound types"), with a TS type of `number` over
+ # it. Refuse it here, where the field still has a name.
+ uncarried = TypeSystem(cpp_parser.enums).uncarried_properties(cpp_parser.components)
+ if uncarried:
+ for comp, prop, cpp_type in uncarried:
+ print(f"[FAIL] {comp}.{prop}: ES_PROPERTY type '{cpp_type}' does not cross the"
+ " boundary. Either drop the annotation (MeshRenderer's geometry payload is"
+ " the precedent: un-annotated, set through its own binding), or teach"
+ " tools/eht/type_system.py to carry the type.")
+ return 1
+
# Emit components/enums in a stable alphabetical order so the generated files
# are byte-reproducible across machines — Path.rglob order is filesystem-
# dependent, which otherwise churns every committed *.generated.* file when a
diff --git a/tools/eht/test_validation.py b/tools/eht/test_validation.py
index 9e4da95f7..3b1cb128c 100644
--- a/tools/eht/test_validation.py
+++ b/tools/eht/test_validation.py
@@ -231,6 +231,29 @@ component_meta_emits('renderable reaches COMPONENT_META',
component_meta_emits('transient reaches COMPONENT_META',
'transient', FLAG, 'transient: true,')
+def carries(name: str, body: str, *, uncarried: int) -> None:
+ """A field type the boundary cannot marshal is refused BEFORE codegen: every
+ generator falls through to emitting an unknown type verbatim, which compiles
+ and then fails when a scene adds the component."""
+ global _failures
+ from eht.type_system import TypeSystem # noqa: PLC0415
+ p = _parse(body)
+ got = TypeSystem(p.enums).uncarried_properties(p.components)
+ if len(got) != uncarried:
+ _failures += 1
+ print(f"FAIL {name}")
+ print(f" uncarried: got {len(got)} want {uncarried} -> {got}")
+ else:
+ print(f"ok {name}")
+
+
+carries('a primitive crosses', 'ES_PROPERTY()\n float x = 0.0f;', uncarried=0)
+carries('glm::vec2 crosses', 'ES_PROPERTY()\n glm::vec2 size;', uncarried=0)
+carries('a handle crosses', 'ES_PROPERTY(asset=texture)\n resource::TextureHandle tex;', uncarried=0)
+carries('std::vector<Entity> crosses', 'ES_PROPERTY()\n std::vector<Entity> entities;', uncarried=0)
+carries('a point list does NOT', 'ES_PROPERTY()\n std::vector<glm::vec2> path;', uncarried=1)
+carries('an unknown struct does NOT', 'ES_PROPERTY()\n SomeThing thing;', uncarried=1)
+
if _failures:
print(f"\n{_failures} case(s) failed")
raise SystemExit(1)
diff --git a/tools/eht/type_system.py b/tools/eht/type_system.py
index 3e4f2fc89..c349ffd34 100644
--- a/tools/eht/type_system.py
+++ b/tools/eht/type_system.py
@@ -1,7 +1,7 @@
"""Type classification and C++/TypeScript mapping."""
import re
-from typing import Dict, List, Optional, Set
+from typing import Dict, List, Optional, Set, Tuple
from .data import Enum
@@ -111,6 +111,25 @@ class TypeSystem:
def is_custom_struct(self, cpp_type: str) -> bool:
return self.clean_type(cpp_type) in self.CUSTOM_STRUCTS
+ def carries(self, cpp_type: str) -> bool:
+ """Whether the boundary can marshal an ES_PROPERTY of this type.
+
+ Every generator below asks a question of the form "is it one of these?"
+ and falls through to emitting the field verbatim, so a type none of them
+ knows reaches embind as `.field(&C::x)` on something embind was never
+ told about. That compiles; it fails when a scene ADDS the component.
+ """
+ t = self.clean_type(cpp_type)
+ return (self.is_skip(t) or self.is_primitive(t) or self.is_glm(t)
+ or t == 'std::string' or self.is_enum(t) or self.is_handle(t)
+ or self.is_entity(t) or t in self.VECTOR_TYPES
+ or self.is_struct_vector(t) or self.is_custom_struct(t))
+
+ def uncarried_properties(self, components) -> List[Tuple[str, str, str]]:
+ """Every (component, field, type) the boundary would silently mangle."""
+ return [(c.name, p.name, self.clean_type(p.cpp_type))
+ for c in components for p in c.properties if not self.carries(p.cpp_type)]
+
def custom_struct_members(self, cpp_type: str):
"""Return the [(member_name, member_cpp_type), ...] list for a custom struct."""
return self.CUSTOM_STRUCTS[self.clean_type(cpp_type)]
diff --git a/tools/gates.mjs b/tools/gates.mjs
index af7e83304..23dc4690f 100644
--- a/tools/gates.mjs
+++ b/tools/gates.mjs
@@ -57,6 +57,9 @@ export const GATES = [
// The generator's output is checked in, so its authority and its artifact can
// disagree with nothing between them to notice.
{ id: 'generated-fresh', run: 'node tools/check-generated-fresh.mjs' },
+ // The generator's own cases had no runner at all — the file said how to run it
+ // and nothing did, which is the shape check-verifier-owners exists to refuse.
+ { id: 'eht-validation', run: 'python3 tools/eht/test_validation.py' },
{ id: 'transform-seam', run: 'node tools/check-transform-seam.mjs' },
// …and the other direction: every C++ writer of a composition input is a
// seam somebody classified, rather than a count that moves with a refactor.