Add support for LLVM/MinGW and ARM64 Windows builds.

pull/1535/head
bruvzg 2024-06-20 09:38:54 +03:00
parent 9b98377a62
commit f2353da5a3
2 changed files with 48 additions and 8 deletions

View File

@ -74,7 +74,7 @@ def generate(env):
else: else:
env.Append(CCFLAGS=["-g2"]) env.Append(CCFLAGS=["-g2"])
else: else:
if using_clang(env) and not is_vanilla_clang(env): if using_clang(env) and not is_vanilla_clang(env) and not env["use_mingw"]:
# Apple Clang, its linker doesn't like -s. # Apple Clang, its linker doesn't like -s.
env.Append(LINKFLAGS=["-Wl,-S", "-Wl,-x", "-Wl,-dead_strip"]) env.Append(LINKFLAGS=["-Wl,-S", "-Wl,-x", "-Wl,-dead_strip"])
else: else:

View File

@ -1,3 +1,4 @@
import os
import sys import sys
import common_compiler_flags import common_compiler_flags
@ -72,10 +73,14 @@ def silence_msvc(env):
def options(opts): 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_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_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("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("silence_msvc", "Silence MSVC's cl/link stdout bloat, redirecting errors to stderr.", True))
opts.Add(BoolVariable("use_llvm", "Use the LLVM compiler", False))
opts.Add("mingw_prefix", "MinGW prefix", mingw)
def exists(env): def exists(env):
@ -86,12 +91,22 @@ def generate(env):
if not env["use_mingw"] and msvc.exists(env): if not env["use_mingw"] and msvc.exists(env):
if env["arch"] == "x86_64": if env["arch"] == "x86_64":
env["TARGET_ARCH"] = "amd64" env["TARGET_ARCH"] = "amd64"
elif env["arch"] == "arm64":
env["TARGET_ARCH"] = "arm64"
elif env["arch"] == "arm32":
env["TARGET_ARCH"] = "arm"
elif env["arch"] == "x86_32": elif env["arch"] == "x86_32":
env["TARGET_ARCH"] = "x86" env["TARGET_ARCH"] = "x86"
env["MSVC_SETUP_RUN"] = False # Need to set this to re-run the tool
env["MSVS_VERSION"] = None
env["MSVC_VERSION"] = None
env["is_msvc"] = True env["is_msvc"] = True
# MSVC, linker, and archiver. # MSVC, linker, and archiver.
msvc.generate(env) msvc.generate(env)
env.Tool("msvc")
env.Tool("mslib") env.Tool("mslib")
env.Tool("mslink") env.Tool("mslink")
@ -111,7 +126,7 @@ def generate(env):
if env["silence_msvc"] and not env.GetOption("clean"): if env["silence_msvc"] and not env.GetOption("clean"):
silence_msvc(env) silence_msvc(env)
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 env["use_mingw"] = True
mingw.generate(env) mingw.generate(env)
# Don't want lib prefixes # Don't want lib prefixes
@ -137,12 +152,32 @@ def generate(env):
else: else:
env["use_mingw"] = True env["use_mingw"] = True
# Cross-compilation using MinGW # Cross-compilation using MinGW
prefix = "i686" if env["arch"] == "x86_32" else env["arch"] prefix = ""
if env["mingw_prefix"]:
prefix = env["mingw_prefix"] + "/bin/"
if env["arch"] == "x86_64":
prefix += "x86_64"
elif env["arch"] == "arm64":
prefix += "aarch64"
elif env["arch"] == "arm32":
prefix += "armv7"
elif env["arch"] == "x86_32":
prefix += "i686"
if env["use_llvm"]:
env["CXX"] = prefix + "-w64-mingw32-clang++"
env["CC"] = prefix + "-w64-mingw32-clang"
env["AR"] = prefix + "-w64-mingw32-llvm-ar"
env["RANLIB"] = prefix + "-w64-mingw32-ranlib"
env["LINK"] = prefix + "-w64-mingw32-clang"
else:
env["CXX"] = prefix + "-w64-mingw32-g++" env["CXX"] = prefix + "-w64-mingw32-g++"
env["CC"] = prefix + "-w64-mingw32-gcc" env["CC"] = prefix + "-w64-mingw32-gcc"
env["AR"] = prefix + "-w64-mingw32-ar" env["AR"] = prefix + "-w64-mingw32-gcc-ar"
env["RANLIB"] = prefix + "-w64-mingw32-ranlib" env["RANLIB"] = prefix + "-w64-mingw32-ranlib"
env["LINK"] = prefix + "-w64-mingw32-g++" env["LINK"] = prefix + "-w64-mingw32-g++"
# Want dll suffix # Want dll suffix
env["SHLIBSUFFIX"] = ".dll" env["SHLIBSUFFIX"] = ".dll"
@ -156,6 +191,11 @@ def generate(env):
"-static-libstdc++", "-static-libstdc++",
] ]
) )
if env["use_llvm"]:
env.Append(LINKFLAGS=["-lstdc++"])
if sys.platform == "win32" or sys.platform == "msys":
my_spawn.configure(env)
env.Append(CPPDEFINES=["WINDOWS_ENABLED"]) env.Append(CPPDEFINES=["WINDOWS_ENABLED"])