Skip to content

Conversation

@rsanchezsaez
Copy link
Contributor

@rsanchezsaez rsanchezsaez commented Aug 26, 2025

Dear Godot community,

This PR is a followup to #105628 (I encourage you to read the description of that PR, where I outlined the plan, to get the full context for this contribution).

This change adds Swift compilation support to SCons, and adopts the SwiftUI lifecycle on Apple embedded platforms, which is the modern way of instantiating apps on Apple platforms. This is a pre-requesite for launching an immersive scene on visionOS.

This PR builds on top of #107789, so that one should be merged first.

cc @BastiaanOlij @stuartcarnie @bruvzg

Technical Discussion

I have developed and tested these changes using Xcode 26 beta 6 (17A5305f).

Minimum Deployment Targets

This PR increases the minimum deployment targets to iOS 14.0 (which is the minimum supported version for SwiftUI app lifecycle), and visionOS 26.0. We believe increasing the iOS target to 14.0 is acceptable given the age of that release.

SCons

There are parts of SCons I don't understand very well, and the current approach for compiling Swift is based on trial and error. I think the way the Builder is implemented a bit unorthodox, because Swift projects don't have header files, so you must pass all Swift files to the compiler.

I have tested that if there are more than one Swift file in the same subfolder, the are compiled and linked successfully.

If any SCons experts have suggestions for improving this aspect, we'd be happy to iterate on the solution.

Testing

We have been testing this PR with the Platformer demo project. We have verified the project continues to work on iOS and visionOS, both with the Mobile and Forward+ renderers using the Metal rendering driver.

Missing Functionality

  • The DPI metrics on visionOS are still hardcoded for now. They can change at runtime depending on how close the window is to the viewer. I think this is not a big deal breaker at this point of time. We may address this functionality in a separate PR in the future.

@rsanchezsaez rsanchezsaez requested review from a team as code owners August 26, 2025 00:07
@rsanchezsaez rsanchezsaez changed the title Apple/swiftui lifecycle SwiftUI lifecycle for Apple embedded platforms Aug 26, 2025
@rsanchezsaez rsanchezsaez force-pushed the apple/swiftui-lifecycle branch from 0438c42 to a7706c9 Compare August 26, 2025 00:40
@syntaxerror247 syntaxerror247 added this to the 4.x milestone Aug 26, 2025
Copy link
Contributor

@stuartcarnie stuartcarnie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great work, @rsanchezsaez and really appreciate you adding support to SCons to handle Swift files and C++ interop! The changes a minimally invasive, which is awesome!

Comment on lines -200 to +205

if (GLOBAL_GET("display/window/ios/allow_high_refresh_rate")) {
self.displayLink.preferredFramesPerSecond = 120;
} else {
self.displayLink.preferredFramesPerSecond = 60;
}
self.displayLink.preferredFramesPerSecond = self.preferredFrameRate;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

This has been moved to iOS (iPhone / iPad) specific implementation, as visionOS has different requirements (90 fps)

Copy link
Contributor

@stuartcarnie stuartcarnie Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I experimented with implementing a whole SCons module for adding Swift support. I think @rsanchezsaez's solution is totally fine. For other reviewers, essentially what it does is combine all .swift files into a single static library and Swift module. Swift has really great Objective-C and C++ interop, so it just works.

@akien-mga as expected, our builder will need to add the Swift compiler toolchain to be able to build these files. Swift is supported on Linux and Windows, so the toolchain is available, but it is unclear how much work I'll need to do to get it running on the Linux builder containers. I can certainly try.

The alternative is that Godot may wish to consider a dedicated machine running macOS for all the Apple builds, which would simplify our build process immensely. Getting it all working on Linux, particularly visionOS, was esoteric and I even patched the Clang toolchain to fix a bug processing visionOS availability via iOS availability attributes. I imagine the number of people able to support that work is relatively small…

@Repiteo Repiteo modified the milestones: 4.x, 4.6 Aug 29, 2025
- 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.
@rsanchezsaez rsanchezsaez force-pushed the apple/swiftui-lifecycle branch from 6a8e24d to 038f593 Compare September 23, 2025 01:20
Copy link
Contributor

@Repiteo Repiteo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the most "SCons" implementation, but neither is most of this repo so that's not exactly a blocker. Similarly, implementation-specific methods should ideally be relegated to implementation-specific locations, but the repo is also violating that (including the function directly preceeding setup_swift_builder())

I think we're safe to integrate this as-is!

@Repiteo Repiteo merged commit cf3c000 into godotengine:master Oct 3, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Oct 3, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants