You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Unify bits, arch, and android_arch into env["arch"]
Fully removes the `bits` option and adapts the code that relied on it. Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
This commit is contained in:
committed by
Rémi Verschelde
parent
8916949b50
commit
27b0f18275
@@ -1,5 +1,6 @@
|
||||
import methods
|
||||
import os
|
||||
from platform_methods import detect_arch
|
||||
|
||||
# To match other platforms
|
||||
STACK_SIZE = 8388608
|
||||
@@ -46,6 +47,7 @@ def can_build():
|
||||
def get_opts():
|
||||
from SCons.Variables import BoolVariable, EnumVariable
|
||||
|
||||
# TODO: These shouldn't be hard-coded for x86.
|
||||
mingw32 = ""
|
||||
mingw64 = ""
|
||||
if os.name == "posix":
|
||||
@@ -77,11 +79,14 @@ def get_opts():
|
||||
|
||||
|
||||
def get_flags():
|
||||
return []
|
||||
return [
|
||||
("arch", detect_arch()),
|
||||
]
|
||||
|
||||
|
||||
def build_res_file(target, source, env):
|
||||
if env["bits"] == "32":
|
||||
# TODO: This shouldn't be hard-coded for x86.
|
||||
if env["arch"] == "x86_32":
|
||||
cmdbase = env["mingw_prefix_32"]
|
||||
else:
|
||||
cmdbase = env["mingw_prefix_64"]
|
||||
@@ -100,21 +105,27 @@ def build_res_file(target, source, env):
|
||||
|
||||
|
||||
def setup_msvc_manual(env):
|
||||
# FIXME: This is super hacky, and probably obsolete.
|
||||
# Won't work with detect_arch() used for `arch` by default.
|
||||
|
||||
"""Set up env to use MSVC manually, using VCINSTALLDIR"""
|
||||
if env["bits"] != "default":
|
||||
if env["arch"] != "auto":
|
||||
print(
|
||||
"""
|
||||
Bits argument is not supported for MSVC compilation. Architecture depends on the Native/Cross Compile Tools Prompt/Developer Console
|
||||
(or Visual Studio settings) that is being used to run SCons. As a consequence, bits argument is disabled. Run scons again without bits
|
||||
argument (example: scons p=windows) and SCons will attempt to detect what MSVC compiler will be executed and inform you.
|
||||
Arch argument is not supported for MSVC manual configuration (VCINSTALLDIR configured).
|
||||
Architecture depends on the Native/Cross Compile Tools Prompt/Developer Console (or Visual Studio settings) that is being used to run SCons.
|
||||
As a consequence, the arch argument is disabled. Run scons again without arch argument (example: scons p=windows)
|
||||
and SCons will attempt to detect what MSVC compiler will be executed and inform you.
|
||||
"""
|
||||
)
|
||||
raise SCons.Errors.UserError("Bits argument should not be used when using VCINSTALLDIR")
|
||||
raise SCons.Errors.UserError("Arch argument should not be used when using VCINSTALLDIR")
|
||||
|
||||
# Force bits arg
|
||||
# Force ARCH arg
|
||||
# (Actually msys2 mingw can support 64-bit, we could detect that)
|
||||
env["bits"] = "32"
|
||||
env["x86_libtheora_opt_vc"] = True
|
||||
# TODO: This is wrong, but not sure what to do about it.
|
||||
# We want to determine the arch and bitness in the SConstruct only.
|
||||
# We can check if it's correct in here, but if it's not, it should
|
||||
# just fail with an error message instead of trying to force it.
|
||||
|
||||
# find compiler manually
|
||||
compiler_version_str = methods.detect_visual_c_compiler_version(env["ENV"])
|
||||
@@ -122,17 +133,19 @@ def setup_msvc_manual(env):
|
||||
|
||||
# If building for 64bit architecture, disable assembly optimisations for 32 bit builds (theora as of writing)... vc compiler for 64bit can not compile _asm
|
||||
if compiler_version_str == "amd64" or compiler_version_str == "x86_amd64":
|
||||
env["bits"] = "64"
|
||||
env["arch"] = "x86_64"
|
||||
env["x86_libtheora_opt_vc"] = False
|
||||
print("Compiled program architecture will be a 64 bit executable (forcing bits=64).")
|
||||
print("Compiled program architecture will be a 64 bit executable (forcing arch=x86_64).")
|
||||
elif compiler_version_str == "x86" or compiler_version_str == "amd64_x86":
|
||||
print("Compiled program architecture will be a 32 bit executable. (forcing bits=32).")
|
||||
env["arch"] = "x86_32"
|
||||
env["x86_libtheora_opt_vc"] = True
|
||||
print("Compiled program architecture will be a 32 bit executable (forcing arch=x86_32).")
|
||||
else:
|
||||
print(
|
||||
"Failed to manually detect MSVC compiler architecture version... Defaulting to 32bit executable settings"
|
||||
" (forcing bits=32). Compilation attempt will continue, but SCons can not detect for what architecture this"
|
||||
" build is compiled for. You should check your settings/compilation setup, or avoid setting VCINSTALLDIR."
|
||||
"Failed to manually detect MSVC compiler architecture version.\n"
|
||||
"You should check your settings/compilation setup, or avoid setting VCINSTALLDIR."
|
||||
)
|
||||
sys.exit()
|
||||
|
||||
|
||||
def setup_msvc_auto(env):
|
||||
@@ -141,6 +154,18 @@ def setup_msvc_auto(env):
|
||||
# If MSVC_VERSION is set by SCons, we know MSVC is installed.
|
||||
# But we may want a different version or target arch.
|
||||
|
||||
# Valid architectures for MSVC's TARGET_ARCH:
|
||||
# ['amd64', 'emt64', 'i386', 'i486', 'i586', 'i686', 'ia64', 'itanium', 'x86', 'x86_64', 'arm', 'arm64', 'aarch64']
|
||||
# Our x86_64 and arm64 are the same, and we need to map the 32-bit
|
||||
# architectures to other names since MSVC isn't as explicit.
|
||||
# The rest we don't need to worry about because they are
|
||||
# aliases or aren't supported by Godot (itanium & ia64).
|
||||
msvc_arch_aliases = {"x86_32": "x86", "arm32": "arm"}
|
||||
if env["arch"] in msvc_arch_aliases.keys():
|
||||
env["TARGET_ARCH"] = msvc_arch_aliases[env["arch"]]
|
||||
else:
|
||||
env["TARGET_ARCH"] = env["arch"]
|
||||
|
||||
# The env may have already been set up with default MSVC tools, so
|
||||
# reset a few things so we can set it up with the tools we want.
|
||||
# (Ideally we'd decide on the tool config before configuring any
|
||||
@@ -149,21 +174,14 @@ def setup_msvc_auto(env):
|
||||
env["MSVC_SETUP_RUN"] = False # Need to set this to re-run the tool
|
||||
env["MSVS_VERSION"] = None
|
||||
env["MSVC_VERSION"] = None
|
||||
env["TARGET_ARCH"] = None
|
||||
if env["bits"] != "default":
|
||||
env["TARGET_ARCH"] = {"32": "x86", "64": "x86_64"}[env["bits"]]
|
||||
|
||||
if "msvc_version" in env:
|
||||
env["MSVC_VERSION"] = env["msvc_version"]
|
||||
env.Tool("msvc")
|
||||
env.Tool("mssdk") # we want the MS SDK
|
||||
# Note: actual compiler version can be found in env['MSVC_VERSION'], e.g. "14.1" for VS2015
|
||||
# Get actual target arch into bits (it may be "default" at this point):
|
||||
if env["TARGET_ARCH"] in ("amd64", "x86_64"):
|
||||
env["bits"] = "64"
|
||||
else:
|
||||
env["bits"] = "32"
|
||||
print("Found MSVC version %s, arch %s, bits=%s" % (env["MSVC_VERSION"], env["TARGET_ARCH"], env["bits"]))
|
||||
if env["TARGET_ARCH"] in ("amd64", "x86_64"):
|
||||
print("Found MSVC version %s, arch %s" % (env["MSVC_VERSION"], env["TARGET_ARCH"]))
|
||||
if env["arch"] == "x86_32":
|
||||
env["x86_libtheora_opt_vc"] = False
|
||||
|
||||
|
||||
@@ -244,7 +262,7 @@ def configure_msvc(env, manual_msvc_config):
|
||||
]
|
||||
)
|
||||
env.AppendUnique(CPPDEFINES=["NOMINMAX"]) # disable bogus min/max WinDef.h macros
|
||||
if env["bits"] == "64":
|
||||
if env["arch"] == "x86_64":
|
||||
env.AppendUnique(CPPDEFINES=["_WIN64"])
|
||||
|
||||
## Libs
|
||||
@@ -328,10 +346,10 @@ def configure_mingw(env):
|
||||
env.Append(CCFLAGS=["-msse2"])
|
||||
|
||||
if env["optimize"] == "speed": # optimize for speed (default)
|
||||
if env["bits"] == "64":
|
||||
env.Append(CCFLAGS=["-O3"])
|
||||
else:
|
||||
if env["arch"] == "x86_32":
|
||||
env.Append(CCFLAGS=["-O2"])
|
||||
else:
|
||||
env.Append(CCFLAGS=["-O3"])
|
||||
else: # optimize for size
|
||||
env.Prepend(CCFLAGS=["-Os"])
|
||||
|
||||
@@ -365,15 +383,12 @@ def configure_mingw(env):
|
||||
if os.name != "nt":
|
||||
env["PROGSUFFIX"] = env["PROGSUFFIX"] + ".exe" # for linux cross-compilation
|
||||
|
||||
if env["bits"] == "default":
|
||||
if os.name == "nt":
|
||||
env["bits"] = "64" if "PROGRAMFILES(X86)" in os.environ else "32"
|
||||
else: # default to 64-bit on Linux
|
||||
env["bits"] = "64"
|
||||
|
||||
mingw_prefix = ""
|
||||
|
||||
if env["bits"] == "32":
|
||||
# TODO: This doesn't seem to be working, or maybe I just have
|
||||
# MinGW set up incorrectly. It always gives me x86_64 builds,
|
||||
# even though arch == "x86_32" and the file name has x86_32 in it.
|
||||
if env["arch"] == "x86_32":
|
||||
if env["use_static_cpp"]:
|
||||
env.Append(LINKFLAGS=["-static"])
|
||||
env.Append(LINKFLAGS=["-static-libgcc"])
|
||||
@@ -460,11 +475,18 @@ def configure_mingw(env):
|
||||
|
||||
|
||||
def configure(env):
|
||||
# Validate arch.
|
||||
supported_arches = ["x86_32", "x86_64", "arm32", "arm64"]
|
||||
if env["arch"] not in supported_arches:
|
||||
print(
|
||||
'Unsupported CPU architecture "%s" for Windows. Supported architectures are: %s.'
|
||||
% (env["arch"], ", ".join(supported_arches))
|
||||
)
|
||||
sys.exit()
|
||||
|
||||
# At this point the env has been set up with basic tools/compilers.
|
||||
env.Prepend(CPPPATH=["#platform/windows"])
|
||||
|
||||
print("Configuring for Windows: target=%s, bits=%s" % (env["target"], env["bits"]))
|
||||
|
||||
if os.name == "nt":
|
||||
env["ENV"] = os.environ # this makes build less repeatable, but simplifies some things
|
||||
env["ENV"]["TMP"] = os.environ["TMP"]
|
||||
|
||||
Reference in New Issue
Block a user