Skip to content

Commit

Permalink
SCons: incorrect compiler detection on msystem based environments
Browse files Browse the repository at this point in the history
As described in issue #1672 msys2 environments don't use a mingw prefix for their compiler binaries.

this patch detects MSYSTEM environment variable detects compilers directly
  • Loading branch information
enetheru committed Feb 4, 2025
1 parent ee2a895 commit ad4626a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tools/godotcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def options(opts, env):
default_platform = "linux"
elif sys.platform == "darwin":
default_platform = "macos"
elif sys.platform == "win32" or sys.platform == "msys":
elif sys.platform == "win32":
default_platform = "windows"
elif ARGUMENTS.get("platform", ""):
default_platform = ARGUMENTS.get("platform")
Expand Down
29 changes: 19 additions & 10 deletions tools/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import common_compiler_flags
import my_spawn
from SCons.Tool import mingw, msvc
from SCons.Tool import clang, clangxx, gcc, mingw, msvc
from SCons.Variables import BoolVariable


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


def options(opts):
mingw = os.getenv("MINGW_PREFIX", "")

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


def exists(env):
return True


def generate(env):
if not env["use_mingw"] and msvc.exists(env):
env["msystem"] = os.getenv("MSYSTEM", "")

if not (env["use_mingw"] or env["msystem"]) and msvc.exists(env):
if env["arch"] == "x86_64":
env["TARGET_ARCH"] = "amd64"
elif env["arch"] == "arm64":
Expand Down Expand Up @@ -130,9 +130,16 @@ def generate(env):
if env["silence_msvc"] and not env.GetOption("clean"):
silence_msvc(env)

elif (sys.platform == "win32" or sys.platform == "msys") and not env["mingw_prefix"]:
env["use_mingw"] = True
mingw.generate(env)
elif env["msystem"]:
# default compiler is dictated by the msystem environment.
match env["msystem"]:
case "UCRT64" | "MINGW64" | "MINGW32":
gcc.generate(env)
case "CLANG64" | "CLANGARM64" | "CLANG32":
env["use_llvm"] = True
clang.generate(env)
clangxx.generate(env)

# Don't want lib prefixes
env["IMPLIBPREFIX"] = ""
env["SHLIBPREFIX"] = ""
Expand All @@ -149,11 +156,14 @@ def generate(env):
"-static-libstdc++",
]
)
if env["use_llvm"]:
env.Append(LINKFLAGS=["-lstdc++"])

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

else:
mingw.generate(env)
env["use_mingw"] = True
# Cross-compilation using MinGW
prefix = ""
Expand Down Expand Up @@ -198,8 +208,7 @@ def generate(env):
if env["use_llvm"]:
env.Append(LINKFLAGS=["-lstdc++"])

if sys.platform == "win32" or sys.platform == "msys":
my_spawn.configure(env)
my_spawn.configure(env)

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

Expand Down

0 comments on commit ad4626a

Please sign in to comment.