Debian Codegraph @

platform/visionos/detect.py

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