summaryrefslogtreecommitdiff
path: root/misc/patches/build_profile_4.0.diff
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2024-06-17 17:55:38 +0200
committerGitHub <noreply@github.com>2024-06-17 17:55:38 +0200
commit44ee53715d1645b8d14cf8a28f1822981e5628eb (patch)
tree78ddc23da6f20277ef97755e4038dd234409fe3f /misc/patches/build_profile_4.0.diff
parentbf8f6e45810930fb5216476f86929c0a675ec12d (diff)
parent0b89ed885d44d77c6e2e0a178264d2b78054bc6b (diff)
downloadfork-godot-webrtc-native-44ee53715d1645b8d14cf8a28f1822981e5628eb.tar.gz
fork-godot-webrtc-native-44ee53715d1645b8d14cf8a28f1822981e5628eb.tar.bz2
fork-godot-webrtc-native-44ee53715d1645b8d14cf8a28f1822981e5628eb.zip
Merge pull request #147 from Faless/build/build_profile
[CI] Add patches to use build profile and speed up builds
Diffstat (limited to 'misc/patches/build_profile_4.0.diff')
-rw-r--r--misc/patches/build_profile_4.0.diff180
1 files changed, 180 insertions, 0 deletions
diff --git a/misc/patches/build_profile_4.0.diff b/misc/patches/build_profile_4.0.diff
new file mode 100644
index 0000000..ee44112
--- /dev/null
+++ b/misc/patches/build_profile_4.0.diff
@@ -0,0 +1,180 @@
+diff --git a/godot-cpp-4.0/SConstruct b/godot-cpp-4.0/SConstruct
+index 27ee137..ec2af72 100644
+--- a/godot-cpp-4.0/SConstruct
++++ b/godot-cpp-4.0/SConstruct
+@@ -119,6 +119,14 @@ opts.Add(
+ opts.Add(
+ BoolVariable("generate_bindings", "Force GDExtension API bindings generation. Auto-detected by default.", False)
+ )
++opts.Add(
++ PathVariable(
++ "build_profile",
++ "Path to a file containing a feature build profile",
++ default=env.get("build_profile", None),
++ validator=lambda key, val, env: os.path.isfile(normalize_path(val)),
++ )
++)
+ opts.Add(BoolVariable("generate_template_get_node", "Generate a template version of the Node class's get_node.", True))
+
+ opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True))
+diff --git a/godot-cpp-4.0/binding_generator.py b/godot-cpp-4.0/binding_generator.py
+index 7634942..7ab51a5 100644
+--- a/godot-cpp-4.0/binding_generator.py
++++ b/godot-cpp-4.0/binding_generator.py
+@@ -70,12 +70,14 @@ def generate_wrappers(target):
+ f.write(txt)
+
+
+-def get_file_list(api_filepath, output_dir, headers=False, sources=False):
++def get_file_list(api_filepath, output_dir, headers=False, sources=False, profile_filepath=""):
+ api = {}
+ files = []
+ with open(api_filepath) as api_file:
+ api = json.load(api_file)
+
++ build_profile = parse_build_profile(profile_filepath, api)
++
+ core_gen_folder = Path(output_dir) / "gen" / "include" / "godot_cpp" / "core"
+ include_gen_folder = Path(output_dir) / "gen" / "include" / "godot_cpp"
+ source_gen_folder = Path(output_dir) / "gen" / "src"
+@@ -104,7 +106,7 @@ def get_file_list(api_filepath, output_dir, headers=False, sources=False):
+ source_filename = source_gen_folder / "classes" / (camel_to_snake(engine_class["name"]) + ".cpp")
+ if headers:
+ files.append(str(header_filename.as_posix()))
+- if sources:
++ if sources and is_class_included(engine_class["name"], build_profile):
+ files.append(str(source_filename.as_posix()))
+
+ for native_struct in api["native_structures"]:
+@@ -132,14 +134,107 @@ def get_file_list(api_filepath, output_dir, headers=False, sources=False):
+ return files
+
+
+-def print_file_list(api_filepath, output_dir, headers=False, sources=False):
++def print_file_list(api_filepath, output_dir, headers=False, sources=False, profile_filepath=""):
+ end = ";"
+- for f in get_file_list(api_filepath, output_dir, headers, sources):
++ for f in get_file_list(api_filepath, output_dir, headers, sources, profile_filepath):
+ print(f, end=end)
+
+
++def parse_build_profile(profile_filepath, api):
++ if profile_filepath == "":
++ return {}
++ print("Using feature build profile: " + profile_filepath)
++
++ with open(profile_filepath, encoding="utf-8") as profile_file:
++ profile = json.load(profile_file)
++
++ api_dict = {}
++ parents = {}
++ children = {}
++ for engine_class in api["classes"]:
++ api_dict[engine_class["name"]] = engine_class
++ parent = engine_class.get("inherits", "")
++ child = engine_class["name"]
++ parents[child] = parent
++ if parent == "":
++ continue
++ children[parent] = children.get(parent, [])
++ children[parent].append(child)
++
++ # Parse methods dependencies
++ deps = {}
++ reverse_deps = {}
++ for name, engine_class in api_dict.items():
++ ref_cls = set()
++ for method in engine_class.get("methods", []):
++ rtype = method.get("return_value", {}).get("type", "")
++ args = [a["type"] for a in method.get("arguments", [])]
++ if rtype in api_dict:
++ ref_cls.add(rtype)
++ elif is_enum(rtype) and get_enum_class(rtype) in api_dict:
++ ref_cls.add(get_enum_class(rtype))
++ for arg in args:
++ if arg in api_dict:
++ ref_cls.add(arg)
++ elif is_enum(arg) and get_enum_class(arg) in api_dict:
++ ref_cls.add(get_enum_class(arg))
++ deps[engine_class["name"]] = set(filter(lambda x: x != name, ref_cls))
++ for acls in ref_cls:
++ if acls == name:
++ continue
++ reverse_deps[acls] = reverse_deps.get(acls, set())
++ reverse_deps[acls].add(name)
++
++ included = []
++ front = list(profile.get("enabled_classes", []))
++ if front:
++ # These must always be included
++ front.append("WorkerThreadPool")
++ front.append("ClassDB")
++ front.append("ClassDBSingleton")
++ while front:
++ cls = front.pop()
++ if cls in included:
++ continue
++ included.append(cls)
++ parent = parents.get(cls, "")
++ if parent:
++ front.append(parent)
++ for rcls in deps.get(cls, set()):
++ if rcls in included or rcls in front:
++ continue
++ front.append(rcls)
++
++ excluded = []
++ front = list(profile.get("disabled_classes", []))
++ while front:
++ cls = front.pop()
++ if cls in excluded:
++ continue
++ excluded.append(cls)
++ front += children.get(cls, [])
++ for rcls in reverse_deps.get(cls, set()):
++ if rcls in excluded or rcls in front:
++ continue
++ front.append(rcls)
++
++ if included and excluded:
++ print(
++ "WARNING: Cannot specify both 'enabled_classes' and 'disabled_classes' in build profile. 'disabled_classes' will be ignored."
++ )
++
++ return {
++ "enabled_classes": included,
++ "disabled_classes": excluded,
++ }
++
++
+ def scons_emit_files(target, source, env):
+- files = [env.File(f) for f in get_file_list(str(source[0]), target[0].abspath, True, True)]
++ profile_filepath = env.get("build_profile", "")
++ if profile_filepath and not Path(profile_filepath).is_absolute():
++ profile_filepath = str((Path(env.Dir("#").abspath) / profile_filepath).as_posix())
++
++ files = [env.File(f) for f in get_file_list(str(source[0]), target[0].abspath, True, True, profile_filepath)]
+ env.Clean(target, files)
+ env["godot_cpp_gen_dir"] = target[0].abspath
+ return files, source
+@@ -1997,6 +2092,20 @@ def is_pod_type(type_name):
+ ]
+
+
++def is_class_included(class_name, build_profile):
++ """
++ Check if an engine class should be included.
++ This removes classes according to a build profile of enabled or disabled classes.
++ """
++ included = build_profile.get("enabled_classes", [])
++ excluded = build_profile.get("disabled_classes", [])
++ if included:
++ return class_name in included
++ if excluded:
++ return class_name not in excluded
++ return True
++
++
+ def is_included_type(type_name):
+ # Types which we already have implemented.
+ return is_included_struct_type(type_name) or type_name in ["ObjectID"]