Skip to content

Commit 24bc6d8

Browse files
ze2jdsnopek
authored andcommitted
Fix shell argument limit
1 parent 3dd9bf1 commit 24bc6d8

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

tools/common_compiler_flags.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,6 @@ def generate(env):
131131
elif env["lto"] == "full":
132132
env.Append(CCFLAGS=["-flto"])
133133
env.Append(LINKFLAGS=["-flto"])
134+
135+
if env["platform"] == "linux" or env.get("use_mingw", False):
136+
env["ARFLAGS"] = "rcs"

tools/godotcpp.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import platform
33
import sys
4+
import tempfile
45

56
import header_builders
67
from SCons import __version__ as scons_raw_version
@@ -545,6 +546,11 @@ def generate(env):
545546
),
546547
}
547548
)
549+
if env["platform"] == "linux" or env.get("use_mingw", False):
550+
env.Append(
551+
BUILDERS={"GodotStaticLibRspBuilder": Builder(action=Action(_build_static_lib_with_rsp, "$ARCOMSTR"))}
552+
)
553+
548554
env.AddMethod(_godot_cpp, "GodotCPP")
549555

550556

@@ -560,6 +566,25 @@ def _get_api_file(extension_dir, api_version):
560566
return path
561567

562568

569+
def _build_static_lib_with_rsp(target, source, env):
570+
target_lib = str(target[0])
571+
572+
with tempfile.NamedTemporaryFile(mode="w", suffix=".rsp", delete=False) as rsp_file:
573+
rsp_path = rsp_file.name
574+
for src in source:
575+
rsp_file.write(str(src) + "\n")
576+
577+
try:
578+
ar = env["AR"]
579+
arflags = env.get("ARFLAGS", "")
580+
command = "{} {} {} @{}".format(ar, arflags, target_lib, rsp_path)
581+
env.Execute(command)
582+
finally:
583+
os.remove(rsp_path)
584+
585+
return None
586+
587+
563588
def _godot_cpp(env):
564589
extension_dir = normalize_path(env.get("gdextension_dir", default=env.Dir("gdextension").srcnode().abspath), env)
565590
default_api_file = _get_api_file(extension_dir, env.get("api_version", None))
@@ -600,7 +625,13 @@ def _godot_cpp(env):
600625
library_name = "libgodot-cpp" + env["suffix"] + env["LIBSUFFIX"]
601626

602627
if env["build_library"]:
603-
library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources)
628+
if env["platform"] == "linux" or env.get("use_mingw", False):
629+
# Use a custom builder to aggregate object files into a static library using a temporary response file.
630+
# This avoids hitting the shell argument limit.
631+
library = env.GodotStaticLibRspBuilder(target=env.File("bin/%s" % library_name), source=env.Object(sources))
632+
else:
633+
library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources)
634+
604635
env.NoCache(library)
605636
default_args = [library]
606637

0 commit comments

Comments
 (0)