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

Improve SwiftPM support #1546

Closed
wants to merge 15 commits into from

Conversation

cntrump
Copy link
Contributor

@cntrump cntrump commented Dec 8, 2021

Changes in this pull request

Improve SwiftPM support:

Build module IGListDiffKit and IGListKit as Objective-C++.

module IGListDiffKit:
- Source/IGListDiffKit
- module defined in Source/IGListDiffKit/modulemap/module.modulemap
- requires -fmodules and -fcxx-modules

module IGListKit:
- depend on IGListDiffKit, use @import IGListDiffKit;
- Source/IGListKit
- module defined in Source/IGListKit/modulemap/module.modulemap
- requires -fmodules and -fcxx-modules

module IGListSwiftKit:
- depend on IGListKit, use import IGListKit
- Source/IGListSwiftKit

Deleted spm/ and scripts/generate_spm_sources_layout.sh, it is unnecessary.

Updated .podspec, add 'OTHER_CFLAGS' => '-fmodules' and 'OTHER_CPLUSPLUSFLAGS' => '-fcxx-modules'.

Add missing swift files for IGListSwiftKit in IGListKit.xcodeproj

How to use

Replace #import <IGListDiffKit/IGListDiffKit.h> with @import IGListDiffKit;, because IGListDiffKit.h isn't exist in modulemap/, Or create a symbol link by ln -sf ../IGListDiffKit.h for support it ?

Examples

Use SwiftPM for building examples.

Checklist

  • All tests pass. Demo project builds and runs.
  • I added tests, an experiment, or detailed why my change isn't tested.
  • I added an entry to the CHANGELOG.md for any breaking changes, enhancements, or bug fixes.
  • I have reviewed the contributing guide

cntrump and others added 9 commits October 16, 2021 00:01
Summary:
I was assuming the delegate would always be an IGListAdapterProxy, but this only happens if the client sets either the `collectionViewDelegate` or `scrollViewDelegate` properties on IGListAdapter. Otherwise the delegate will just be the IGListAdapter. Change the debug code to handle this case.

We were starting to see some debug logs roll in with the delegate class listed as IGListAdapter. Hopefully this will return the correct class now.

Differential Revision: D31690438

fbshipit-source-id: bf6dde57756fee4fe617944d45e152cae734b4f1
Summary:
As title, currently https://instagram.github.io/IGListKit/ is not working.

Let's try to rebuild the doc

Reviewed By: Ziewvater

Differential Revision: D31811862

fbshipit-source-id: 8a0b0ce6c73542da71dddd13c24b5eb9fe9b0506
…agram#1544)

Summary:
Pull Request resolved: Instagram#1544

Refactored and added functions to IGListAdapter for getting index path or scroll position of first visible item in list.

This makes it possible to see which item is the current first visible item scrolled to in the list, and determine how far it is scrolled into (analogous to additionalOffset in scrollToObject:).

Reviewed By: lorixx

Differential Revision: D32196398

fbshipit-source-id: d809d5f96bb4e1d95055dbebe4e55c1a428a40ed
@cntrump cntrump changed the title Pr/improve swiftpm support Improve Swiftpm support Dec 8, 2021
@cntrump cntrump changed the title Improve Swiftpm support Improve SwiftPM support Dec 8, 2021
@cntrump cntrump mentioned this pull request Dec 8, 2021
4 tasks
@lorixx
Copy link
Contributor

lorixx commented Jan 14, 2022

wow, this change is awesome that we removed the need to use spm/ folder and the generation script. I would love to get @3a4oT to take a look as well since he worked on this bigger change before in #1487 At the same time, I can try importing into the repo and see if anything failed.

@facebook-github-bot
Copy link
Contributor

@lorixx has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@TimOliver has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@TimOliver has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@TimOliver merged this pull request in c9e045c.

@TimOliver
Copy link
Member

Hi @cntrump! I'm so sorry for the amount of time it took for us to get back to you on this!

Thanks a lot for the amazing PR! I've been playing with it internally and as a fork on my personal GitHub.

I did have to modify it and roll back some of your changes though. As awesome as being able to configure SPM without having to use symlink references to every file is, it unfortunately didn't work when I tested it without using modular imports. I think this might be related to the fact that SPM is really strict on searching for headers outside of a target's directory, and we're relying on certain IGListDiffKit internal headers to build IGListKit.

Hopefully as SPM improves, we can explore this again in the future. Thanks again!

GreeMoz pushed a commit to appintheair/IGListKit that referenced this pull request Jan 31, 2024
Summary:
This diff imports and refines the PR made by cntrump on GitHub.

The PR introduces the following:

* Sample apps now use SPM instead of CocoaPods to import IGListKit.
* Adds Mac Catalyst as an example target.
* Adds C++ flags to the CocoaPods specs.
* Fixes a script issue that was discovered when regenerating the symlinks.

The PR originally aimed to remove the need for symlinked references to the IGListKit and IGListDiffKit source files, but in testing, I couldn't get it working. It's possible SPM being too strict [on where the headers can be placed to be discovered](https://forums.swift.org/t/how-do-i-specify-the-headers-directory-for-a-objc-target-in-swift-package-managers-package-swift/58531/3).

Additionally, another issue was that the original PR changed all of the `#import` statements to the the modular `import` statements, which is fine for the sample apps, but ended up breaking compatibility for any apps that had modules disabled.

## Changes in this pull request

Improve SwiftPM support:

Build module `IGListDiffKit` and `IGListKit` as Objective-C++.

module `IGListDiffKit`:
    - Source/IGListDiffKit
    - module defined in `Source/IGListDiffKit/modulemap/module.modulemap`
    - requires `-fmodules` and `-fcxx-modules`

module `IGListKit`:
    - depend on `IGListDiffKit`, use `import IGListDiffKit;`
    - Source/IGListKit
    - module defined in `Source/IGListKit/modulemap/module.modulemap`
    - requires `-fmodules` and `-fcxx-modules`

module `IGListSwiftKit`:
    - depend on `IGListKit`, use `import IGListKit`
    - Source/IGListSwiftKit

Deleted `spm/` and `scripts/generate_spm_sources_layout.sh`, it is unnecessary.

Updated `.podspec`, add `'OTHER_CFLAGS' => '-fmodules'` and `'OTHER_CPLUSPLUSFLAGS' => '-fcxx-modules'`.

Add missing swift files for `IGListSwiftKit` in `IGListKit.xcodeproj`

### How to use

Replace `#import <IGListDiffKit/IGListDiffKit.h>` with `import IGListDiffKit;`, because `IGListDiffKit.h` isn't exist in `modulemap/`, Or create a symbol link by `ln -sf ../IGListDiffKit.h` for support it ?

### Examples

Use SwiftPM for building examples.

### Checklist

- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [ ] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)

Pull Request resolved: Instagram#1546

Test Plan: Test PR showing running tests: https://github.com/TimOliver/IGListKit/actions/runs/4339956050/jobs/7578047058

Reviewed By: lorixx

Differential Revision: D33592395

Pulled By: TimOliver

fbshipit-source-id: 8f7b1873f2b1c6a80908bb55b123e31bea13bb0c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants