You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Implement "get_mingw_tool" to fix mingw prefixes
• Replaces "try_cmd" entirely and removes need for "get_mingw_bin_prefix" in isolation
This commit is contained in:
@@ -18,36 +18,30 @@ def get_name():
|
|||||||
return "Windows"
|
return "Windows"
|
||||||
|
|
||||||
|
|
||||||
def try_cmd(test, prefix, arch):
|
def get_mingw_tool(tool, prefix="", arch="", test="--version"):
|
||||||
if arch:
|
if not prefix:
|
||||||
try:
|
prefix = os.getenv("MINGW_PREFIX", "")
|
||||||
out = subprocess.Popen(
|
supported_arches = ["x86_64", "x86_32", "arm64", "arm32"]
|
||||||
get_mingw_bin_prefix(prefix, arch) + test,
|
if arch in supported_arches:
|
||||||
shell=True,
|
arches = [arch, ""]
|
||||||
stderr=subprocess.PIPE,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
)
|
|
||||||
out.communicate()
|
|
||||||
if out.returncode == 0:
|
|
||||||
return True
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
for a in ["x86_64", "x86_32", "arm64", "arm32"]:
|
arches = ["x86_64", "x86_32", "arm64", "arm32", ""]
|
||||||
|
for a in arches:
|
||||||
try:
|
try:
|
||||||
|
path = f"{get_mingw_bin_prefix(prefix, a)}{tool}"
|
||||||
out = subprocess.Popen(
|
out = subprocess.Popen(
|
||||||
get_mingw_bin_prefix(prefix, a) + test,
|
f"{path} {test}",
|
||||||
shell=True,
|
shell=True,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
)
|
)
|
||||||
out.communicate()
|
out.communicate()
|
||||||
if out.returncode == 0:
|
if out.returncode == 0:
|
||||||
return True
|
return path
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return False
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def can_build():
|
def can_build():
|
||||||
@@ -65,9 +59,7 @@ def can_build():
|
|||||||
|
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
# Cross-compiling with MinGW-w64 (old MinGW32 is not supported)
|
# Cross-compiling with MinGW-w64 (old MinGW32 is not supported)
|
||||||
prefix = os.getenv("MINGW_PREFIX", "")
|
if get_mingw_tool("gcc") or get_mingw_tool("clang"):
|
||||||
|
|
||||||
if try_cmd("gcc --version", prefix, "") or try_cmd("clang --version", prefix, ""):
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
@@ -255,30 +247,20 @@ def get_flags():
|
|||||||
|
|
||||||
|
|
||||||
def build_res_file(target, source, env: "SConsEnvironment"):
|
def build_res_file(target, source, env: "SConsEnvironment"):
|
||||||
|
cmdbase = get_mingw_tool("windres", env["mingw_prefix"], env["arch"])
|
||||||
|
if not cmdbase:
|
||||||
|
return -1
|
||||||
|
|
||||||
arch_aliases = {
|
arch_aliases = {
|
||||||
"x86_32": "pe-i386",
|
"x86_32": "pe-i386",
|
||||||
"x86_64": "pe-x86-64",
|
"x86_64": "pe-x86-64",
|
||||||
"arm32": "armv7-w64-mingw32",
|
"arm32": "armv7-w64-mingw32",
|
||||||
"arm64": "aarch64-w64-mingw32",
|
"arm64": "aarch64-w64-mingw32",
|
||||||
}
|
}
|
||||||
cmdbase = "windres --include-dir . --target=" + arch_aliases[env["arch"]]
|
cmdbase += " --include-dir . --target=" + arch_aliases[env["arch"]]
|
||||||
|
|
||||||
mingw_bin_prefix = get_mingw_bin_prefix(env["mingw_prefix"], env["arch"])
|
|
||||||
|
|
||||||
for x in range(len(source)):
|
for x in range(len(source)):
|
||||||
ok = True
|
cmd = f"{cmdbase} -i {source[x]} -o {target[x]}"
|
||||||
# Try prefixed executable (MinGW on Linux).
|
|
||||||
cmd = mingw_bin_prefix + cmdbase + " -i " + str(source[x]) + " -o " + str(target[x])
|
|
||||||
try:
|
|
||||||
out = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE).communicate()
|
|
||||||
if len(out[1]):
|
|
||||||
ok = False
|
|
||||||
except Exception:
|
|
||||||
ok = False
|
|
||||||
|
|
||||||
# Try generic executable (MSYS2).
|
|
||||||
if not ok:
|
|
||||||
cmd = cmdbase + " -i " + str(source[x]) + " -o " + str(target[x])
|
|
||||||
try:
|
try:
|
||||||
out = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE).communicate()
|
out = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE).communicate()
|
||||||
if len(out[1]):
|
if len(out[1]):
|
||||||
@@ -358,8 +340,8 @@ def setup_mingw(env: "SConsEnvironment"):
|
|||||||
)
|
)
|
||||||
sys.exit(255)
|
sys.exit(255)
|
||||||
|
|
||||||
if not try_cmd("gcc --version", env["mingw_prefix"], env["arch"]) and not try_cmd(
|
if not get_mingw_tool("gcc", env["mingw_prefix"], env["arch"]) and not get_mingw_tool(
|
||||||
"clang --version", env["mingw_prefix"], env["arch"]
|
"clang", env["mingw_prefix"], env["arch"]
|
||||||
):
|
):
|
||||||
print_error("No valid compilers found, use MINGW_PREFIX environment variable to set MinGW path.")
|
print_error("No valid compilers found, use MINGW_PREFIX environment variable to set MinGW path.")
|
||||||
sys.exit(255)
|
sys.exit(255)
|
||||||
@@ -600,10 +582,10 @@ def configure_mingw(env: "SConsEnvironment"):
|
|||||||
|
|
||||||
## Build type
|
## Build type
|
||||||
|
|
||||||
if not env["use_llvm"] and not try_cmd("gcc --version", env["mingw_prefix"], env["arch"]):
|
if not env["use_llvm"] and not get_mingw_tool("gcc", env["mingw_prefix"], env["arch"]):
|
||||||
env["use_llvm"] = True
|
env["use_llvm"] = True
|
||||||
|
|
||||||
if env["use_llvm"] and not try_cmd("clang --version", env["mingw_prefix"], env["arch"]):
|
if env["use_llvm"] and not get_mingw_tool("clang", env["mingw_prefix"], env["arch"]):
|
||||||
env["use_llvm"] = False
|
env["use_llvm"] = False
|
||||||
|
|
||||||
# TODO: Re-evaluate the need for this / streamline with common config.
|
# TODO: Re-evaluate the need for this / streamline with common config.
|
||||||
@@ -638,27 +620,26 @@ def configure_mingw(env: "SConsEnvironment"):
|
|||||||
if env["arch"] in ["x86_32", "x86_64"]:
|
if env["arch"] in ["x86_32", "x86_64"]:
|
||||||
env["x86_libtheora_opt_gcc"] = True
|
env["x86_libtheora_opt_gcc"] = True
|
||||||
|
|
||||||
mingw_bin_prefix = get_mingw_bin_prefix(env["mingw_prefix"], env["arch"])
|
|
||||||
|
|
||||||
if env["use_llvm"]:
|
if env["use_llvm"]:
|
||||||
env["CC"] = mingw_bin_prefix + "clang"
|
env["CC"] = get_mingw_tool("clang", env["mingw_prefix"], env["arch"])
|
||||||
env["CXX"] = mingw_bin_prefix + "clang++"
|
env["CXX"] = get_mingw_tool("clang++", env["mingw_prefix"], env["arch"])
|
||||||
if try_cmd("as --version", env["mingw_prefix"], env["arch"]):
|
tool_as = get_mingw_tool("as", env["mingw_prefix"], env["arch"])
|
||||||
env["AS"] = mingw_bin_prefix + "as"
|
tool_ar = get_mingw_tool("ar", env["mingw_prefix"], env["arch"])
|
||||||
if try_cmd("ar --version", env["mingw_prefix"], env["arch"]):
|
tool_ranlib = get_mingw_tool("ranlib", env["mingw_prefix"], env["arch"])
|
||||||
env["AR"] = mingw_bin_prefix + "ar"
|
|
||||||
if try_cmd("ranlib --version", env["mingw_prefix"], env["arch"]):
|
|
||||||
env["RANLIB"] = mingw_bin_prefix + "ranlib"
|
|
||||||
env.extra_suffix = ".llvm" + env.extra_suffix
|
env.extra_suffix = ".llvm" + env.extra_suffix
|
||||||
else:
|
else:
|
||||||
env["CC"] = mingw_bin_prefix + "gcc"
|
env["CC"] = get_mingw_tool("gcc", env["mingw_prefix"], env["arch"])
|
||||||
env["CXX"] = mingw_bin_prefix + "g++"
|
env["CXX"] = get_mingw_tool("g++", env["mingw_prefix"], env["arch"])
|
||||||
if try_cmd("as --version", env["mingw_prefix"], env["arch"]):
|
tool_as = get_mingw_tool("as", env["mingw_prefix"], env["arch"])
|
||||||
env["AS"] = mingw_bin_prefix + "as"
|
tool_ar = get_mingw_tool("gcc-ar", env["mingw_prefix"], env["arch"])
|
||||||
if try_cmd("gcc-ar --version", env["mingw_prefix"], env["arch"]):
|
tool_ranlib = get_mingw_tool("gcc-ranlib", env["mingw_prefix"], env["arch"])
|
||||||
env["AR"] = mingw_bin_prefix + "gcc-ar"
|
|
||||||
if try_cmd("gcc-ranlib --version", env["mingw_prefix"], env["arch"]):
|
if tool_as:
|
||||||
env["RANLIB"] = mingw_bin_prefix + "gcc-ranlib"
|
env["AS"] = tool_as
|
||||||
|
if tool_ar:
|
||||||
|
env["AR"] = tool_ar
|
||||||
|
if tool_ranlib:
|
||||||
|
env["RANLIB"] = tool_ranlib
|
||||||
|
|
||||||
## LTO
|
## LTO
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,17 @@
|
|||||||
"""Functions used to generate source files during build time"""
|
"""Functions used to generate source files during build time"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from detect import get_mingw_bin_prefix
|
from detect import get_mingw_tool
|
||||||
from detect import try_cmd
|
|
||||||
|
|
||||||
|
|
||||||
def make_debug_mingw(target, source, env):
|
def make_debug_mingw(target, source, env):
|
||||||
dst = str(target[0])
|
objcopy = get_mingw_tool("objcopy", env["mingw_prefix"], env["arch"])
|
||||||
# Force separate debug symbols if executable size is larger than 1.9 GB.
|
strip = get_mingw_tool("strip", env["mingw_prefix"], env["arch"])
|
||||||
if env["separate_debug_symbols"] or os.stat(dst).st_size >= 2040109465:
|
|
||||||
mingw_bin_prefix = get_mingw_bin_prefix(env["mingw_prefix"], env["arch"])
|
if not objcopy or not strip:
|
||||||
if try_cmd("objcopy --version", env["mingw_prefix"], env["arch"]):
|
print('`separate_debug_symbols` requires both "objcopy" and "strip" to function.')
|
||||||
os.system(mingw_bin_prefix + "objcopy --only-keep-debug {0} {0}.debugsymbols".format(dst))
|
return
|
||||||
else:
|
|
||||||
os.system("objcopy --only-keep-debug {0} {0}.debugsymbols".format(dst))
|
os.system("{0} --only-keep-debug {1} {1}.debugsymbols".format(objcopy, target[0]))
|
||||||
if try_cmd("strip --version", env["mingw_prefix"], env["arch"]):
|
os.system("{0} --strip-debug --strip-unneeded {1}".format(strip, target[0]))
|
||||||
os.system(mingw_bin_prefix + "strip --strip-debug --strip-unneeded {0}".format(dst))
|
os.system("{0} --add-gnu-debuglink={1}.debugsymbols {1}".format(objcopy, target[0]))
|
||||||
else:
|
|
||||||
os.system("strip --strip-debug --strip-unneeded {0}".format(dst))
|
|
||||||
if try_cmd("objcopy --version", env["mingw_prefix"], env["arch"]):
|
|
||||||
os.system(mingw_bin_prefix + "objcopy --add-gnu-debuglink={0}.debugsymbols {0}".format(dst))
|
|
||||||
else:
|
|
||||||
os.system("objcopy --add-gnu-debuglink={0}.debugsymbols {0}".format(dst))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user