-
Notifications
You must be signed in to change notification settings - Fork 133
Showcase a fix for exposing Swift types in an Objecive-C API #957
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
Open
abdulowork
wants to merge
1
commit into
swiftlang:main
Choose a base branch
from
abdulowork:timofey.solonin/pass-transitive-swift-modulemaps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pr! Not every target will have a generated modulemap, and not every transitive dependency will build a module compatible with the current compilation, so I don't think we should attempt to inject module map flags here.
Generally speaking, the intent is that the PIF generated by swift-package-manager is supposed to include module map paths in the "imparted build properties" as needed for SwiftPM targets generating module maps. Then, swift-build is responsible for ensuring those imparted build properties are imposed on transitive dependents which build for the same platform. Based on your bug report it's possible either SwiftPM is failing to add the right path to the PIF, or the imparted properties exist but aren't propagated to dependents correctly (I haven't taken a detailed look yet). The former we'd want to fix in SwiftPM, the latter we'd likely want to fix in Swift Build at dependency resolution time instead of when we're constructing the Swift compilation task
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the output of
swift package dump-pifand at similar information emitted withdefaults write com.apple.dt.XCBuild EnableBuildDebugging -bool YES. I see thatObjcTargethas the following inimpartedBuildProperties:And the SwiftTarget doesn't have the imparted
OTHER_SWIFT_FLAGS, so the transitive Swift consumer doesn't see the generatedSwiftTarget.modulemap.That still leaves me with a couple of questions: do I understand correctly that, for general Swift -> Swift compilation dependencies, SwiftPM relies on Swift Build to produce all outputs in
$(BUILT_PRODUCTS_DIR)and have them picked up by a sharedswiftc -I $(BUILT_PRODUCTS_DIR)search path?If my understanding is correct, I see another possible fix for this issue being Swift Build creating
$(BUILT_PRODUCTS_DIR)/SwiftTargetdirectory with themodule.modulemapand theSwiftTarget-Swift.h. Then, from my understanding, bothclang -fmodulesandswiftccan pick the necessary Clang module, and wouldn't need to rely on the imparted build settings at all.Would such a fix be acceptable, and would it need to be implemented in Swift Build?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the benefit of such a solution might be that if there is no
Swift Producer -> ObjC Consumerdependency, then the build system doesn't need to ask the compiler to generate the-Swift.hfile, and it doesn't need to create the modulemap, but if such an edge does occur, then in the case ofSwift Producer -> ObjC -> Swift ConsumertheSwift Consumerwill still be able to see everything due to emitted module and the header in the shared search path.Or is this something SwiftPM must decide on ahead of time based on its knowledge about the dependency graph?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I browsed some more through the PIF files, and I see the
MODULEMAP_FILE_CONTENTS,MODULEMAP_PATH,SWIFT_OBJC_INTERFACE_HEADER_DIRandSWIFT_OBJC_INTERFACE_HEADER_NAMEbuild settings there, which I assume get encoded into PIF from here. So perhaps for the fix with the shared search path, this would still require a change in SwiftPM and not in Swift Build