You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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
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.
The text was updated successfully, but these errors were encountered:
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.
Attachment: Download
Environment
Xcode 13.2.1 (13C100)
Additional Detail from JIRA
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.
The text was updated successfully, but these errors were encountered: