|
1 | 1 | import os
|
2 | 2 | import platform
|
| 3 | +import tempfile |
3 | 4 | import sys
|
4 | 5 |
|
5 | 6 | from SCons.Action import Action
|
@@ -162,6 +163,25 @@ def scons_generate_bindings(target, source, env):
|
162 | 163 | return None
|
163 | 164 |
|
164 | 165 |
|
| 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 | + |
165 | 185 | platforms = ["linux", "macos", "windows", "android", "ios", "web"]
|
166 | 186 |
|
167 | 187 | # CPU architecture options.
|
@@ -513,6 +533,9 @@ def generate(env):
|
513 | 533 | "GodotCPPDocData": Builder(action=scons_generate_doc_source),
|
514 | 534 | }
|
515 | 535 | )
|
| 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 | + |
516 | 539 | env.AddMethod(_godot_cpp, "GodotCPP")
|
517 | 540 |
|
518 | 541 |
|
@@ -547,7 +570,13 @@ def _godot_cpp(env):
|
547 | 570 | library_name = "libgodot-cpp" + env["suffix"] + env["LIBSUFFIX"]
|
548 | 571 |
|
549 | 572 | 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 | + |
551 | 580 | env.NoCache(library)
|
552 | 581 | default_args = [library]
|
553 | 582 |
|
|
0 commit comments