Skip to content

Commit f2353da

Browse files
committed
Add support for LLVM/MinGW and ARM64 Windows builds.
1 parent 9b98377 commit f2353da

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

tools/common_compiler_flags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def generate(env):
7474
else:
7575
env.Append(CCFLAGS=["-g2"])
7676
else:
77-
if using_clang(env) and not is_vanilla_clang(env):
77+
if using_clang(env) and not is_vanilla_clang(env) and not env["use_mingw"]:
7878
# Apple Clang, its linker doesn't like -s.
7979
env.Append(LINKFLAGS=["-Wl,-S", "-Wl,-x", "-Wl,-dead_strip"])
8080
else:

tools/windows.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import sys
23

34
import common_compiler_flags
@@ -72,10 +73,14 @@ def spawn_capture(sh, escape, cmd, args, env):
7273

7374

7475
def options(opts):
76+
mingw = os.getenv("MINGW_PREFIX", "")
77+
7578
opts.Add(BoolVariable("use_mingw", "Use the MinGW compiler instead of MSVC - only effective on Windows", False))
7679
opts.Add(BoolVariable("use_clang_cl", "Use the clang driver instead of MSVC - only effective on Windows", False))
7780
opts.Add(BoolVariable("use_static_cpp", "Link MinGW/MSVC C++ runtime libraries statically", True))
7881
opts.Add(BoolVariable("silence_msvc", "Silence MSVC's cl/link stdout bloat, redirecting errors to stderr.", True))
82+
opts.Add(BoolVariable("use_llvm", "Use the LLVM compiler", False))
83+
opts.Add("mingw_prefix", "MinGW prefix", mingw)
7984

8085

8186
def exists(env):
@@ -86,12 +91,22 @@ def generate(env):
8691
if not env["use_mingw"] and msvc.exists(env):
8792
if env["arch"] == "x86_64":
8893
env["TARGET_ARCH"] = "amd64"
94+
elif env["arch"] == "arm64":
95+
env["TARGET_ARCH"] = "arm64"
96+
elif env["arch"] == "arm32":
97+
env["TARGET_ARCH"] = "arm"
8998
elif env["arch"] == "x86_32":
9099
env["TARGET_ARCH"] = "x86"
100+
101+
env["MSVC_SETUP_RUN"] = False # Need to set this to re-run the tool
102+
env["MSVS_VERSION"] = None
103+
env["MSVC_VERSION"] = None
104+
91105
env["is_msvc"] = True
92106

93107
# MSVC, linker, and archiver.
94108
msvc.generate(env)
109+
env.Tool("msvc")
95110
env.Tool("mslib")
96111
env.Tool("mslink")
97112

@@ -111,7 +126,7 @@ def generate(env):
111126
if env["silence_msvc"] and not env.GetOption("clean"):
112127
silence_msvc(env)
113128

114-
elif sys.platform == "win32" or sys.platform == "msys":
129+
elif (sys.platform == "win32" or sys.platform == "msys") and not env["mingw_prefix"]:
115130
env["use_mingw"] = True
116131
mingw.generate(env)
117132
# Don't want lib prefixes
@@ -137,12 +152,32 @@ def generate(env):
137152
else:
138153
env["use_mingw"] = True
139154
# Cross-compilation using MinGW
140-
prefix = "i686" if env["arch"] == "x86_32" else env["arch"]
141-
env["CXX"] = prefix + "-w64-mingw32-g++"
142-
env["CC"] = prefix + "-w64-mingw32-gcc"
143-
env["AR"] = prefix + "-w64-mingw32-ar"
144-
env["RANLIB"] = prefix + "-w64-mingw32-ranlib"
145-
env["LINK"] = prefix + "-w64-mingw32-g++"
155+
prefix = ""
156+
if env["mingw_prefix"]:
157+
prefix = env["mingw_prefix"] + "/bin/"
158+
159+
if env["arch"] == "x86_64":
160+
prefix += "x86_64"
161+
elif env["arch"] == "arm64":
162+
prefix += "aarch64"
163+
elif env["arch"] == "arm32":
164+
prefix += "armv7"
165+
elif env["arch"] == "x86_32":
166+
prefix += "i686"
167+
168+
if env["use_llvm"]:
169+
env["CXX"] = prefix + "-w64-mingw32-clang++"
170+
env["CC"] = prefix + "-w64-mingw32-clang"
171+
env["AR"] = prefix + "-w64-mingw32-llvm-ar"
172+
env["RANLIB"] = prefix + "-w64-mingw32-ranlib"
173+
env["LINK"] = prefix + "-w64-mingw32-clang"
174+
else:
175+
env["CXX"] = prefix + "-w64-mingw32-g++"
176+
env["CC"] = prefix + "-w64-mingw32-gcc"
177+
env["AR"] = prefix + "-w64-mingw32-gcc-ar"
178+
env["RANLIB"] = prefix + "-w64-mingw32-ranlib"
179+
env["LINK"] = prefix + "-w64-mingw32-g++"
180+
146181
# Want dll suffix
147182
env["SHLIBSUFFIX"] = ".dll"
148183

@@ -156,6 +191,11 @@ def generate(env):
156191
"-static-libstdc++",
157192
]
158193
)
194+
if env["use_llvm"]:
195+
env.Append(LINKFLAGS=["-lstdc++"])
196+
197+
if sys.platform == "win32" or sys.platform == "msys":
198+
my_spawn.configure(env)
159199

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

0 commit comments

Comments
 (0)