-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
| 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.