Skip to content

[camera_avfoundation] Implementation swift migration #8988

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

Conversation

RobertOdrowaz
Copy link
Contributor

@RobertOdrowaz RobertOdrowaz commented Apr 3, 2025

Migrates camera implementation as part of flutter/flutter#119109

This PR includes the CameraPlugin class migration. Some additional changes regarding imports were necessary to keep Swift Package Manager compatibility. SPM does not support mixed languages in a single target. I assume there might be a better solution so I'm open to suggestions

After splitting only a new target for SPM is created in this PR and the objc implementation is moved to a dedicated directory.

During the plugin's migration from ObjC to Swift, there will be a transitional period during which the implementation will be mixed, with some parts already migrated to Swift and some still in ObjC. This is somewhat problematic with SwiftPM. SwiftPM does support packages with mixed language implementation but different languages have to be in separate targets. Every target defines a separate module which means that in some cases both have to be imported. However, this only applies to SwiftPM with Cocoapods we can mix Swift and ObjC code in the same pod and have a single module. Simmingly the best solution is to use conditional imports for the additional module when SwiftPM during the migration.

@testable import camera_avfoundation

#if canImport(camera_avfoundation_objc)
  @testable import camera_avfoundation_objc
#endif

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

@RobertOdrowaz RobertOdrowaz force-pushed the feature/camera-implementation-swift-migration branch from 9ba0c7b to 24ef036 Compare April 4, 2025 14:54
@RobertOdrowaz RobertOdrowaz force-pushed the feature/camera-implementation-swift-migration branch 2 times, most recently from 1d00092 to 912ce03 Compare April 5, 2025 11:52
@RobertOdrowaz RobertOdrowaz force-pushed the feature/camera-implementation-swift-migration branch 2 times, most recently from c0faae7 to d99fe5c Compare April 12, 2025 17:53
@hellohuanlin
Copy link
Contributor

Every target defines a separate Swift module which means that in some cases both will have to be imported.

I'm confused, the ObjC target doesn't define a "swift" module right? isn't it still a clang module?

@@ -13,9 +13,13 @@ A Flutter plugin to use the camera from your Flutter app.
s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' }
s.source = { :http => 'https://github.com/flutter/packages/tree/main/packages/camera_avfoundation' }
s.documentation_url = 'https://pub.dev/packages/camera_avfoundation'
s.source_files = 'camera_avfoundation/Sources/camera_avfoundation/**/*.{h,m}'
s.public_header_files = 'camera_avfoundation/Sources/camera_avfoundation/include/**/*.h'
s.module_map = 'camera_avfoundation/Sources/camera_avfoundation/include/CameraPlugin.modulemap'
Copy link
Contributor

@hellohuanlin hellohuanlin Apr 15, 2025

Choose a reason for hiding this comment

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

it's been a while since i touched this. Why we are removing the module map?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not supported with Swift static libraries.

[!] Using Swift static libraries with custom module maps is currently not supported. Please build `camera_avfoundation` as a framework or remove the custom module map.

It's still the same issue you've encountered here flutter/plugins#6369

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh i completely forgot about this! thanks for the reference.

dependencies: [],
exclude: ["include/camera_avfoundation-umbrella.h", "include/CameraPlugin.modulemap"],
Copy link
Contributor

Choose a reason for hiding this comment

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

same question to the umbrella header.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct me if I'm missing something but I don't see much value in having a custom umbrella header without a custom module map. Without the module map cocoapods generate the public umbrella header that includes everything either way

@RobertOdrowaz RobertOdrowaz force-pushed the feature/camera-implementation-swift-migration branch from d99fe5c to 57e7fe1 Compare April 15, 2025 06:31
@RobertOdrowaz
Copy link
Contributor Author

RobertOdrowaz commented Apr 15, 2025

I'm confused, the ObjC target doesn't define a "swift" module right? isn't it still a clang module?

Yes, there won't be a swift module for the ObjC target. I've corrected the description

@RobertOdrowaz RobertOdrowaz added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 16, 2025
@auto-submit auto-submit bot merged commit 7728bba into flutter:main Apr 16, 2025
82 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 21, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Apr 21, 2025
flutter/packages@2fcc403...ac21f53

