Skip to content

Commit 4996bcf

Browse files
committed
SCons: incorrect compiler detection on msystem based environments
As described in issue godotengine#1672 msys2 environments don't use a mingw prefix for their compiler binaries. this patch detects MSYSTEM environment variable detects compilers directly
1 parent ee2a895 commit 4996bcf

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

tools/godotcpp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def options(opts, env):
204204
default_platform = "linux"
205205
elif sys.platform == "darwin":
206206
default_platform = "macos"
207-
elif sys.platform == "win32" or sys.platform == "msys":
207+
elif sys.platform == "win32":
208208
default_platform = "windows"
209209
elif ARGUMENTS.get("platform", ""):
210210
default_platform = ARGUMENTS.get("platform")

tools/windows.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import common_compiler_flags
55
import my_spawn
6-
from SCons.Tool import mingw, msvc
6+
from SCons.Tool import clang, clangxx, mingw, msvc, gcc
77
from SCons.Variables import BoolVariable
88

99

@@ -73,22 +73,22 @@ def spawn_capture(sh, escape, cmd, args, env):
7373

7474

7575
def options(opts):
76-
mingw = os.getenv("MINGW_PREFIX", "")
77-
7876
opts.Add(BoolVariable("use_mingw", "Use the MinGW compiler instead of MSVC - only effective on Windows", False))
7977
opts.Add(BoolVariable("use_static_cpp", "Link MinGW/MSVC C++ runtime libraries statically", True))
8078
opts.Add(BoolVariable("silence_msvc", "Silence MSVC's cl/link stdout bloat, redirecting errors to stderr.", True))
8179
opts.Add(BoolVariable("debug_crt", "Compile with MSVC's debug CRT (/MDd)", False))
8280
opts.Add(BoolVariable("use_llvm", "Use the LLVM compiler (MVSC or MinGW depending on the use_mingw flag)", False))
83-
opts.Add("mingw_prefix", "MinGW prefix", mingw)
81+
opts.Add("mingw_prefix", "MinGW prefix", os.getenv("MINGW_PREFIX", "") )
8482

8583

8684
def exists(env):
8785
return True
8886

8987

9088
def generate(env):
91-
if not env["use_mingw"] and msvc.exists(env):
89+
env["msystem"] = os.getenv("MSYSTEM", "")
90+
91+
if not (env["use_mingw"] or env['msystem']) and msvc.exists(env):
9292
if env["arch"] == "x86_64":
9393
env["TARGET_ARCH"] = "amd64"
9494
elif env["arch"] == "arm64":
@@ -130,9 +130,16 @@ def generate(env):
130130
if env["silence_msvc"] and not env.GetOption("clean"):
131131
silence_msvc(env)
132132

133-
elif (sys.platform == "win32" or sys.platform == "msys") and not env["mingw_prefix"]:
134-
env["use_mingw"] = True
135-
mingw.generate(env)
133+
elif env["msystem"]:
134+
# default compiler is dictated by the msystem environment.
135+
match env["msystem"]:
136+
case "UCRT64" | "MINGW64" | "MINGW32":
137+
gcc.generate(env)
138+
case "CLANG64" | "CLANGARM64" | "CLANG32":
139+
env["use_llvm"] = True
140+
clang.generate(env)
141+
clangxx.generate(env)
142+
136143
# Don't want lib prefixes
137144
env["IMPLIBPREFIX"] = ""
138145
env["SHLIBPREFIX"] = ""
@@ -149,11 +156,14 @@ def generate(env):
149156
"-static-libstdc++",
150157
]
151158
)
159+
if env["use_llvm"]:
160+
env.Append(LINKFLAGS=["-lstdc++"])
152161

153162
# Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
154163
my_spawn.configure(env)
155164

156165
else:
166+
mingw.generate(env)
157167
env["use_mingw"] = True
158168
# Cross-compilation using MinGW
159169
prefix = ""
@@ -198,8 +208,7 @@ def generate(env):
198208
if env["use_llvm"]:
199209
env.Append(LINKFLAGS=["-lstdc++"])
200210

201-
if sys.platform == "win32" or sys.platform == "msys":
202-
my_spawn.configure(env)
211+
my_spawn.configure(env)
203212

204213
env.Append(CPPDEFINES=["WINDOWS_ENABLED"])
205214

0 commit comments

Comments
 (0)