detect.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import methods
  2. import os
  3. import sys
  4. from platform_methods import detect_arch
  5. from typing import TYPE_CHECKING
  6. if TYPE_CHECKING:
  7. from SCons import Environment
  8. def is_active():
  9. return True
  10. def get_name():
  11. return "UWP"
  12. def can_build():
  13. if os.name == "nt":
  14. # building natively on windows!
  15. if os.getenv("VSINSTALLDIR"):
  16. if os.getenv("ANGLE_SRC_PATH") is None:
  17. return False
  18. return True
  19. return False
  20. def get_opts():
  21. return [
  22. ("msvc_version", "MSVC version to use (ignored if the VCINSTALLDIR environment variable is set)", None),
  23. ]
  24. def get_flags():
  25. return [
  26. ("arch", detect_arch()),
  27. ("tools", False),
  28. ("xaudio2", True),
  29. ("builtin_pcre2_with_jit", False),
  30. ]
  31. def configure(env: "Environment"):
  32. # Validate arch.
  33. supported_arches = ["x86_32", "x86_64", "arm32"]
  34. if env["arch"] not in supported_arches:
  35. print(
  36. 'Unsupported CPU architecture "%s" for UWP. Supported architectures are: %s.'
  37. % (env["arch"], ", ".join(supported_arches))
  38. )
  39. sys.exit()
  40. env.msvc = True
  41. ## Build type
  42. if env["target"] == "release":
  43. env.Append(CCFLAGS=["/MD"])
  44. env.Append(LINKFLAGS=["/SUBSYSTEM:WINDOWS"])
  45. if env["optimize"] != "none":
  46. env.Append(CCFLAGS=["/O2", "/GL"])
  47. env.Append(LINKFLAGS=["/LTCG"])
  48. elif env["target"] == "release_debug":
  49. env.Append(CCFLAGS=["/MD"])
  50. env.Append(LINKFLAGS=["/SUBSYSTEM:CONSOLE"])
  51. env.AppendUnique(CPPDEFINES=["WINDOWS_SUBSYSTEM_CONSOLE"])
  52. if env["optimize"] != "none":
  53. env.Append(CCFLAGS=["/O2", "/Zi"])
  54. elif env["target"] == "debug":
  55. env.Append(CCFLAGS=["/Zi"])
  56. env.Append(CCFLAGS=["/MDd"])
  57. env.Append(LINKFLAGS=["/SUBSYSTEM:CONSOLE"])
  58. env.AppendUnique(CPPDEFINES=["WINDOWS_SUBSYSTEM_CONSOLE"])
  59. env.Append(LINKFLAGS=["/DEBUG"])
  60. ## Compiler configuration
  61. env["ENV"] = os.environ
  62. vc_base_path = os.environ["VCTOOLSINSTALLDIR"] if "VCTOOLSINSTALLDIR" in os.environ else os.environ["VCINSTALLDIR"]
  63. # Force to use Unicode encoding
  64. env.AppendUnique(CCFLAGS=["/utf-8"])
  65. # ANGLE
  66. angle_root = os.environ["ANGLE_SRC_PATH"]
  67. env.Prepend(CPPPATH=[angle_root + "/include"])
  68. jobs = str(env.GetOption("num_jobs"))
  69. angle_build_cmd = (
  70. "msbuild.exe "
  71. + angle_root
  72. + "/winrt/10/src/angle.sln /nologo /v:m /m:"
  73. + jobs
  74. + " /p:Configuration=Release /p:Platform="
  75. )
  76. if os.path.isfile(f"{angle_root}/winrt/10/src/angle.sln"):
  77. env["build_angle"] = True
  78. ## Architecture
  79. arch = ""
  80. if str(os.getenv("Platform")).lower() == "arm":
  81. print("Compiled program architecture will be an ARM executable (forcing arch=arm32).")
  82. arch = "arm"
  83. env["arch"] = "arm32"
  84. env.Append(LINKFLAGS=["/MACHINE:ARM"])
  85. env.Append(LIBPATH=[vc_base_path + "lib/store/arm"])
  86. angle_build_cmd += "ARM"
  87. env.Append(LIBPATH=[angle_root + "/winrt/10/src/Release_ARM/lib"])
  88. else:
  89. compiler_version_str = methods.detect_visual_c_compiler_version(env["ENV"])
  90. if compiler_version_str == "amd64" or compiler_version_str == "x86_amd64":
  91. env["arch"] = "x86_64"
  92. print("Compiled program architecture will be a x64 executable (forcing arch=x86_64).")
  93. elif compiler_version_str == "x86" or compiler_version_str == "amd64_x86":
  94. env["arch"] = "x86_32"
  95. print("Compiled program architecture will be a x86 executable (forcing arch=x86_32).")
  96. else:
  97. print(
  98. "Failed to detect MSVC compiler architecture version... Defaulting to x86 32-bit executable settings"
  99. " (forcing arch=x86_32). Compilation attempt will continue, but SCons can not detect for what architecture"
  100. " this build is compiled for. You should check your settings/compilation setup."
  101. )
  102. env["arch"] = "x86_32"
  103. if env["arch"] == "x86_32":
  104. arch = "x86"
  105. angle_build_cmd += "Win32"
  106. env.Append(LINKFLAGS=["/MACHINE:X86"])
  107. env.Append(LIBPATH=[vc_base_path + "lib/store"])
  108. env.Append(LIBPATH=[angle_root + "/winrt/10/src/Release_Win32/lib"])
  109. else:
  110. arch = "x64"
  111. angle_build_cmd += "x64"
  112. env.Append(LINKFLAGS=["/MACHINE:X64"])
  113. env.Append(LIBPATH=[os.environ["VCINSTALLDIR"] + "lib/store/amd64"])
  114. env.Append(LIBPATH=[angle_root + "/winrt/10/src/Release_x64/lib"])
  115. env["PROGSUFFIX"] = "." + arch + env["PROGSUFFIX"]
  116. env["OBJSUFFIX"] = "." + arch + env["OBJSUFFIX"]
  117. env["LIBSUFFIX"] = "." + arch + env["LIBSUFFIX"]
  118. ## Compile flags
  119. env.Prepend(CPPPATH=["#platform/uwp", "#drivers/windows"])
  120. env.Append(CPPDEFINES=["UWP_ENABLED", "WINDOWS_ENABLED", "TYPED_METHOD_BIND"])
  121. env.Append(CPPDEFINES=["GLES_ENABLED", "GL_GLEXT_PROTOTYPES", "EGL_EGLEXT_PROTOTYPES", "ANGLE_ENABLED"])
  122. winver = "0x0602" # Windows 8 is the minimum target for UWP build
  123. env.Append(CPPDEFINES=[("WINVER", winver), ("_WIN32_WINNT", winver), "WIN32"])
  124. env.Append(CPPDEFINES=["__WRL_NO_DEFAULT_LIB__", ("PNG_ABORT", "abort")])
  125. env.Append(CPPFLAGS=["/AI", vc_base_path + "lib/store/references"])
  126. env.Append(CPPFLAGS=["/AI", vc_base_path + "lib/x86/store/references"])
  127. env.Append(
  128. CCFLAGS=(
  129. '/FS /MP /GS /wd"4453" /wd"28204" /wd"4291" /Zc:wchar_t /Gm- /fp:precise /errorReport:prompt /WX-'
  130. " /Zc:forScope /Gd /EHsc /nologo".split()
  131. )
  132. )
  133. env.Append(CPPDEFINES=["_UNICODE", "UNICODE", ("WINAPI_FAMILY", "WINAPI_FAMILY_APP")])
  134. env.Append(CXXFLAGS=["/ZW"])
  135. env.Append(
  136. CCFLAGS=[
  137. "/AI",
  138. vc_base_path + "\\vcpackages",
  139. "/AI",
  140. os.environ["WINDOWSSDKDIR"] + "\\References\\CommonConfiguration\\Neutral",
  141. ]
  142. )
  143. ## Link flags
  144. env.Append(
  145. LINKFLAGS=[
  146. "/MANIFEST:NO",
  147. "/NXCOMPAT",
  148. "/DYNAMICBASE",
  149. "/WINMD",
  150. "/APPCONTAINER",
  151. "/ERRORREPORT:PROMPT",
  152. "/NOLOGO",
  153. "/TLBID:1",
  154. '/NODEFAULTLIB:"kernel32.lib"',
  155. '/NODEFAULTLIB:"ole32.lib"',
  156. ]
  157. )
  158. LIBS = [
  159. "WindowsApp",
  160. "mincore",
  161. "ws2_32",
  162. "libANGLE",
  163. "libEGL",
  164. "libGLESv2",
  165. "bcrypt",
  166. ]
  167. env.Append(LINKFLAGS=[p + ".lib" for p in LIBS])
  168. # Incremental linking fix
  169. env["BUILDERS"]["ProgramOriginal"] = env["BUILDERS"]["Program"]
  170. env["BUILDERS"]["Program"] = methods.precious_program
  171. env.Append(BUILDERS={"ANGLE": env.Builder(action=angle_build_cmd)})