Skip to content

Commit 5458596

Browse files
committed
Fix shell argument limit
1 parent 714c9e2 commit 5458596

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

tools/common_compiler_flags.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,6 @@ def generate(env):
121121
elif env["lto"] == "full":
122122
env.Append(CCFLAGS=["-flto"])
123123
env.Append(LINKFLAGS=["-flto"])
124+
125+
if env["platform"] == "linux" or env.get("use_mingw", False):
126+
env['ARFLAGS'] = "rcs"

tools/godotcpp.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import platform
3+
import tempfile
34
import sys
45

56
from SCons.Action import Action
@@ -162,6 +163,25 @@ def scons_generate_bindings(target, source, env):
162163
return None
163164

164165

166+
def _build_static_lib_with_rsp(target, source, env):
167+
target_lib = str(target[0])
168+
169+
with tempfile.NamedTemporaryFile(mode="w", suffix=".rsp", delete=False) as rsp_file:
170+
rsp_path = rsp_file.name
171+
for src in source:
172+
rsp_file.write(str(src) + "\n")
173+
174+
try:
175+
ar = env['AR']
176+
arflags = env.get("ARFLAGS", "")
177+
command = "{} {} {} @{}".format(ar, arflags, target_lib, rsp_path)
178+
env.Execute(command)
179+
finally:
180+
os.remove(rsp_path)
181+
182+
return None
183+
184+
165185
platforms = ["linux", "macos", "windows", "android", "ios", "web"]
166186

167187
# CPU architecture options.
@@ -513,6 +533,9 @@ def generate(env):
513533
"GodotCPPDocData": Builder(action=scons_generate_doc_source),
514534
}
515535
)
536+
if env["platform"] == "linux" or env.get("use_mingw", False):
537+
env.Append(BUILDERS={"GodotStaticLibRspBuilder": Builder(action=Action(_build_static_lib_with_rsp, "$ARCOMSTR"))})
538+
516539
env.AddMethod(_godot_cpp, "GodotCPP")
517540

518541

@@ -547,7 +570,13 @@ def _godot_cpp(env):
547570
library_name = "libgodot-cpp" + env["suffix"] + env["LIBSUFFIX"]
548571

549572
if env["build_library"]:
550-
library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources)
573+
if env["platform"] == "linux" or env.get("use_mingw", False):
574+
# Use a custom builder to aggregate object files into a static library using a temporary response file.
575+
# This avoids hitting the shell argument limit.
576+
library = env.GodotStaticLibRspBuilder(target=env.File("bin/%s" % library_name), source=env.Object(sources))
577+
else:
578+
library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources)
579+
551580
env.NoCache(library)
552581
default_args = [library]
553582

0 commit comments

Comments
 (0)