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-7051] Compiler fails with "Module not found" error #49599

Open
iby opened this issue Feb 21, 2018 · 8 comments
Open

[SR-7051] Compiler fails with "Module not found" error #49599

iby opened this issue Feb 21, 2018 · 8 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself PrintAsClang Area → compiler: The PrintAsClang library

Comments

@iby
Copy link

iby commented Feb 21, 2018

Previous ID SR-7051
Radar rdar://problem/67420748
Original Reporter @iby
Type Bug

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, PrintAsObjC
Assignee None
Priority Medium

md5: b810dd94930798e2172c09555d671956

is duplicated by:

  • SR-13482 Generated Obj-C header imports framework if any extension exists even if nonobjc

relates to:

  • SR-2772 Objective-C compatibility header exposes private extensions outside its module.

Issue Description:

Trying to make it make it as simple as possible, but still sounds a little complicated. Consider:

1. Project with macOS app (App) and static Swift lib (Lib) that it depends upon.
2. App target has a bridging header and some Obj-C code.
3. Static lib has Foo class inheriting from NSObject and Bar class (plain Swift).
4. When attempting to create an extension for Foo the build fails saying that `module 'Lib' not found`.
5. When attempting to create an extension for Bar the build succeeds.

It appears that compiler recognises that Foo has NSObject in parent hierarchy and automatically adds `@import Lib` into `App-Swift.h`. Is this expected? How do deal with it? Project attached.

Update 2019.01.18:

So glad I've filed this! Saved myself a lot of time figuring out what went wrong… The cases when the extension is not empty also fails, apparently it only doesn't like intermediate classes, e.g., Foo, extending Bar seems okay:

extension Foo {
    var name: String { return "Me is foo" }
}
@belkadan
Copy link
Contributor

The revenge of SR-2772! I guess we need to check if an extension is "empty" even earlier, so that we don't think we need to emit imports for it.

@iby
Copy link
Author

iby commented Feb 22, 2018

Hey. The point here is not that it's empty – I just didn't include more details than necessary. The point is that it fails. Why? I don't mark it or any contents as @objc, I don't want it to be imported into App-Swift.h. But even if it gets in there, why doesn't it work? If I would want to do @import Lib in Objective-C – it doesn't work when done manually. Very confused… ☹️

@belkadan
Copy link
Contributor

It's only including the import in the generated header because of the extension. If the extension were absent, it wouldn't include the import, and if the extension had stuff in it, you'd need it.

The actual import doesn't work because static libraries don't have C modules or headers by default. You can make it work, but Xcode doesn't help you do it today. That's not a Swift issue, though.

@iby
Copy link
Author

iby commented Feb 22, 2018

Ok, cool. Understanding that this isn't a Swift problem, can you shed some light on how to make it work or point in the right direction? Tried enabling modules, adding headers, bridging header and a few other tricks without any luck.

@swift-ci
Copy link
Collaborator

Comment by Scott Talbot (JIRA)

I also encountered this and, in case others get to here with the same problem, the advice in this blog post helped me:
https://paul-samuels.com/blog/2018/01/14/swift-static-library-in-objective-c/

The gist is that you have to copy the `<product>-Swift.h` header to a place in the built products directory and create a module map that references it.

@iby
Copy link
Author

iby commented Aug 23, 2018

cysp (JIRA User) great point![]( I used Paul's approach before, won't be surprised if on related issue… :D Thanks for the reference)

@swift-ci
Copy link
Collaborator

Comment by Pawel Szot (JIRA)

I encountered this while experimenting with internal module maps. Even making extension private will not help.

@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself PrintAsClang Area → compiler: The PrintAsClang library
Projects
None yet
Development

No branches or pull requests

4 participants