Skip to content
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

[SR-13075] Swift Package that has @objc in Swift code causes Objective-C module failure with transitive depdency #4531

Open
niw opened this issue Jun 25, 2020 · 3 comments
Labels

Comments

@niw
Copy link
Contributor

niw commented Jun 25, 2020

Previous ID SR-13075
Radar https://feedbackassistant.apple.com/feedback/7781285
Original Reporter @niw
Type Bug
Environment
  • Xcode 11.5 (11E608c)

  • Xcode 12.0 beta (12A6159)

Additional Detail from JIRA
Votes 6
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: d0de46f3d4acb3486ea389af9cfdde7a

is blocked by:

  • SR-14575 Frameworks built from Swift packages lack a Headers folder

Issue Description:

When the Xcode target (such as Application) has a transitive dependency to the Swift Package, such as it is importing a dynamic framework that is importing Swift Package that has public @objc interface, such as a delegate protocol, we can’t build the target due to Objective-C module failure.

Reproducible project is at https://github.com/niw/swift_package_objc_module_failure.

Error message you will see is like this.

<module-includes>:2:9: note: in file included from <module-includes>:2:
#import "Headers/TestFramework-Swift.h"
        ^
/Users/niw/Library/Developer/Xcode/DerivedData/Test-gcmgljtjqifdtzbblkpxoahggxkj/Build/Products/Debug-iphonesimulator/TestFramework.framework/Headers/TestFramework-Swift.h:192:9: error: module 'TestPackage' not found
@import TestPackage;
        ^
<unknown>:0: error: could not build Objective-C module 'TestFramework'

In this example, the dependency is like this.

Application target (Test)
→ Dynamic Framework target (TestFramework)
→ Swift Package (TestPackage)

Since if the middle dynamic link library is using Swift package or not is unrelated to both the application target owner and package owner, all Swift packages that have @objc can have this issue.
Therefore, currently basically @objc can't be use feely in Swift Package.

A few observations:

  • This is caused by missing -Xcc -module-map-file for swift -frontend for the transitive Swift package dependency used for the Swift files in the application target.

  • This is not happening if the module that Swift Package provided is written in Objective-C.

@niw
Copy link
Contributor Author

niw commented Jun 25, 2020

This is also asked in https://developer.apple.com/forums/thread/650935 at WWDC20.

@niw
Copy link
Contributor Author

niw commented Jun 26, 2020

@swift-ci
Copy link
Contributor

swift-ci commented May 3, 2021

Comment by Jonathan Gilbert (JIRA)

I think the reason is simply because the .framework built from the Swift Package will be missing a Headers directory. If I make an Xcode project from the same code as my Swift Package, but now I add a Copy Headers phase and add an umbrella header that imports ModuleName-Swift.h compatibility header, now the problem disappears. It seems like it would be easy to update SPM to add a Copy Headers phase for all Swift targets that have any @objc files.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants