Skip to content

Commit 28bd72a

Browse files
committed
Merge pull request #109758 from Repiteo/scons/dlltool-fix
SCons: Fix `dlltool` on Windows MinGW builds
2 parents e855f67 + d9a77a4 commit 28bd72a

File tree

3 files changed

+32
-48
lines changed

3 files changed

+32
-48
lines changed

methods.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,10 @@ def CommandNoCache(env, target, sources, command, **args):
603603
return result
604604

605605

606-
def Run(env, function):
606+
def Run(env, function, comstr="$GENCOMSTR"):
607607
from SCons.Script import Action
608608

609-
return Action(function, "$GENCOMSTR")
609+
return Action(function, comstr)
610610

611611

612612
def detect_darwin_toolchain_path(env):

platform/windows/SCsub

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,7 @@ env.add_source_files(sources, common_win)
7474
sources += res_obj
7575

7676
if env["accesskit"] and not env.msvc:
77-
env["BUILDERS"]["DEF"].emitter = redirect_emitter
78-
def_file = "uiautomationcore." + env["arch"] + ".def"
79-
def_target = "libuiautomationcore." + env["arch"] + ".a"
80-
def_obj = env.DEF(def_target, def_file)
81-
sources += def_obj
77+
sources += env.DEFLIB("uiautomationcore")
8278

8379
prog = env.add_program("#bin/godot", sources, PROGSUFFIX=env["PROGSUFFIX"])
8480
arrange_program_clean(prog)

platform/windows/detect.py

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -237,46 +237,6 @@ def get_flags():
237237
}
238238

239239

240-
def build_def_file(target, source, env: "SConsEnvironment"):
241-
arch_aliases = {
242-
"x86_32": "i386",
243-
"x86_64": "i386:x86-64",
244-
"arm32": "arm",
245-
"arm64": "arm64",
246-
}
247-
248-
cmdbase = "dlltool -m " + arch_aliases[env["arch"]]
249-
if env["arch"] == "x86_32":
250-
cmdbase += " -k"
251-
else:
252-
cmdbase += " --no-leading-underscore"
253-
254-
mingw_bin_prefix = get_mingw_bin_prefix(env["mingw_prefix"], env["arch"])
255-
256-
for x in range(len(source)):
257-
ok = True
258-
# Try prefixed executable (MinGW on Linux).
259-
cmd = mingw_bin_prefix + cmdbase + " -d " + str(source[x]) + " -l " + str(target[x])
260-
try:
261-
out = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE).communicate()
262-
if len(out[1]):
263-
ok = False
264-
except Exception:
265-
ok = False
266-
267-
# Try generic executable (MSYS2).
268-
if not ok:
269-
cmd = cmdbase + " -d " + str(source[x]) + " -l " + str(target[x])
270-
try:
271-
out = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE).communicate()
272-
if len(out[1]):
273-
return -1
274-
except Exception:
275-
return -1
276-
277-
return 0
278-
279-
280240
def configure_msvc(env: "SConsEnvironment"):
281241
"""Configure env to work with MSVC"""
282242

@@ -919,7 +879,35 @@ def configure_mingw(env: "SConsEnvironment"):
919879
env.Append(CPPDEFINES=["MINGW_ENABLED", ("MINGW_HAS_SECURE_API", 1)])
920880

921881
# dlltool
922-
env.Append(BUILDERS={"DEF": env.Builder(action=build_def_file, suffix=".a", src_suffix=".def")})
882+
env["DEF"] = get_detected(env, "dlltool")
883+
env["DEFCOM"] = "$DEF $DEFFLAGS -d $SOURCE -l $TARGET"
884+
env["DEFCOMSTR"] = "$CXXCOMSTR"
885+
env["DEFPREFIX"] = "$LIBPREFIX"
886+
env["DEFSUFFIX"] = ".${__env__['arch']}$LIBSUFFIX"
887+
env["DEFSRCSUFFIX"] = ".${__env__['arch']}.def"
888+
DEF_ALIASES = {
889+
"x86_32": "i386",
890+
"x86_64": "i386:x86-64",
891+
"arm32": "arm",
892+
"arm64": "arm64",
893+
}
894+
env.Append(DEFFLAGS=["-m", DEF_ALIASES[env["arch"]]])
895+
if env["arch"] == "x86_32":
896+
env.Append(DEFFLAGS=["-k"])
897+
else:
898+
env.Append(DEFFLAGS=["--no-leading-underscore"])
899+
900+
env.Append(
901+
BUILDERS={
902+
"DEFLIB": env.Builder(
903+
action=env.Run("$DEFCOM", "$DEFCOMSTR"),
904+
prefix="$DEFPREFIX",
905+
suffix="$DEFSUFFIX",
906+
src_suffix="$DEFSRCSUFFIX",
907+
emitter=methods.redirect_emitter,
908+
)
909+
}
910+
)
923911

924912

925913
def configure(env: "SConsEnvironment"):

0 commit comments

Comments
 (0)