Skip to content

Commit 1ed10bb

Browse files
committed
Add classes_sample option to compile a subset of Godot classes
1 parent dc5864b commit 1ed10bb

File tree

4 files changed

+99
-4
lines changed

4 files changed

+99
-4
lines changed

meson_options.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
option('cpython_distrib_version', type: 'string', value: '3.10.8', description: 'Version of CPython to ship')
22
option('godot_headers', type: 'string', value: 'godot_headers', description: 'Path to Godot extension headers directory')
33
option('real_is_double', type: 'boolean', value: false, description: 'Built for Godot with 64bits floating point numbers (i.e. double) in builtins instead of 32bits (i.e. float)')
4+
option('classes_sample', type: 'boolean', value: false, description: 'Only bind a subset of Godot classes (useful for tests&debug for faster build time)')

scripts/extension_api_parser/api.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def order_classes(classes: List[ClassTypeSpec]) -> List[ClassTypeSpec]:
293293

294294

295295
def parse_extension_api_json(
296-
path: Path, build_config: BuildConfig, skip_classes: bool = False
296+
path: Path, build_config: BuildConfig, filter_classes: Union[bool, Set[str]]
297297
) -> ExtensionApi:
298298
api_json = json.loads(path.read_text(encoding="utf8"))
299299
assert isinstance(api_json, dict)
@@ -327,9 +327,14 @@ def _register_enums(enums, parent_id=None):
327327
_register_enums(builtin_type.enums, parent_id=builtin_type.original_name)
328328

329329
# Parsing classes takes ~75% of the time while not being needed to render builtins stuff
330-
if skip_classes:
330+
if filter_classes is True:
331331
# Only keep Object root class that is always needed
332-
api_json["classes"] = [next(k for k in api_json["classes"] if k["name"] == "Object")]
332+
filter_classes = {"Object"}
333+
if filter_classes:
334+
api_json["classes"] = [
335+
k for k in api_json["classes"]
336+
if k["name"] in filter_classes
337+
]
333338

334339
classes = order_classes(
335340
[parse_class(x, object_size=api_json["object_size"]) for x in api_json["classes"]]

scripts/generate_tmpl.py

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,80 @@
2626
}
2727

2828

29+
# Subset of tlasses to use when generating the project for test&debug purpose,
30+
# this makes compilation much faster !
31+
GODOT_CLASSES_SAMPLE = {
32+
"ArrayMesh",
33+
"CallbackTweener",
34+
"Camera2D",
35+
"Camera3D",
36+
"CameraAttributes",
37+
"CanvasItem",
38+
"ClassDB",
39+
"ConcavePolygonShape3D",
40+
"Control",
41+
"ConvexPolygonShape3D",
42+
"Engine",
43+
"Environment",
44+
"Font",
45+
"Image",
46+
"InputEvent",
47+
"IntervalTweener",
48+
"MainLoop",
49+
"Material",
50+
"Mesh",
51+
"MethodTweener",
52+
"MultiMesh",
53+
"MultiplayerAPI",
54+
"MultiplayerPeer",
55+
"Node",
56+
"Node2D",
57+
"Node3D",
58+
"Node3DGizmo",
59+
"OS",
60+
"Object",
61+
"PackedScene",
62+
"PacketPeer",
63+
"PhysicsDirectSpaceState2D",
64+
"PhysicsDirectSpaceState3D",
65+
"PhysicsPointQueryParameters2D",
66+
"PhysicsPointQueryParameters3D",
67+
"PhysicsRayQueryParameters2D",
68+
"PhysicsRayQueryParameters3D",
69+
"PhysicsShapeQueryParameters2D",
70+
"PhysicsShapeQueryParameters3D",
71+
"ProjectSettings",
72+
"PropertyTweener",
73+
"RefCounted",
74+
"Resource",
75+
"ResourceFormatLoader",
76+
"ResourceFormatSaver",
77+
"ResourceImporter",
78+
"SceneState",
79+
"SceneTree",
80+
"SceneTreeTimer",
81+
"Script",
82+
"ScriptExtension",
83+
"ScriptLanguage",
84+
"Shape2D",
85+
"Shape3D",
86+
"Sky",
87+
"StyleBox",
88+
"TextServer",
89+
"Texture",
90+
"Texture2D",
91+
"Theme",
92+
"TriangleMesh",
93+
"Tween",
94+
"Tweener",
95+
"Viewport",
96+
"ViewportTexture",
97+
"Window",
98+
"World2D",
99+
"World3D",
100+
}
101+
102+
29103
def make_jinja_env(import_dir: Path) -> Environment:
30104
env = Environment(
31105
loader=FileSystemLoader(import_dir),
@@ -48,6 +122,10 @@ def make_jinja_env(import_dir: Path) -> Environment:
48122
type=Path,
49123
help="Path to Godot extension_api.json file",
50124
)
125+
parser.add_argument(
126+
"--classes-sample",
127+
action="store_true",
128+
)
51129
parser.add_argument(
52130
"--build-config",
53131
required=True,
@@ -78,8 +156,16 @@ def make_jinja_env(import_dir: Path) -> Environment:
78156
template_name = f"{name}.j2"
79157
todo.append((output, template_name, template_home))
80158

159+
if need_classes:
160+
if args.classes_sample:
161+
filter_classes = GODOT_CLASSES_SAMPLE
162+
else:
163+
filter_classes = False # keep all classes
164+
else:
165+
filter_classes = True
166+
81167
api = parse_extension_api_json(
82-
path=args.input, build_config=BuildConfig(args.build_config), skip_classes=not need_classes
168+
path=args.input, build_config=BuildConfig(args.build_config), filter_classes=filter_classes
83169
)
84170

85171
for todo_output, todo_template_name, todo_template_home in todo:

src/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ generate_tmpl_cmd = [
2828
'--output',
2929
'@OUTPUT0@',
3030
]
31+
if get_option('classes_sample')
32+
generate_tmpl_cmd += '--classes-sample'
33+
endif
3134

3235

3336
##############################################################################

0 commit comments

Comments
 (0)