From f91c4a9b59aa6ccc2b809c8eaad03a7348ba3714 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:32:32 +0300 Subject: [PATCH] Fix LLVM/MinGW build on Windows. --- godot-patches/patch_mingw_build.diff | 12 ++++++++++++ godot-tools/windows.py | 22 ++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/godot-patches/patch_mingw_build.diff b/godot-patches/patch_mingw_build.diff index 2695bc0a1..b6becc8a2 100644 --- a/godot-patches/patch_mingw_build.diff +++ b/godot-patches/patch_mingw_build.diff @@ -226,3 +226,15 @@ index aec331a76c..be98814486 100644 #include #include #include +diff --git a/third_party/zlib/cpu_features.c b/third_party/zlib/cpu_features.c +index 64e0428..1332971 100644 +--- a/third_party/zlib/cpu_features.c ++++ b/third_party/zlib/cpu_features.c +@@ -11,7 +11,7 @@ + #include + #if defined(_MSC_VER) + #include +-#elif defined(ADLER32_SIMD_SSSE3) ++#elif defined(ADLER32_SIMD_SSSE3) || (defined(__clang__) && (defined(__i386__) || defined(__x86_64__))) + #include + #endif diff --git a/godot-tools/windows.py b/godot-tools/windows.py index 913100f46..0675e2c50 100644 --- a/godot-tools/windows.py +++ b/godot-tools/windows.py @@ -1,3 +1,4 @@ +import os import sys import my_spawn @@ -7,12 +8,14 @@ from SCons.Variables import * 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_clang_cl", "Use the clang driver 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("debug_crt", "Compile with MSVC's debug CRT (/MDd)", False)) opts.Add(BoolVariable("use_llvm", "Use the LLVM compiler", False)) - + opts.Add("mingw_prefix", "MinGW prefix", mingw) def exists(env): return True @@ -48,7 +51,7 @@ def generate(env): env["CC"] = "clang-cl" env["CXX"] = "clang-cl" - elif sys.platform == "win32" or sys.platform == "msys": + elif (sys.platform == "win32" or sys.platform == "msys") and not env["mingw_prefix"]: env["use_mingw"] = True mingw.generate(env) env.Append(CPPDEFINES=["MINGW_ENABLED"]) @@ -63,14 +66,18 @@ def generate(env): else: env["use_mingw"] = True # Cross-compilation using MinGW + prefix = "" + if env["mingw_prefix"]: + prefix = env["mingw_prefix"] + "/bin/" + if env["arch"] == "x86_64": - prefix = "x86_64" + prefix += "x86_64" elif env["arch"] == "arm64": - prefix = "aarch64" + prefix += "aarch64" elif env["arch"] == "arm32": - prefix = "armv7" + prefix += "armv7" elif env["arch"] == "x86_32": - prefix = "i686" + prefix += "i686" if env["use_llvm"]: env["CXX"] = prefix + "-w64-mingw32-clang++" @@ -100,3 +107,6 @@ def generate(env): "-Wl,--no-undefined", ] ) + + if (sys.platform == "win32" or sys.platform == "msys"): + my_spawn.configure(env)