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-15718] Swift references with '@objc' in a swift package cannot be exposed in ObjC headers that are visible to swift. Module not found build error. #4362

Open
swift-ci opened this issue Jan 11, 2022 · 1 comment
Labels

Comments

@swift-ci
Copy link
Contributor

@swift-ci swift-ci commented Jan 11, 2022

Previous ID SR-15718
Radar https://feedbackassistant.apple.com/feedback/9841286
Original Reporter matkavalec (JIRA User)
Type Bug

Attachment: Download

Environment

Xcode 13.2.1 (13C100)

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

md5: dd6e44f2a103ab57e0db7c7fc1e7fd52

Issue Description:

There is a bug in swift package manager that makes it nearly impossible to use this package management system in a mixed swift & ObjC codebase. ​It is impossible to expose swift references from a swift package in an ObjC header that is visible to other swift code. Xcode throws a build error that says that the swift module is not found if the module is imported in the ObjC header. If the swift references are forward-declared, they get stripped out.

There are 2 common scenarios where this bug reproduces.

Scenario 1: We have a swift package with 3 targets. Target1 is a swift target that exposes ObjC-compatible references using @objc statements. Target2 is an ObjC target that uses the swift references from Target1. Target2 exposes some of these swift references in its public header files. Target3 is a swift target that imports Target2. Target3 fails to build, Xcode throws a build error saying that the module for Target1 is not found. The build error only happens if Target2 imports Target1 in one of its header files. If Target2 forward declares the references from Target1, those references won't be accessible from Target3. Either way, there is a bug.

Scenario 2: We have a swift package written in swift with ObjC compatibility (@objc). We have an Xcode project with a mixed ObjC-swift build target. Some of the ObjC header files in that target contain references to this swift package. If these header files are added to the ObjC bridging header, the build will fail with the same error that was mentioned in Scenario 1.

Steps using the attached sample project:

  • Open the attached sample project.

  • Open the Package.swift file.

  • Run Xcode builds.

  • Xcode throws this build error: Module 'SwiftTarget' not found.

  • To see another example of this failure, open SwiftObjCSwift.xcodeproj.

  • Go to Xcode->File->Add Packages...->Add Local...

  • In the open panel, select the current directory in which the Package.swift and SwiftObjCSwift.xcodeproj files are found.

  • Go to the Xcode project settings and select the "MixedTarget" build target.

  • In the "Frameworks and Libraries" section, click on "+" and add "SwiftObjCSwift".

  • Build the "MixedTarget" scheme.

  • Xcode throws this build error: Module 'SwiftTarget' not found.

@swift-ci
Copy link
Contributor Author

@swift-ci swift-ci commented Jan 11, 2022

Comment by Mathieu Kavalec (JIRA)

This bug makes it impossible to adopt SPM in many projects that used mixed ObjC-swift. As soon as one of the ObjC headers in the bridging header contains swift types that came from a swift package, this bug happens.

@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

2 participants