-
Notifications
You must be signed in to change notification settings - Fork 28.6k
Build Swift files in the engine to support Swift-only APIs on iOS and macOS #144791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can/should we use Xcode's swiftc? Will this work with Goma/RBE? |
We probably need not only a toolchain, but also we need to investigate any swift-specific GN features we'd need to use. |
Initially we should copy whatever is in the Chrome buildroot. After that's working, we may want to use the Xcode version to help stay more up-to-date.
Likely not. |
Not sure if I'm in the right spot, but here's a python script accumulating swiftc flags:
|
It's finally happened, there's a Swift-only API we need in the engine: #150392 |
I banged up a prototype of this a few weeks ago, but ran into a Until that's fixed, we'd need to opt back in to using stamp files in A question we need to consider is that Swift 5 is the first version of Swift to ship with a stable ABI. The first version of iOS to ship with Swift 5 runtime libs was iOS 13, but we support back to iOS 12. That means that for iOS 12 users, we'd be adding about 5MB of baggage to app size. |
|
Swift support actually landed over the past couple years (though the documentation is poor). I did need to update to a newer version of So yeah, I'll likely to update EDIT: the SHA you mentioned ( |
In order to, at some future date, support building Swift in the engine, we'll need an updated version of `gn`. Note that all versions of `gn` after f792b9756418af8ab8a91a4c15b582431cb86ff9 up to and including this version are affected by a crasher when building Swift `source_set` targets. The workaround to support Swift is to opt back in to stamp files until the issue is fixed. * Bug: https://crbug.com/gn/380799198 * Discussion: http://shortn/_KbylT3nDsZ Either way, prior to this patch, we were using a version of gn from 2021, so we should probably update to a more recent version of `gn` regardless. Issue: flutter/flutter#144791
Sent a gn roll patch as a trial balloon: flutter/engine#57169 |
Roll to tip-of-tree prior to testing Swift toolchain for macOS/iOS. Issue: flutter#144791
Roll to tip-of-tree prior to testing Swift toolchain for macOS/iOS. Issue: #144791 ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [X] I updated/added relevant documentation (doc comments with `///`). - [X] I added new tests to check the change I am making, or this PR is [test-exempt]. - [X] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [X] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
I’m actively working on this now. While I was experimenting with this back in November, I uncovered a gn bug (https://crbug.com/gn/380799198) that we'll need to work around by re-enabling stamp files until it's fixed in gn. Googlers can find details published at http://shortn/_KbylT3nDsZ. Will update once I’ve got a proof of concept. |
Support trailing closure syntax in FlutterRunLoop perform methods. This allows us to write Swift code like: ``` FlutterRunLoop.mainLoop.perform(withDelay: delay) { // code. } ``` Follow-up to flutter#168174. Issue: flutter#144791
Enables the `swift` tool in the gn mac toolchain and wires up support for Swift `source_set` targets. Ports `FlutterRunLoop` to Swift. * Adds `//flutter/build/config/mac:compiler` config that sets up `swiftflags` for the `swift` tool in the toolchain for macOS, and adds it to the default configs on `is_mac` builds. * Adds `mac_swift_lib_paths` in `engine/src/build/config/apple/apple_sdk.gni` which holds the path of Swift shared libraries for macOS targets. This is within the appropriate `macosx` SDK directory within Xcode. Finally, this code adds Swift code to the embedder and embedder tests as proof of concept and to prevent regressions. This ports `FlutterRunLoop` to Swift in order to verify Objective-C imports of Swift via the bridging header. Issue: flutter#144791 ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [X] I updated/added relevant documentation (doc comments with `///`). - [X] I added new tests to check the change I am making, or this PR is [test-exempt]. - [X] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [X] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Support trailing closure syntax in FlutterRunLoop perform methods. This allows us to write Swift code like: ``` FlutterRunLoop.mainLoop.perform(withDelay: delay) { // code. } ``` This also matches the ordering used in NSRunLoop/RunLoop: * https://developer.apple.com/documentation/foundation/runloop/perform(inmodes:block:)?language=objc * https://developer.apple.com/documentation/foundation/runloop/perform(inmodes:block:) Follow-up to #168174. No tests since this is just a method rename. Issue: #144791 ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [X] I updated/added relevant documentation (doc comments with `///`). - [X] I added new tests to check the change I am making, or this PR is [test-exempt]. - [X] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [X] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Update is that we can now write Swift in the iOS and macOS embedders. We are not yet ready to expose any public API written in Swift, so this should be used for internal implementation code only. |
In new Swift code in the iOS/macOS embedder, we currently lack core features currently provided by shared internal C++ library code in FML. This provides a logging implementation that can be used across the iOS/macOS embedders, whether in Swift, Objective-C, or C++ code, and migrates the iOS and macOS embedders to use it. This patch also introduces gn support for authoring [Swift Testing][] tests. * Introduces a `SwiftTestingRunner` class that launches the Swift Testing test runner, which runs all tests annotated with `@Test` linked into the current executable. * Introduces a `SwiftTestingRunnerMain` class that implements a main entrypoint that launches the `SwiftTestingRunner`. * Introduces a `gn` `source_set` target (`//flutter/shell/platform/darwin/common:swift_testing_main`) that includes the Swift Testing main entrypoint, such that `executable` targets can add it to their deps to automatically be built as a Swift Testing runner. * Adds a `framework_common_swift_unittests` executable target for the common framework unit tests, and wires that into the build and `run_tests.py` for macOS. Issue: #168564 Issue: #144791 [Swift Testing]: https://developer.apple.com/xcode/swift-testing/ ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [X] I updated/added relevant documentation (doc comments with `///`). - [X] I added new tests to check the change I am making, or this PR is [test-exempt]. - [X] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [X] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This adds Obj-C/Swift bridging headers to Swift targets, which allows us to use public Flutter framework API from Swift code in the framework. This also restricts visibility of the Swift framework targets to the corresponding framework target. The addition of a bridging header allows us to use public framework types declared in those headers from Swift, but those types are defined in the framework target, and thus using the Swift target directly may result in linking errors in the user. Instead, all usage of the Swift target should be transitive via the framework target. Issue: flutter#144791
As of #168929, this will be complete. |
This adds Obj-C/Swift bridging headers to Swift targets, which allows us to use public Flutter framework API from Swift code in the framework. This also restricts visibility of the Swift framework targets to the corresponding framework target. The addition of a bridging header allows us to use public framework types declared in those headers from Swift, but those types are defined in the framework target, and thus using the Swift target directly may result in linking errors in the user. Instead, all usage of the Swift target should be transitive via the framework target. Issue: #144791 ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [X] I updated/added relevant documentation (doc comments with `///`). - [X] I added new tests to check the change I am making, or this PR is [test-exempt]. - [X] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [X] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This migrates FlutterResizeSynchronizer from an Objective-C implementaton to a Swift implementation. This is serves a couple purposes: * adds the first Swift tests for the macOS embedder. * adds Swift usage of the Logger I added in flutter#168568. Issue: flutter#168564 Issue: flutter#144791
This migrates FlutterResizeSynchronizer from an Objective-C implementaton to a Swift implementation. This is serves a couple purposes: * adds the first Swift tests for the macOS embedder. * adds Swift usage of the Logger I added in flutter#168568. Issue: flutter#168564 Issue: flutter#144791
This patch: * migrates FlutterResizeSynchronizer from Objective-C to Swift. * adds an optional onTimeout parameter to ResizeSynchronizer.beginResize. * adds test coverage for the timeout case. * significantly improves the class documentation. * adds the first Swift Testing tests for the macOS embedder. * adds the new tests to run_test.py. Issue: flutter#168564 Issue: flutter#144791
This patch: * migrates FlutterResizeSynchronizer from Objective-C to Swift. * reorders the performCommit parameters to support trailing closure syntax in Swift. * adds an optional onTimeout parameter to ResizeSynchronizer.beginResize. * adds test coverage for the timeout case. * significantly improves the class documentation. * adds the first Swift Testing tests for the macOS embedder. * adds the new tests to run_test.py. Issue: flutter#168564 Issue: flutter#144791
This patch: * migrates FlutterResizeSynchronizer from Objective-C to Swift. * reorders the performCommit parameters to support trailing closure syntax in Swift. * adds an optional onTimeout parameter to ResizeSynchronizer.beginResize. * adds test coverage for the timeout case. * significantly improves the class documentation. * adds the first Swift Testing tests for the macOS embedder. * adds the new tests to run_test.py. Issue: flutter#168564 Issue: flutter#144791
This patch: * migrates FlutterResizeSynchronizer from Objective-C to Swift. * reorders the performCommit parameters to support trailing closure syntax in Swift. * adds an optional onTimeout parameter to ResizeSynchronizer.beginResize. * adds test coverage for the timeout case. * significantly improves the class documentation. * adds the first Swift Testing tests for the macOS embedder. * adds the new tests to run_test.py. Issue: flutter#168564 Issue: flutter#144791
This patch: * migrates FlutterResizeSynchronizer from Objective-C to Swift. * reorders the performCommit parameters to support trailing closure syntax in Swift. * adds an optional onTimeout parameter to ResizeSynchronizer.beginResize. * adds test coverage for the timeout case. * significantly improves the class documentation. * adds the first Swift Testing tests for the macOS embedder. * adds the new tests to run_test.py. Issue: flutter#168564 Issue: flutter#144791
This patch: * migrates FlutterResizeSynchronizer from Objective-C to Swift. * reorders the performCommit parameters to support trailing closure syntax in Swift. * adds an optional onTimeout parameter to ResizeSynchronizer.beginResize. * adds test coverage for the timeout case. * significantly improves the class documentation. * adds the first Swift Testing tests for the macOS embedder. * adds the new tests to run_test.py. Issue: flutter#168564 Issue: flutter#144791
This patch: * migrates FlutterResizeSynchronizer from Objective-C to Swift. * reorders the performCommit parameters to support trailing closure syntax in Swift. * adds an optional onTimeout parameter to ResizeSynchronizer.beginResize. * adds test coverage for the timeout case. * significantly improves the class documentation. * adds the first Swift Testing tests for the macOS embedder. * adds the new tests to run_test.py. Issue: flutter#168564 Issue: flutter#144791
This patch: * migrates FlutterResizeSynchronizer from Objective-C to Swift. * reorders the performCommit parameters to support trailing closure syntax in Swift. * adds an optional onTimeout parameter to ResizeSynchronizer.beginResize. * adds test coverage for the timeout case. * significantly improves the class documentation. * adds the first Swift Testing tests for the macOS embedder. * adds the new tests to run_test.py. Issue: flutter#168564 Issue: flutter#144791
This patch: * migrates FlutterResizeSynchronizer from Objective-C to Swift. * reorders the performCommit parameters to support trailing closure syntax in Swift. * adds an optional onTimeout parameter to ResizeSynchronizer.beginResize. * adds test coverage for the timeout case. * significantly improves the class documentation. * adds the first Swift Testing tests for the macOS embedder. * adds the new tests to run_test.py. Issue: flutter#168564 Issue: flutter#144791
This patch: * migrates FlutterResizeSynchronizer from Objective-C to Swift. * reorders the performCommit parameters to support trailing closure syntax in Swift. * adds an optional onTimeout parameter to ResizeSynchronizer.beginResize. * adds test coverage for the timeout case. * significantly improves the class documentation. * adds the first Swift Testing tests for the macOS embedder. * adds the new tests to run_test.py. Issue: flutter#168564 Issue: flutter#144791
This patch: * migrates FlutterResizeSynchronizer from Objective-C to Swift. * reorders the performCommit parameters to support trailing closure syntax in Swift. * adds an optional onTimeout parameter to ResizeSynchronizer.beginResize. * adds test coverage for the timeout case. * significantly improves the class documentation. * adds the first Swift Testing tests for the macOS embedder. * adds the new tests to run_test.py. Issue: flutter#168564 Issue: flutter#144791
This patch: * migrates FlutterResizeSynchronizer from Objective-C to Swift. * reorders the performCommit parameters to support trailing closure syntax in Swift. * adds an optional onTimeout parameter to ResizeSynchronizer.beginResize. * adds test coverage for the timeout case. * significantly improves the class documentation. * adds the first Swift Testing tests for the macOS embedder. * adds the new tests to run_test.py. Issue: flutter#168564 Issue: flutter#144791
This patch: * migrates FlutterResizeSynchronizer from Objective-C to Swift. * reorders the performCommit parameters to support trailing closure syntax in Swift. * adds an optional onTimeout parameter to ResizeSynchronizer.beginResize. * adds test coverage for the timeout case. * significantly improves the class documentation. * adds the first Swift Testing tests for the macOS embedder. * adds the new tests to run_test.py. Admittedly, the original purpose was just to add a class that we could write Swift tests for, but things got a bit out of hand. Issue: #168564 Issue: #144791 ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [X] I updated/added relevant documentation (doc comments with `///`). - [X] I added new tests to check the change I am making, or this PR is [test-exempt]. - [X] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [X] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Uh oh!
There was an error while loading. Please reload this page.
Apple has and will continue to ship Swift-only APIs. We would be able to add Swift files to the iOS and macOS embedder and tests where necessary. Figure out what's needed to compile Swift files in the engine (toolchain, gn flags, other tooling).
The text was updated successfully, but these errors were encountered: