Skip to content

Conversation

0x0c
Copy link

@0x0c 0x0c commented May 20, 2019

Hi, I added @import UIKit; at UIImage+WebP.h to fix the issue that I mentioned at this PR's title.

The issue can be reproduced using a Podfile with use_modular_headers!, to link this library as a static library, as follows:

/<Your Project>/Pods/Headers/Public/SDWebImageWebPCoder/UIImage+WebP.h:12:12: Declaration of 'UIImage' must be imported from module 'UIKit.UIDocumentBrowserAction' before it is required 

and

/<Your Project>/Pods/Headers/Public/SDWebImageWebPCoder/UIImage+WebP.h:12:12: Definition of 'UIImage' must be imported from module 'UIKit.UIImage' before it is required 
@kinarobin
Copy link
Member

@0x0c What Xcode version with you computer? I test in Xcode 10.2.1, And it's OK.

@0x0c
Copy link
Author

0x0c commented May 20, 2019

@kinarob I'm using Xcode 10.2.1 and CocoaPods 1.6.3.

First, I apologize my wrong report; I found another reason for the issue that I cannot compile my project when using use_modular_headers!, so please forget my report at the first of this PR.

By the way, I got errors when using use_modular_headers! as shown in an attached image and it may cause of header fragility of #import directive.
(Header Fragility is mentioned by Doug Gregor who is a one of a developer of LLVM http://llvm.org/devmtg/2012-11/Gregor-Modules.pdf)
image
(The commit e51a218 resolves errors that are first and second one from bottom of the image.)
To resolve these errors, I use @import instead of #import.

I edit an example project of this repo and my changes has no effect for build when using use_framework! and use_modular_headers! in Podfile.
Of course, it works without these keywords(use_framework! and use_modular_headers!).

@kinarobin
Copy link
Member

kinarobin commented May 21, 2019

From the error, Can you upload a demo? Thus, We can find out the issue from your usage. Thanks!

@0x0c
Copy link
Author

0x0c commented May 22, 2019

@kinarob OK, please wait a moment.

@ledyba
Copy link

ledyba commented May 29, 2019

@kinarob Hi, I can reproduce this compile error.

Could you take a look at this demo repository?:
https://github.com/ledyba/SDWebImageWebPCoderTest

Screen Shot 2019-05-29 at 14 41 47

@kinarobin
Copy link
Member

@ledyba OK, I'll check this immediately.

@ledyba
Copy link

ledyba commented May 29, 2019

@kinarob Thank you!

@dreampiggy
Copy link
Contributor

dreampiggy commented May 29, 2019

@ledyba This @import SDWebImage only works for the integrate project, which Enable the Clang Module. For CocoaPods, it's the use_frameworks! or use_modular_headers!.

This will break the user who still using the Static Library + Headers.

Instead, I suggest to just change to using #import <SDWebImage/SDWebImge.h>. This is compatible for both of 3 cases. Clang will lookup this SDWebImage.h as a module import as @import SDWebImage, because we mark SDWebImage.h as umbrella headers. See SDWebImage.modulemap

* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this line into #import <SDWebImage/SDWebImage.h> to works for Static Library user.

*/

#import <SDWebImage/SDWebImageCompat.h>
@import SDWebImage;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same

@dreampiggy
Copy link
Contributor

Seems a bug because of CocoaPods: CocoaPods/CocoaPods#7598 (comment)

Even I change this into modular import, I found that all the private headers are marked as public when using use_modular_headers!. This need CocoaPods to fix.

@dreampiggy
Copy link
Contributor

@ledyba Seems you're too busy to reply. To solve the users who still face the problem. I'll merge this right now and do changes. Thanks for your contribution !

@dreampiggy dreampiggy merged commit 299d1d7 into SDWebImage:master Jun 2, 2019
@0x0c
Copy link
Author

0x0c commented Jun 2, 2019

@dreampiggy Hi, I’m working with @ledyba at same company and this issue is caused in our proprietary project so I apologize that could not share detail, and thank to merge our PR.
I upload repos that reproduce this issue.
If you interested in this problem, check these.

This repo is able to compile: https://github.com/0x0c/SDWebImageWebPCoderTest
This repo is not able to compile: https://github.com/ledyba/SDWebImageWebPCoderTest

Difference is only using @import or #import (plz see Podfile.)

@dreampiggy
Copy link
Contributor

@0x0c OK...It can now suceesfuly build. My review of your PR is about to change @import ModuleName to #import <ModuleName/umbrella_headers>. This works the same if you enable clang module.

But if you disable clang module (There are a little project who still use as this, they have their reasons), the @import cause a compiler error. We just support both of them.

See the screenshot.

image

Note: The warning is CocoaPods's bug, need them to fix via CocoaPods 1.8.0 or later.

@dreampiggy
Copy link
Contributor

The bug of CocoaPods issue change to: CocoaPods/CocoaPods#8879

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4 participants