|
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,23 @@ 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 | + rsp_fd, rsp_path = tempfile.mkstemp(suffix=".rsp") |
| 169 | + os.close(rsp_fd) |
| 170 | + try: |
| 171 | + with open(rsp_path, "w") as rsp_file: |
| 172 | + for src in source: |
| 173 | + rsp_file.write(str(src) + "\n") |
| 174 | + ar = env['AR'] |
| 175 | + arflags = env.get("ARFLAGS", "") |
| 176 | + command = "{} {} {} @{}".format(ar, arflags, target_lib, rsp_path) |
| 177 | + env.Execute(command) |
| 178 | + finally: |
| 179 | + os.remove(rsp_path) |
| 180 | + return None |
| 181 | + |
| 182 | + |
165 | 183 | platforms = ["linux", "macos", "windows", "android", "ios", "web"] |
166 | 184 |
|
167 | 185 | # CPU architecture options. |
@@ -513,6 +531,9 @@ def generate(env): |
513 | 531 | "GodotCPPDocData": Builder(action=scons_generate_doc_source), |
514 | 532 | } |
515 | 533 | ) |
| 534 | + if env["platform"] == "linux": |
| 535 | + env.Append(BUILDERS={"GodotStaticLibRspBuilder": Builder(action=Action(_build_static_lib_with_rsp, "$ARCOMSTR"))}) |
| 536 | + |
516 | 537 | env.AddMethod(_godot_cpp, "GodotCPP") |
517 | 538 |
|
518 | 539 |
|
@@ -547,7 +568,13 @@ def _godot_cpp(env): |
547 | 568 | library_name = "libgodot-cpp" + env["suffix"] + env["LIBSUFFIX"] |
548 | 569 |
|
549 | 570 | if env["build_library"]: |
550 | | - library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources) |
| 571 | + if env["platform"] == "linux": |
| 572 | + # Use a custom builder to aggregate object files into a static library using a temporary response file. |
| 573 | + # This avoids hitting the shell argument limit. |
| 574 | + library = env.GodotStaticLibRspBuilder(target=env.File("bin/%s" % library_name), source=env.Object(sources)) |
| 575 | + else: |
| 576 | + library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources) |
| 577 | + |
551 | 578 | env.NoCache(library) |
552 | 579 | default_args = [library] |
553 | 580 |
|
|
0 commit comments