You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
[Apple embedded] Adopt SwiftUI lifecycle for Apple embedded platforms
- Introduces a SCons builder for Swift files - Increases the minimum deployment targets to iOS 14.0, and visionOS 26.0. - Replaces manually UIWindow management by a SwiftUI instantiated app.
This commit is contained in:
@@ -243,3 +243,85 @@ def generate_bundle_apple_embedded(platform, framework_dir, framework_dir_sim, u
|
||||
zip_dir = env.Dir("#bin/" + (app_prefix + extra_suffix).replace(".", "_")).abspath
|
||||
shutil.make_archive(zip_dir, "zip", root_dir=app_dir)
|
||||
shutil.rmtree(app_dir)
|
||||
|
||||
|
||||
def setup_swift_builder(env, apple_platform, sdk_path, current_path, bridging_header_filename, all_swift_files):
|
||||
from SCons.Script import Action, Builder
|
||||
|
||||
if apple_platform == "macos":
|
||||
target_suffix = "macosx10.9"
|
||||
|
||||
elif apple_platform == "ios":
|
||||
target_suffix = "ios14.0" # iOS 14.0 needed for SwiftUI lifecycle
|
||||
|
||||
elif apple_platform == "iossimulator":
|
||||
target_suffix = "ios14.0-simulator" # iOS 14.0 needed for SwiftUI lifecycle
|
||||
|
||||
elif apple_platform == "visionos":
|
||||
target_suffix = "xros26.0"
|
||||
|
||||
elif apple_platform == "visionossimulator":
|
||||
target_suffix = "xros26.0-simulator"
|
||||
|
||||
else:
|
||||
raise Exception("Invalid platform argument passed to detect_darwin_sdk_path")
|
||||
|
||||
swiftc_target = env["arch"] + "-apple-" + target_suffix
|
||||
|
||||
env["ALL_SWIFT_FILES"] = all_swift_files
|
||||
env["CURRENT_PATH"] = current_path
|
||||
frontend_path = "$APPLE_TOOLCHAIN_PATH/usr/bin/swift-frontend"
|
||||
bridging_header_path = current_path + "/" + bridging_header_filename
|
||||
env["SWIFTC"] = frontend_path + " -frontend -c" # Swift compiler
|
||||
env["SWIFTCFLAGS"] = [
|
||||
"-cxx-interoperability-mode=default",
|
||||
"-emit-object",
|
||||
"-target",
|
||||
swiftc_target,
|
||||
"-sdk",
|
||||
sdk_path,
|
||||
"-import-objc-header",
|
||||
bridging_header_path,
|
||||
"-swift-version",
|
||||
"6",
|
||||
"-parse-as-library",
|
||||
"-module-name",
|
||||
"godot_swift_module",
|
||||
"-I./", # Pass the current directory as the header root so bridging headers can include files from any point of the hierarchy
|
||||
]
|
||||
|
||||
if env["debug_symbols"]:
|
||||
env.Append(SWIFTCFLAGS=["-g"])
|
||||
|
||||
if env["optimize"] in ["speed", "speed_trace"]:
|
||||
env.Append(SWIFTCFLAGS=["-O"])
|
||||
|
||||
elif env["optimize"] == "size":
|
||||
env.Append(SWIFTCFLAGS=["-Osize"])
|
||||
|
||||
elif env["optimize"] in ["debug", "none"]:
|
||||
env.Append(SWIFTCFLAGS=["-Onone"])
|
||||
|
||||
def generate_swift_action(source, target, env, for_signature):
|
||||
fullpath_swift_files = [env["CURRENT_PATH"] + "/" + file for file in env["ALL_SWIFT_FILES"]]
|
||||
fullpath_swift_files.remove(source[0].abspath)
|
||||
|
||||
fullpath_swift_files_string = '"' + '" "'.join(fullpath_swift_files) + '"'
|
||||
compile_command = "$SWIFTC " + fullpath_swift_files_string + " -primary-file $SOURCE -o $TARGET $SWIFTCFLAGS"
|
||||
|
||||
swift_comdstr = env.get("SWIFTCOMSTR")
|
||||
if swift_comdstr is not None:
|
||||
swift_action = Action(compile_command, cmdstr=swift_comdstr)
|
||||
else:
|
||||
swift_action = Action(compile_command)
|
||||
|
||||
return swift_action
|
||||
|
||||
# Define Builder for Swift files
|
||||
swift_builder = Builder(
|
||||
generator=generate_swift_action, suffix=env["OBJSUFFIX"], src_suffix=".swift", emitter=methods.redirect_emitter
|
||||
)
|
||||
|
||||
env.Append(BUILDERS={"Swift": swift_builder})
|
||||
env["BUILDERS"]["Library"].add_src_builder("Swift")
|
||||
env["BUILDERS"]["Object"].add_action(".swift", Action(generate_swift_action, generator=1))
|
||||
|
||||
Reference in New Issue
Block a user