11import os
22import platform
33import sys
4+ import tempfile
45
56import header_builders
67from 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+
563588def _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