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