summaryrefslogtreecommitdiffstats
path: root/platform
diff options
context:
space:
mode:
authorAlvin Wong <alvinhochun@gmail.com>2024-08-31 17:42:21 +0800
committerAlvin Wong <alvinhochun@gmail.com>2024-09-01 02:13:31 +0800
commit35a8ff9284edc2f942b7dca942f2a3c4f3698b92 (patch)
tree2efb43b6573d5fbcf954fcaef7fb42068adbef30 /platform
parent61598c5c88d95b96811d386cb20d714c35f4c6d7 (diff)
downloadredot-engine-35a8ff9284edc2f942b7dca942f2a3c4f3698b92.tar.gz
mingw: Only use `ar --thin` on supported versions
The flag is supported since Binutils 2.38 [1] or LLVM 14 [2]. [1]: https://sourceware.org/bugzilla/show_bug.cgi?id=28759 [2]: https://github.com/llvm/llvm-project/commit/dd6e7e0d5722d6396f8a0e94146f0b5e50dfa028
Diffstat (limited to 'platform')
-rw-r--r--platform/windows/detect.py58
1 files changed, 57 insertions, 1 deletions
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index d2a9c2315f..92ac921cee 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -649,6 +649,61 @@ def configure_msvc(env: "SConsEnvironment", vcvars_msvc_config):
env.AppendUnique(LINKFLAGS=["/STACK:" + str(STACK_SIZE)])
+def get_ar_version(env):
+ ret = {
+ "major": -1,
+ "minor": -1,
+ "patch": -1,
+ "is_llvm": False,
+ }
+ try:
+ output = (
+ subprocess.check_output([env.subst(env["AR"]), "--version"], shell=(os.name == "nt"))
+ .strip()
+ .decode("utf-8")
+ )
+ except (subprocess.CalledProcessError, OSError):
+ print_warning("Couldn't check version of `ar`.")
+ return ret
+
+ match = re.search(r"GNU ar \(GNU Binutils\) (\d+)\.(\d+)(:?\.(\d+))?", output)
+ if match:
+ ret["major"] = int(match[1])
+ ret["minor"] = int(match[2])
+ if match[3]:
+ ret["patch"] = int(match[3])
+ else:
+ ret["patch"] = 0
+ return ret
+
+ match = re.search(r"LLVM version (\d+)\.(\d+)\.(\d+)", output)
+ if match:
+ ret["major"] = int(match[1])
+ ret["minor"] = int(match[2])
+ ret["patch"] = int(match[3])
+ ret["is_llvm"] = True
+ return ret
+
+ print_warning("Couldn't parse version of `ar`.")
+ return ret
+
+
+def get_is_ar_thin_supported(env):
+ """Check whether `ar --thin` is supported. It is only supported since Binutils 2.38 or LLVM 14."""
+ ar_version = get_ar_version(env)
+ if ar_version["major"] == -1:
+ return False
+
+ if ar_version["is_llvm"]:
+ return ar_version["major"] >= 14
+
+ if ar_version["major"] == 2:
+ return ar_version["minor"] >= 38
+
+ print_warning("Unknown Binutils `ar` version.")
+ return False
+
+
def configure_mingw(env: "SConsEnvironment"):
# Workaround for MinGW. See:
# https://www.scons.org/wiki/LongCmdLinesOnWin32
@@ -781,7 +836,8 @@ def configure_mingw(env: "SConsEnvironment"):
if env["use_llvm"] and os.name == "nt" and methods._colorize:
env.Append(CCFLAGS=["$(-fansi-escape-codes$)", "$(-fcolor-diagnostics$)"])
- env.Append(ARFLAGS=["--thin"])
+ if get_is_ar_thin_supported(env):
+ env.Append(ARFLAGS=["--thin"])
env.Append(CPPDEFINES=["WINDOWS_ENABLED", "WASAPI_ENABLED", "WINMIDI_ENABLED"])
env.Append(