| 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_error, 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 "iOS" |
| 14 |
|
| 15 |
|
| 16 |
def can_build(): |
| 17 |
if sys.platform == "darwin" or ("OSXCROSS_IOS" 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 |
("vulkan_sdk_path", "Path to the Vulkan SDK", ""), |
| 28 |
("SWIFT_FRONTEND", "Path to the swift-frontend binary", ""), |
| 29 |
|
| 30 |
(("APPLE_TOOLCHAIN_PATH", "IOS_TOOLCHAIN_PATH"), "Path to the Apple toolchain", ""), |
| 31 |
(("APPLE_SDK_PATH", "IOS_SDK_PATH"), "Path to the iOS SDK", ""), |
| 32 |
(("apple_target_triple", "ios_triple"), "Triple for the corresponding target Apple platform toolchain", ""), |
| 33 |
BoolVariable(("simulator", "ios_simulator"), "Build for Simulator", False), |
| 34 |
BoolVariable("generate_bundle", "Generate an APP bundle after building iOS/macOS binaries", False), |
| 35 |
] |
| 36 |
|
| 37 |
|
| 38 |
def get_doc_classes(): |
| 39 |
return [ |
| 40 |
"EditorExportPlatformIOS", |
| 41 |
] |
| 42 |
|
| 43 |
|
| 44 |
def get_doc_path(): |
| 45 |
return "doc_classes" |
| 46 |
|
| 47 |
|
| 48 |
def get_flags(): |
| 49 |
return { |
| 50 |
"arch": "arm64", |
| 51 |
"target": "template_debug", |
| 52 |
"use_volk": False, |
| 53 |
"metal": True, |
| 54 |
"supported": ["metal", "mono"], |
| 55 |
"builtin_pcre2_with_jit": False, |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
def configure(env: "SConsEnvironment"): |
| 60 |
|
| 61 |
supported_arches = ["x86_64", "arm64"] |
| 62 |
validate_arch(env["arch"], get_name(), supported_arches) |
| 63 |
detect_darwin_toolchain_path(env) |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
if env["lto"] == "auto": |
| 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 |
|
| 79 |
|
| 80 |
|
| 81 |
if "OSXCROSS_IOS" 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 |
|
| 95 |
|
| 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 |
|
| 103 |
|
| 104 |
if env["simulator"]: |
| 105 |
env["APPLE_PLATFORM"] = "iossimulator" |
| 106 |
env.Append(ASFLAGS=["-mios-simulator-version-min=14.0"]) |
| 107 |
env.Append(CCFLAGS=["-mios-simulator-version-min=14.0"]) |
| 108 |
env.Append(CPPDEFINES=["IOS_SIMULATOR"]) |
| 109 |
env.extra_suffix = ".simulator" + env.extra_suffix |
| 110 |
else: |
| 111 |
env["APPLE_PLATFORM"] = "ios" |
| 112 |
env.Append(ASFLAGS=["-miphoneos-version-min=14.0"]) |
| 113 |
env.Append(CCFLAGS=["-miphoneos-version-min=14.0"]) |
| 114 |
detect_darwin_sdk_path(env["APPLE_PLATFORM"], env) |
| 115 |
|
| 116 |
if env["arch"] == "x86_64": |
| 117 |
if not env["simulator"]: |
| 118 |
print_error("Building for iOS with 'arch=x86_64' requires 'simulator=yes'.") |
| 119 |
sys.exit(255) |
| 120 |
|
| 121 |
env["ENV"]["MACOSX_DEPLOYMENT_TARGET"] = "10.9" |
| 122 |
env.Append( |
| 123 |
CCFLAGS=( |
| 124 |
"-fobjc-arc -arch x86_64" |
| 125 |
" -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fblocks" |
| 126 |
" -fasm-blocks -isysroot $APPLE_SDK_PATH" |
| 127 |
).split() |
| 128 |
) |
| 129 |
env.Append(ASFLAGS=["-arch", "x86_64"]) |
| 130 |
elif env["arch"] == "arm64": |
| 131 |
env.Append( |
| 132 |
CCFLAGS=( |
| 133 |
"-fobjc-arc -arch arm64 -fmessage-length=0" |
| 134 |
" -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits" |
| 135 |
" -fpascal-strings -fblocks -fvisibility=hidden -MMD -MT dependencies" |
| 136 |
" -isysroot $APPLE_SDK_PATH".split() |
| 137 |
) |
| 138 |
) |
| 139 |
env.Append(ASFLAGS=["-arch", "arm64"]) |
| 140 |
|
| 141 |
|
| 142 |
env.Append(CCFLAGS=["-Wno-ambiguous-macro"]) |
| 143 |
|
| 144 |
env.Prepend( |
| 145 |
CPPPATH=[ |
| 146 |
"$APPLE_SDK_PATH/usr/include", |
| 147 |
"$APPLE_SDK_PATH/System/Library/Frameworks/AudioUnit.framework/Headers", |
| 148 |
] |
| 149 |
) |
| 150 |
|
| 151 |
env.Prepend(CPPPATH=["#platform/ios"]) |
| 152 |
env.Append(CPPDEFINES=["IOS_ENABLED", "APPLE_EMBEDDED_ENABLED", "UNIX_ENABLED", "COREAUDIO_ENABLED"]) |
| 153 |
|
| 154 |
if env["metal"] and env["simulator"]: |
| 155 |
print_warning("iOS Simulator does not support the Metal rendering driver") |
| 156 |
env["metal"] = False |
| 157 |
|
| 158 |
if env["metal"]: |
| 159 |
env.AppendUnique(CPPDEFINES=["METAL_ENABLED", "RD_ENABLED"]) |
| 160 |
env.Prepend( |
| 161 |
CPPPATH=[ |
| 162 |
"$APPLE_SDK_PATH/System/Library/Frameworks/Metal.framework/Headers", |
| 163 |
"$APPLE_SDK_PATH/System/Library/Frameworks/MetalFX.framework/Headers", |
| 164 |
"$APPLE_SDK_PATH/System/Library/Frameworks/QuartzCore.framework/Headers", |
| 165 |
] |
| 166 |
) |
| 167 |
env.Prepend(CPPPATH=["#thirdparty/spirv-cross"]) |
| 168 |
|
| 169 |
if env["vulkan"] and env["simulator"]: |
| 170 |
print_warning("iOS Simulator does not support the Vulkan rendering driver") |
| 171 |
env["vulkan"] = False |
| 172 |
|
| 173 |
if env["vulkan"]: |
| 174 |
env.AppendUnique(CPPDEFINES=["VULKAN_ENABLED", "RD_ENABLED"]) |
| 175 |
|
| 176 |
if env["opengl3"]: |
| 177 |
env.Append(CPPDEFINES=["GLES3_ENABLED", "GLES_SILENCE_DEPRECATION"]) |
| 178 |
env.Append(CCFLAGS=["-Wno-module-import-in-extern-c"]) |
| 179 |
env.Prepend( |
| 180 |
CPPPATH=[ |
| 181 |
"$APPLE_SDK_PATH/System/Library/Frameworks/OpenGLES.framework/Headers", |
| 182 |
] |
| 183 |
) |