detect.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import os
  2. import sys
  3. from typing import TYPE_CHECKING
  4. from methods import detect_darwin_sdk_path, detect_darwin_toolchain_path, 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 "visionOS"
  10. def can_build():
  11. if sys.platform == "darwin" or ("OSXCROSS_VISIONOS" in os.environ):
  12. return True
  13. return False
  14. def get_opts():
  15. from SCons.Variables import BoolVariable
  16. return [
  17. # APPLE_TOOLCHAIN_PATH Example: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
  18. (("APPLE_TOOLCHAIN_PATH", "IOS_TOOLCHAIN_PATH"), "Path to the Apple toolchain", ""),
  19. ("VISIONOS_SDK_PATH", "Path to the visionOS SDK", ""),
  20. ("apple_target_triple", "Triple for corresponding target Apple platform toolchain", ""),
  21. BoolVariable("simulator", "Build for Simulator", False),
  22. BoolVariable("generate_bundle", "Generate an APP bundle after building visionOS/macOS binaries", False),
  23. ]
  24. def get_doc_classes():
  25. return [
  26. "EditorExportPlatformVisionOS",
  27. ]
  28. def get_doc_path():
  29. return "doc_classes"
  30. def get_flags():
  31. return {
  32. "arch": "arm64",
  33. "target": "template_debug",
  34. "use_volk": False,
  35. "metal": True,
  36. "supported": ["metal", "mono"],
  37. "builtin_pcre2_with_jit": False,
  38. "vulkan": False,
  39. "opengl3": False,
  40. }
  41. def configure(env: "SConsEnvironment"):
  42. # Validate arch.
  43. supported_arches = ["x86_64", "arm64"]
  44. validate_arch(env["arch"], get_name(), supported_arches)
  45. detect_darwin_toolchain_path(env)
  46. ## LTO
  47. if env["lto"] == "auto": # Disable by default as it makes linking in Xcode very slow.
  48. env["lto"] = "none"
  49. if env["lto"] != "none":
  50. if env["lto"] == "thin":
  51. env.Append(CCFLAGS=["-flto=thin"])
  52. env.Append(LINKFLAGS=["-flto=thin"])
  53. else:
  54. env.Append(CCFLAGS=["-flto"])
  55. env.Append(LINKFLAGS=["-flto"])
  56. ## Compiler configuration
  57. # Save this in environment for use by other modules
  58. if "OSXCROSS_VISIONOS" in os.environ:
  59. env["osxcross"] = True
  60. env["ENV"]["PATH"] = env["APPLE_TOOLCHAIN_PATH"] + "/Developer/usr/bin/:" + env["ENV"]["PATH"]
  61. compiler_path = "$APPLE_TOOLCHAIN_PATH/usr/bin/${apple_target_triple}"
  62. ccache_path = os.environ.get("CCACHE")
  63. if ccache_path is None:
  64. env["CC"] = compiler_path + "clang"
  65. env["CXX"] = compiler_path + "clang++"
  66. env["S_compiler"] = compiler_path + "clang"
  67. else:
  68. # there aren't any ccache wrappers available for visionOS,
  69. # to enable caching we need to prepend the path to the ccache binary
  70. env["CC"] = ccache_path + " " + compiler_path + "clang"
  71. env["CXX"] = ccache_path + " " + compiler_path + "clang++"
  72. env["S_compiler"] = ccache_path + " " + compiler_path + "clang"
  73. env["AR"] = compiler_path + "ar"
  74. env["RANLIB"] = compiler_path + "ranlib"
  75. ## Compile flags
  76. if env["simulator"]:
  77. detect_darwin_sdk_path("visionossimulator", env)
  78. env.Append(ASFLAGS=["-mtargetos=xros2.0-simulator"])
  79. env.Append(CCFLAGS=["-mtargetos=xros2.0-simulator"])
  80. env.Append(CPPDEFINES=["VISIONOS_SIMULATOR"])
  81. env.extra_suffix = ".simulator" + env.extra_suffix
  82. else:
  83. detect_darwin_sdk_path("visionos", env)
  84. env.Append(ASFLAGS=["-mtargetos=xros2.0"])
  85. env.Append(CCFLAGS=["-mtargetos=xros2.0"])
  86. if env["arch"] == "arm64":
  87. env.Append(
  88. CCFLAGS=(
  89. "-fobjc-arc -arch arm64 -fmessage-length=0"
  90. " -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits"
  91. " -fpascal-strings -fblocks -fvisibility=hidden -MMD -MT dependencies"
  92. " -isysroot $VISIONOS_SDK_PATH".split()
  93. )
  94. )
  95. env.Append(ASFLAGS=["-arch", "arm64"])
  96. # Temp fix for ABS/MAX/MIN macros in visionOS SDK blocking compilation
  97. env.Append(CCFLAGS=["-Wno-ambiguous-macro"])
  98. env.Prepend(
  99. CPPPATH=[
  100. "$VISIONOS_SDK_PATH/usr/include",
  101. "$VISIONOS_SDK_PATH/System/Library/Frameworks/AudioUnit.framework/Headers",
  102. ]
  103. )
  104. env.Prepend(CPPPATH=["#platform/visionos"])
  105. env.Append(CPPDEFINES=["VISIONOS_ENABLED", "APPLE_EMBEDDED_ENABLED", "UNIX_ENABLED", "COREAUDIO_ENABLED"])
  106. if env["vulkan"]:
  107. print_warning("The visionOS platform does not support the Vulkan rendering driver")
  108. env["vulkan"] = False
  109. if env["metal"] and env["simulator"]:
  110. print_warning("visionOS Simulator does not support the Metal rendering driver")
  111. env["metal"] = False
  112. if env["metal"]:
  113. env.AppendUnique(CPPDEFINES=["METAL_ENABLED", "RD_ENABLED"])
  114. env.Prepend(
  115. CPPPATH=[
  116. "$VISIONOS_SDK_PATH/System/Library/Frameworks/Metal.framework/Headers",
  117. "$VISIONOS_SDK_PATH/System/Library/Frameworks/MetalFX.framework/Headers",
  118. "$VISIONOS_SDK_PATH/System/Library/Frameworks/QuartzCore.framework/Headers",
  119. ]
  120. )
  121. env.Prepend(CPPPATH=["#thirdparty/spirv-cross"])
  122. if env["opengl3"]:
  123. print_warning("The visionOS platform does not support the OpenGL rendering driver")
  124. env["opengl3"] = False