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

Adding SwiftLint Using SPM Includes Extra Packages #5434

Open
faizan-ali-mlk opened this issue Jan 21, 2024 · 8 comments
Open

Adding SwiftLint Using SPM Includes Extra Packages #5434

faizan-ali-mlk opened this issue Jan 21, 2024 · 8 comments
Labels
help integration Issues related to integration of SwiftLint into toolchains.

Comments

@faizan-ali-mlk
Copy link

Hi,

I am trying to add SwiftLint using Swift Package Manager (SPM), but I don't know why it contains extra packages with it. I tested with CocoaPods, but there it is not adding any extra packages. I also tried to install other packages using SPM, like Alamofire, but that also did not add extra packages with it. I searched the issue logs, but I don't think anyone else is experiencing this issue. Please see the screenshots for the issue display.

Swiftlint using package manager

Screenshot 2024-01-21 at 14 41 47 Screenshot 2024-01-21 at 14 42 00

AlamoreFire Using Package manager

Screenshot 2024-01-21 at 14 42 17 Screenshot 2024-01-21 at 14 42 21
@SimplyDanny
Copy link
Collaborator

SimplyDanny commented Jan 21, 2024

Actually, it shouldn't be surprising that Swift packages depend on other packages transitively. However, on macOS, the SwiftLint plugin depends on a compiled binary only. So the sources shouldn't be required. There seems to be a bug in Xcode/Swift Package Manager, though, so that still all dependencies are loaded and compiled.

#5404 appears to fix this. Please have a try with the current main branch and let us know if it works.

@SimplyDanny SimplyDanny added help integration Issues related to integration of SwiftLint into toolchains. labels Jan 21, 2024
@faizan-ali-mlk
Copy link
Author

faizan-ali-mlk commented Jan 21, 2024

Thank you for the quick reply. I tested it by setting the main branch in SPM, but the result is the same.

Screenshot 2024-01-21 at 18 16 41 Screenshot 2024-01-21 at 18 17 54

I am also confused about one more flow. When I add the package, I get this popup.

Screenshot 2024-01-21 at 18 15 28

If I set the target for my app, I encounter the following errors, and my project does not compile. However, it works without selecting the target. I am sharing this information in case you can help me understand why that popup is appearing.

Screenshot 2024-01-21 at 18 16 32

> Note: I am using Xcode 15.2 and Macbook Pro with M1 Chip

@SimplyDanny
Copy link
Collaborator

If I set the target for my app, I encounter the following errors, and my project does not compile.

SwiftLint can also be consumed as a library (e.g. to develop your own version with extensions). It's a normal Swift package that provides three products: the executable, the library and the plugin.

To use the plugin only you must not assign the other products to any of your targets. Otherwise, they will be seen as dependencies that must be compiled for the target platform. But SwiftLint only builds on macOS (and Linux).

I tested it by setting the main branch in SPM, but the result is the same.

Xcode and SPM behave a bit surprising with respect to binary dependencies. All source dependencies are still downloaded and checked out even though they won't be used in later steps. That's why you see all the packages listed in Xcode. Yet, the build should be fast (at least on main), because the binary SwiftLint framework is consumed to actually build/link the plugin.

@faizan-ali-mlk
Copy link
Author

ok @SimplyDanny, so will this issue be resolve or I should switch to Pod, Because i am not liking it that i have not 1 or 2 but almost 8 other libraries which i am not intended to use it.

@SimplyDanny
Copy link
Collaborator

ok @SimplyDanny, so will this issue be resolve or I should switch to Pod, Because i am not liking it that i have not 1 or 2 but almost 8 other libraries which i am not intended to use it.

I don't think we can do anything on the SwiftLint side. This might rather be an issue with SPM or Xcode. If you can reproduce it with a small example, you may open a ticket on their side.

@filiplazov
Copy link

Hello @SimplyDanny, how about providing a binary only repository for the plugin? I think its a pretty common use case that swiftlint is consumed by iOS / Mac developers and they don't necessarily need to import the actual framework.
In our company, the main reason we are using the plugin is for an SDK project (a swift package with many modules) and we don't have build phases to invoke swiftlint. Of course we can wrap the SDK in an app and run the lint from there but its very inneficient as compared to running an individual swift module.
Do you think this is a worthy use case?

@filiplazov
Copy link

What I asked above is for the purposes of avoiding "spilling out" internal Swiftlint dependencies so they are never resolved by the consumer.

@mildm8nnered
Copy link
Collaborator

Xcode and SPM behave a bit surprising with respect to binary dependencies. All source dependencies are still downloaded and checked out even though they won't be used in later steps. That's why you see all the packages listed in Xcode. Yet, the build should be fast (at least on main), because the binary SwiftLint framework is consumed to actually build/link the plugin.

I've been bitten by this before - thinking that this unnecessarily downloaded source was the source for what was executing, when it was not, and I find this SPM behaviour generally quite annoying.

I did try playing around a while ago with making a binary only package, but I don't think I got it to the point where it was working. Because of the limitations of SPM I think it might require a dedicated repo, which is also a pain. I think it would be less confusing for the user though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help integration Issues related to integration of SwiftLint into toolchains.
Projects
None yet
Development

No branches or pull requests

4 participants