IGListKit icon indicating copy to clipboard operation
IGListKit copied to clipboard

Swift Package Manager integration already broken (4.0.0), though it's not a pain

Open dreampiggy opened this issue 6 years ago • 12 comments

New issue checklist

  • [x] I have reviewed the README and documentation
  • [x] I have searched existing issues and this is not a duplicate
  • [x] I have attempted to reproduce the issue and include an example project.

General information

  • IGListKit version: 4.0.0
  • iOS version(s): Any
  • CocoaPods/Carthage version: None
  • Xcode version: Xcode 11.2.1
  • Devices/Simulators affected: Any
  • Reproducible in the demo project? (Yes/No): Yes
  • Related issues:

Debug information

# Please include debug logs using the following lldb command:
po [IGListDebugger dump]

Just two screenshots, enough to say the issues...

image

image

dreampiggy avatar Dec 12 '19 15:12 dreampiggy

SPM isn't supported (https://github.com/Instagram/IGListKit/issues/1368).

Any idea when it can be added? @lorixx :)

danqing avatar Dec 14 '19 16:12 danqing

@danqing For SwiftPM on Objective-C, it's a pain because SwiftPM design assume using the raw C style for include public headers, however:

  • Objective-C developer used to use Object.h/Object.m in the same directory, not a standalone include directory for public headers. Tha's a suck for treating Objective-C the same as C.

If you want to supports SwiftPM, you can checkout what SDWebImage do, which have also two Target (one SDWebImage and another SDWebImageMapKit). Which use the custom header search path to achieve this, and also have to hide the Private Headers (I previouslly think facebook guys already solve this problem, but actually not)

dreampiggy avatar Dec 14 '19 18:12 dreampiggy

@dreampiggy I note that SDWebImage use #import ".h" to import its file. And I try that way on IGListKit and write the Package.swift, it works. So Is that what you mean above you said?

Bruce-pac avatar Dec 28 '19 14:12 Bruce-pac

@Bruce-pac Use both

  • Objective-C
@import IGListKit;
  • Swift
import IGListKit

cause the compile error showed in the first screenshot. You can have a check again at 4.0.0 version via SwiftPM.

dreampiggy avatar Dec 29 '19 03:12 dreampiggy

@dreampiggy yeah, a big reason of that is that the Package.swift manifest file is not right. I'm trying rewrite Package.swift file. I note that SDWebImage use #import ".h" to import its file in its other file. such as this:

#import "SDAnimatedImage.h"
#import "NSImage+Compatibility.h"
#import "SDImageCoder.h"
#import "SDImageCodersManager.h"
#import "SDImageFrame.h"
#import "UIImage+MemoryCacheCost.h"
#import "SDImageAssetManager.h"

However, IGListKit use #import <A/B.h> to import its file in its other file. The modified file like:

// swift-tools-version:5.1
import PackageDescription

let package = Package(name: "IGListKit",
                      platforms: [
                          .macOS(.v10_11),
                          .iOS(.v9),
                          .tvOS(.v9)
                      ],
                     products: [
//                          .library(name: "IGListKit", targets: ["IGListKit"]),
                          .library(name: "IGListDiffKit", targets: ["IGListDiffKit"])
                      ],
                     dependencies: [],
                     targets: [.target(name: "IGListDiffKit",
                               dependencies: [],
                               path: nil,
                               sources: nil,
                               publicHeadersPath: "Source/IGListDiffKit/Public",
                               cSettings: [
                               .headerSearchPath("Public"),
                               .headerSearchPath("Internal"),
                             ],
                               linkerSettings: [
                             .linkedLibrary("libc++"),
                             ]
                     ),
//                          .target(name: "IGListKit",
//                                  dependencies: ["IGListDiffKit"],
//                                  path: ".",
//                                  sources: ["Source/IGListKit"],
//                                  publicHeadersPath: "include/IGListKit",
//                                  cSettings: [
//                                    .headerSearchPath("Source/IGListKit"),
//                                    .headerSearchPath("Source/IGListKit/Internal"),
//                                    .headerSearchPath(".")
//                                ],
//                                  linkerSettings: [
//                                  .linkedLibrary("libc++"),
//                                  ]
//                                )
    ],
                     cxxLanguageStandard: .cxx11)

If I modify the import style to #import ".h" , IGListDiffKit can compile success, but the original import style #import <A/B.h> cause the compile error showed in the first screenshot.

So I guess this issue maybe has two solutions, one is like SDWebImage, other is like CocoaLumberjack.

Bruce-pac avatar Dec 29 '19 06:12 Bruce-pac

If you use #import <A/B.h>. You must have public header search path, pointer to A's parent directory. SwiftPM for C/ObjC, only support one public header directory, and does not have module umbrella header like CocoaPods/Carthage (it use a Umbrella Directory, see: https://clang.llvm.org/docs/Modules.html#umbrella-directory-declaration)

For example, move the source code's header, as this strcture

- Source <---- Public Header Directory
-- IGListKit
--- IGListAdapter.h

So the SwiftPM can search this with <IGListKit/IGListAdapter.h>

dreampiggy avatar Dec 29 '19 10:12 dreampiggy

Do you have an ETA on when this is gonna be released? @Bruce-pac @dreampiggy

claudiogomezGL avatar Jul 01 '20 19:07 claudiogomezGL

spm sucks, i stick with cocoapods

jafara avatar Sep 03 '20 04:09 jafara

OMG I had exact issue that @Bruce-pac experienced before: https://github.com/Instagram/IGListKit/issues/1368#issuecomment-696529398 this is what I am trying, maybe we cannot go around the Apple's setting to require "XXX.h" format instead of <Library/XXX>h> format here.

@dreampiggy interesting, I actually tried it out but I am not able to successfully build the project still.

lorixx avatar Sep 22 '20 06:09 lorixx

I'm not the maintainer of IGListKit. I'm the maintainer of SDWebImge.

You can try to see how we use symbol link the header to keep the same import syntax of #import <SDWebImage/SDWebImage.h> across all these Package Managers:

  • CocoaPods (including static library/framework, use modular headers, 3 types)
  • Carthage (prebuilt binary framework)
  • SwiftPM

https://github.com/SDWebImage/SDWebImage/pull/2987

Though I think these massive crazy Package Managers (first Carthage) may disappear after some years of adopting SwiftPM.

dreampiggy avatar Sep 22 '20 07:09 dreampiggy

Some work in progress #1465

3a4oT avatar Oct 09 '20 12:10 3a4oT

any updates on this?

BrentMifsud avatar Aug 11 '21 17:08 BrentMifsud