Skip to content

Commit 121d48d

Browse files
FIX: Add custom library build handler to godotcpp.py for chunked object processing to prevent CI/CD from crashing
GitHub Actions runners have a limit of 1024 arguments, which would cause the CI jobs to fail if more 1024 `.o` files got generated during the build process.
1 parent 60b5a41 commit 121d48d

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

‎tools/godotcpp.py‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,44 @@ def generate(env):
528528
env.AddMethod(_godot_cpp, "GodotCPP")
529529

530530

531+
def _godot_cpp_build_library(target, source, env):
532+
ar = env.subst("$AR")
533+
arflags = env.subst("$ARFLAGS")
534+
ranlib = env.subst("$RANLIB")
535+
ranlibflags = env.subst("$RANLIBFLAGS")
536+
537+
target_lib = str(target[0])
538+
# Objects are the source for the library
539+
objects = [str(s) for s in source]
540+
541+
# Create directory if it doesn't exist
542+
if not os.path.exists(os.path.dirname(target_lib)):
543+
os.makedirs(os.path.dirname(target_lib))
544+
545+
# Remove existing library to start fresh
546+
if os.path.exists(target_lib):
547+
os.remove(target_lib)
548+
549+
# Process in chunks of 100
550+
for i in range(0, len(objects), 100):
551+
chunk = objects[i : i + 100]
552+
# Use Execute with an Action to get proper logging if no_verbose is not used
553+
# but here we manually call it.
554+
# AR typically needs "rc" flags. On Windows it might be "LIB"
555+
# We assume standard SCons ARFLAGS has what's needed.
556+
cmd = "%s %s %s %s" % (ar, arflags, target_lib, " ".join(chunk))
557+
if not env["verbose"]:
558+
print("Archiving %s (chunk %d-%d) ..." % (os.path.basename(target_lib), i, i + len(chunk)))
559+
res = env.Execute(cmd)
560+
if res != 0:
561+
return res
562+
563+
# Finalize library
564+
if ranlib:
565+
return env.Execute("%s %s %s" % (ranlib, ranlibflags, target_lib))
566+
return 0
567+
568+
531569
def _godot_cpp(env):
532570
extension_dir = normalize_path(env.get("gdextension_dir", default=env.Dir("gdextension").srcnode().abspath), env)
533571
api_file = normalize_path(
@@ -569,7 +607,12 @@ def _godot_cpp(env):
569607
library_name = "libgodot-cpp" + env["suffix"] + env["LIBSUFFIX"]
570608

571609
if env["build_library"]:
572-
library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources)
610+
objects = [env.Object(s) for s in sources]
611+
library = env.Command(
612+
target=env.File("bin/%s" % library_name),
613+
source=objects,
614+
action=Action(_godot_cpp_build_library, "$ARCOMSTR"),
615+
)
573616
env.NoCache(library)
574617
default_args = [library]
575618

0 commit comments

Comments
 (0)