2025-04-20 engine-flutter-autoroll@skia.org Roll Flutter from
3ed38e2 to cfb887c (17 revisions) (flutter/packages#9118)
2025-04-19 stuartmorgan@google.com [various] Scrubs pre-SDK-21 Android
code (flutter/packages#9112)
2025-04-18 engine-flutter-autoroll@skia.org Roll Flutter from
ecabb1a to 3ed38e2 (23 revisions) (flutter/packages#9114)
2025-04-18 ricardodalarme@outlook.com [flutter_svg] feat: Expose the
`colorMapper` property in `SvgPicture` (flutter/packages#9043)
2025-04-18 stuartmorgan@google.com [tool] Add initial file-based command
skipping (flutter/packages#8928)
2025-04-18 stuartmorgan@google.com [pigeon] Convert test plugins to SPM
(flutter/packages#9105)
2025-04-18 10687576+bparrishMines@users.noreply.github.com
[webview_flutter] Adds support to control overscrolling
(flutter/packages#8451)
2025-04-17 louisehsu@google.com [in_app_purchase] add
Storefront.countryCode() and AppStore.sync() (flutter/packages#8900)
2025-04-17 145144088+camfrandsen@users.noreply.github.com
[webview_flutter_wkwebview] Expose the allowsLinkPreview property in
WKWebView for iOS (flutter/packages#5029)
2025-04-17 10687576+bparrishMines@users.noreply.github.com
[webview_flutter_android][webview_flutter_wkwebview] Adds platform
implementations to set over-scroll mode (flutter/packages#9101)
2025-04-17 1063596+reidbaker@users.noreply.github.com
[shared_preferences] Update AGP to 8.9.1 (flutter/packages#9106)
2025-04-17 10687576+bparrishMines@users.noreply.github.com [pigeon] Adds
Kotlin lint tests to example code and fix lints (flutter/packages#9034)
2025-04-17 30872003+misos1@users.noreply.github.com
[video_player_avfoundation] enable more than 30 fps
(flutter/packages#7466)
2025-04-17 engine-flutter-autoroll@skia.org Roll Flutter from
aef4718 to ecabb1a (25 revisions) (flutter/packages#9104)
2025-04-16 stuartmorgan@google.com [pigeon] Unify iOS and macOS test
plugins (flutter/packages#9100)
2025-04-16 engine-flutter-autoroll@skia.org Roll Flutter from
db68c95 to aef4718 (7 revisions) (flutter/packages#9098)
2025-04-16 10687576+bparrishMines@users.noreply.github.com
[webview_flutter_platform_interface] Adds method to set overscroll mode
(flutter/packages#9099)
2025-04-16 matanlurey@users.noreply.github.com Update `CODEOWNERS`
(flutter/packages#8984)
2025-04-16 stuartmorgan@google.com [google_sign_is] Update iOS SDK to
8.0 (flutter/packages#9081)
2025-04-16 robert.odrowaz@leancode.pl [camera_avfoundation]
Implementation swift migration (flutter/packages#8988)
2025-04-16 32538273+ValentinVignal@users.noreply.github.com [go_router]
Adds `caseSensitive` to `GoRoute` (flutter/packages#8992)
2025-04-16 engine-flutter-autoroll@skia.org Manual roll Flutter from
30e53b0 to db68c95 (98 revisions) (flutter/packages#9092)
2025-04-15 stuartmorgan@google.com [tool] Run config-only build for
iOS/macOS native-test (flutter/packages#9080)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
CodixNinja pushed a commit to CodixNinja/flutter that referenced this pull request May 15, 2025
flutter/packages@2fcc403...ac21f53

2025-04-20 engine-flutter-autoroll@skia.org Roll Flutter from
409a8ac to cd51fa3 (17 revisions) (flutter/packages#9118)
2025-04-19 stuartmorgan@google.com [various] Scrubs pre-SDK-21 Android
code (flutter/packages#9112)
2025-04-18 engine-flutter-autoroll@skia.org Roll Flutter from
d0741df to 409a8ac (23 revisions) (flutter/packages#9114)
2025-04-18 ricardodalarme@outlook.com [flutter_svg] feat: Expose the
`colorMapper` property in `SvgPicture` (flutter/packages#9043)
2025-04-18 stuartmorgan@google.com [tool] Add initial file-based command
skipping (flutter/packages#8928)
2025-04-18 stuartmorgan@google.com [pigeon] Convert test plugins to SPM
(flutter/packages#9105)
2025-04-18 10687576+bparrishMines@users.noreply.github.com
[webview_flutter] Adds support to control overscrolling
(flutter/packages#8451)
2025-04-17 louisehsu@google.com [in_app_purchase] add
Storefront.countryCode() and AppStore.sync() (flutter/packages#8900)
2025-04-17 145144088+camfrandsen@users.noreply.github.com
[webview_flutter_wkwebview] Expose the allowsLinkPreview property in
WKWebView for iOS (flutter/packages#5029)
2025-04-17 10687576+bparrishMines@users.noreply.github.com
[webview_flutter_android][webview_flutter_wkwebview] Adds platform
implementations to set over-scroll mode (flutter/packages#9101)
2025-04-17 1063596+reidbaker@users.noreply.github.com
[shared_preferences] Update AGP to 8.9.1 (flutter/packages#9106)
2025-04-17 10687576+bparrishMines@users.noreply.github.com [pigeon] Adds
Kotlin lint tests to example code and fix lints (flutter/packages#9034)
2025-04-17 30872003+misos1@users.noreply.github.com
[video_player_avfoundation] enable more than 30 fps
(flutter/packages#7466)
2025-04-17 engine-flutter-autoroll@skia.org Roll Flutter from
9616f9c to d0741df (25 revisions) (flutter/packages#9104)
2025-04-16 stuartmorgan@google.com [pigeon] Unify iOS and macOS test
plugins (flutter/packages#9100)
2025-04-16 engine-flutter-autoroll@skia.org Roll Flutter from
a7ce7ff to 9616f9c (7 revisions) (flutter/packages#9098)
2025-04-16 10687576+bparrishMines@users.noreply.github.com
[webview_flutter_platform_interface] Adds method to set overscroll mode
(flutter/packages#9099)
2025-04-16 matanlurey@users.noreply.github.com Update `CODEOWNERS`
(flutter/packages#8984)
2025-04-16 stuartmorgan@google.com [google_sign_is] Update iOS SDK to
8.0 (flutter/packages#9081)
2025-04-16 robert.odrowaz@leancode.pl [camera_avfoundation]
Implementation swift migration (flutter/packages#8988)
2025-04-16 32538273+ValentinVignal@users.noreply.github.com [go_router]
Adds `caseSensitive` to `GoRoute` (flutter/packages#8992)
2025-04-16 engine-flutter-autoroll@skia.org Manual roll Flutter from
f2d54fd to a7ce7ff (98 revisions) (flutter/packages#9092)
2025-04-15 stuartmorgan@google.com [tool] Run config-only build for
iOS/macOS native-test (flutter/packages#9080)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
androidseb pushed a commit to androidseb/packages that referenced this pull request Jun 8, 2025
Migrates camera implementation as part of flutter/flutter#119109

~This PR includes the `CameraPlugin` class migration. Some additional changes regarding imports were necessary to keep Swift Package Manager compatibility. SPM does not support mixed languages in a single target. I assume there might be a better solution so I'm open to suggestions~

After splitting only a new target for SPM is created in this PR and the objc implementation is moved to a dedicated directory. 

During the plugin's migration from ObjC to Swift, there will be a transitional period during which the implementation will be mixed, with some parts already migrated to Swift and some still in ObjC. This is somewhat problematic with SwiftPM. SwiftPM does support packages with mixed language implementation but different languages have to be in separate targets. Every target defines a separate module which means that in some cases both have to be imported. However, this only applies to SwiftPM with Cocoapods we can mix Swift and ObjC code in the same pod and have a single module. Simmingly the best solution is to use conditional imports for the additional module when SwiftPM during the migration.
```swift
@testable import camera_avfoundation

#if canImport(camera_avfoundation_objc)
  @testable import camera_avfoundation_objc
#endif
```

## Pre-Review Checklist

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
FMorschel pushed a commit to FMorschel/packages that referenced this pull request Jun 9, 2025
Migrates camera implementation as part of flutter/flutter#119109

~This PR includes the `CameraPlugin` class migration. Some additional changes regarding imports were necessary to keep Swift Package Manager compatibility. SPM does not support mixed languages in a single target. I assume there might be a better solution so I'm open to suggestions~

After splitting only a new target for SPM is created in this PR and the objc implementation is moved to a dedicated directory. 

During the plugin's migration from ObjC to Swift, there will be a transitional period during which the implementation will be mixed, with some parts already migrated to Swift and some still in ObjC. This is somewhat problematic with SwiftPM. SwiftPM does support packages with mixed language implementation but different languages have to be in separate targets. Every target defines a separate module which means that in some cases both have to be imported. However, this only applies to SwiftPM with Cocoapods we can mix Swift and ObjC code in the same pod and have a single module. Simmingly the best solution is to use conditional imports for the additional module when SwiftPM during the migration.
```swift
@testable import camera_avfoundation

#if canImport(camera_avfoundation_objc)
  @testable import camera_avfoundation_objc
#endif
```

## Pre-Review Checklist

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: camera platform-ios platform-macos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants