detect.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import os
  2. import sys
  3. from typing import TYPE_CHECKING
  4. from methods import detect_darwin_sdk_path, print_error, print_warning
  5. from platform_methods import validate_arch
  6. if TYPE_CHECKING:
  7. from SCons.Script.SConscript import SConsEnvironment
  8. def get_name():
  9. return "iOS"
  10. def can_build():
  11. if sys.platform == "darwin" or ("OSXCROSS_IOS" in os.environ):
  12. return True
  13. return False
  14. def get_opts():
  15. from SCons.Variables import BoolVariable
  16. return [
  17. ("vulkan_sdk_path", "Path to the Vulkan SDK", ""),
  18. (
  19. "IOS_TOOLCHAIN_PATH",
  20. "Path to iOS toolchain",
  21. "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain",
  22. ),
  23. ("IOS_SDK_PATH", "Path to the iOS SDK", ""),
  24. BoolVariable("ios_simulator", "Build for iOS Simulator", False),
  25. ("ios_triple", "Triple for ios toolchain", ""),
  26. BoolVariable("generate_bundle", "Generate an APP bundle after building iOS/macOS binaries", False),
  27. ]
  28. def get_doc_classes():
  29. return [
  30. "EditorExportPlatformIOS",
  31. ]
  32. def get_doc_path():
  33. return "doc_classes"
  34. def get_flags():
  35. return {
  36. "arch": "arm64",
  37. "target": "template_debug",
  38. "use_volk": False,
  39. "metal": True,
  40. "supported": ["metal", "mono"],
  41. "builtin_pcre2_with_jit": False,
  42. }
  43. def configure(env: "SConsEnvironment"):
  44. # Validate arch.
  45. supported_arches = ["x86_64", "arm64"]
  46. validate_arch(env["arch"], get_name(), supported_arches)
  47. ## LTO
  48. if env["lto"] == "auto": # Disable by default as it makes linking in Xcode very slow.
  49. env["lto"] = "none"
  50. if env["lto"] != "none":
  51. if env["lto"] == "thin":
  52. env.Append(CCFLAGS=["-flto=thin"])
  53. env.Append(LINKFLAGS=["-flto=thin"])
  54. else:
  55. env.Append(CCFLAGS=["-flto"])
  56. env.Append(LINKFLAGS=["-flto"])
  57. ## Compiler configuration
  58. # Save this in environment for use by other modules
  59. if "OSXCROSS_IOS" in os.environ:
  60. env["osxcross"] = True
  61. env["ENV"]["PATH"] = env["IOS_TOOLCHAIN_PATH"] + "/Developer/usr/bin/:" + env["ENV"]["PATH"]
  62. compiler_path = "$IOS_TOOLCHAIN_PATH/usr/bin/${ios_triple}"
  63. ccache_path = os.environ.get("CCACHE")
  64. if ccache_path is None:
  65. env["CC"] = compiler_path + "clang"
  66. env["CXX"] = compiler_path + "clang++"
  67. env["S_compiler"] = compiler_path + "clang"
  68. else:
  69. # there aren't any ccache wrappers available for iOS,
  70. # to enable caching we need to prepend the path to the ccache binary
  71. env["CC"] = ccache_path + " " + compiler_path + "clang"
  72. env["CXX"] = ccache_path + " " + compiler_path + "clang++"
  73. env["S_compiler"] = ccache_path + " " + compiler_path + "clang"
  74. env["AR"] = compiler_path + "ar"
  75. env["RANLIB"] = compiler_path + "ranlib"
  76. ## Compile flags
  77. if env["ios_simulator"]:
  78. detect_darwin_sdk_path("iossimulator", env)
  79. env.Append(ASFLAGS=["-mios-simulator-version-min=12.0"])
  80. env.Append(CCFLAGS=["-mios-simulator-version-min=12.0"])
  81. env.Append(CPPDEFINES=["IOS_SIMULATOR"])
  82. env.extra_suffix = ".simulator" + env.extra_suffix
  83. else:
  84. detect_darwin_sdk_path("ios", env)
  85. env.Append(ASFLAGS=["-miphoneos-version-min=12.0"])
  86. env.Append(CCFLAGS=["-miphoneos-version-min=12.0"])
  87. if env["arch"] == "x86_64":
  88. if not env["ios_simulator"]:
  89. print_error("Building for iOS with 'arch=x86_64' requires 'ios_simulator=yes'.")
  90. sys.exit(255)
  91. env["ENV"]["MACOSX_DEPLOYMENT_TARGET"] = "10.9"
  92. env.Append(
  93. CCFLAGS=(
  94. "-fobjc-arc -arch x86_64"
  95. " -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fblocks"
  96. " -fasm-blocks -isysroot $IOS_SDK_PATH"
  97. ).split()
  98. )
  99. env.Append(ASFLAGS=["-arch", "x86_64"])
  100. elif env["arch"] == "arm64":
  101. env.Append(
  102. CCFLAGS=(
  103. "-fobjc-arc -arch arm64 -fmessage-length=0"
  104. " -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits"
  105. " -fpascal-strings -fblocks -fvisibility=hidden -MMD -MT dependencies"
  106. " -isysroot $IOS_SDK_PATH".split()
  107. )
  108. )
  109. env.Append(ASFLAGS=["-arch", "arm64"])
  110. # Temp fix for ABS/MAX/MIN macros in iOS SDK blocking compilation
  111. env.Append(CCFLAGS=["-Wno-ambiguous-macro"])
  112. env.Prepend(
  113. CPPPATH=[
  114. "$IOS_SDK_PATH/usr/include",
  115. "$IOS_SDK_PATH/System/Library/Frameworks/AudioUnit.framework/Headers",
  116. ]
  117. )
  118. env.Prepend(CPPPATH=["#platform/ios"])
  119. env.Append(CPPDEFINES=["IOS_ENABLED", "UNIX_ENABLED", "COREAUDIO_ENABLED"])
  120. if env["metal"] and env["arch"] != "arm64":
  121. print_warning("Target architecture '{}' does not support the Metal rendering driver".format(env["arch"]))
  122. env["metal"] = False
  123. if env["metal"]:
  124. env.AppendUnique(CPPDEFINES=["METAL_ENABLED", "RD_ENABLED"])
  125. env.Prepend(
  126. CPPPATH=[
  127. "$IOS_SDK_PATH/System/Library/Frameworks/Metal.framework/Headers",
  128. "$IOS_SDK_PATH/System/Library/Frameworks/QuartzCore.framework/Headers",
  129. ]
  130. )
  131. env.Prepend(CPPPATH=["#thirdparty/spirv-cross"])
  132. if env["vulkan"]:
  133. env.AppendUnique(CPPDEFINES=["VULKAN_ENABLED", "RD_ENABLED"])
  134. if env["opengl3"]:
  135. env.Append(CPPDEFINES=["GLES3_ENABLED", "GLES_SILENCE_DEPRECATION"])
  136. env.Prepend(
  137. CPPPATH=[
  138. "$IOS_SDK_PATH/System/Library/Frameworks/OpenGLES.framework/Headers",
  139. ]
  140. )