-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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
Remove use of modulemaps in flutter/packages when using SwiftPM #148572
Comments
@loic-sharma and I like this approach and are planning to move forward with it. If users want to use modulemaps with SwiftPM, we plan to point them to SwiftPM's documentation about it: https://github.com/apple/swift-package-manager/blob/main/Documentation/Usage.md#creating-c-language-targets |
I created an experiment that allows for custom module maps with SwiftPM: flutter/packages@main...loic-sharma:flutter-packages:spm_camera_separate_public_file_symlinks This works by creating separate header directories for CocoaPods (
Due to these drawbacks we prefer to avoid module maps in SwiftPM if possible. |
In the tests: @import camera_avfoundation;
@import camera_avfoundation_test; If we were only in SwiftPM world, could we normally |
We could do imports directly. That actually makes me realize, we can simplify this even further. Since all the headers are public and we're not using a custom umbrella header and modulemap, we don't need to do a separate target or import separate headers. All the headers should be available via the |
Adds Swift Package Manager compatibility to `image_picker_ios`. The previous attempt, #6617, was partially reverted due to flutter/flutter#148307. This reland uses the new approach proposed in flutter/flutter#148572: the Swift Package Manager package does not have a `.modulemap`. As a result, the plugin no longer has a `.Test` submodule if using Swift Package Manager. Fixes flutter/flutter#146919.
Use case
To support both CocoaPods and Swift Package Manager, dynamic and static linking, two different modulemaps are needed.
CocoaPods modulemap
CocoaPods seems to require the modulemap be a
framework
module and doesn't use relative paths.For example,
SwiftPM modulemap
SwiftPM requires the modulemap to be named
module.modulemap
and be located within theinclude
directory. It also doesn't seem to work if defined as aframework
module and uses relative paths.For example,
The problem
The problem is that when you have two modulemaps (most likely also because one is named
module.modulemap
, which is the implicit modulemap file), this can cause issues:Proposal
It's been pretty difficult to figure out a way to support both CocoaPods and SwiftPM modulemaps. As a result, we're leaning towards eliminating modulemaps in SwiftPM.
Instead of using a modulemap and umbrella header for the SwiftPM integration of plugins, we simply allow all public headers to be available via
@import plugin_name_ios
.@import plugin_name_ios; - @import plugin_name_ios.Test;
The headers are already public and could be imported individually (like
#import <plugin_name_ios/PublicHeader_Test.h>
), so making them available through the module isn't much worse.Modulemap and umbrella header should be excluded from SwiftPM target:
.target( name: "plugin_name_ios", dependencies: [], + exclude: ["cocoapods_plugin_name_ios.modulemap", "plugin_name_ios-umbrella.h"],
Unit tests can also be kept compatible with both CocoaPods and SwiftPM with something like:
Prototype
flutter/packages@main...vashworth:packages:camera_avfoundation_remove_swiftpm_modulemap
Re-adding SwiftPM
.modulemap
sOnce the ecosystem has migrated to SwiftPM, we will remove support for CocoaPods. At this point, we should consider re-adding
module.modulemap
s to the plugins' SwiftPM integration. This step might not be necessary as we plan to rewrite plugins in Swift.The text was updated successfully, but these errors were encountered: