SwiftLint: Cannot add SwiftLint as package for Xcode plugin
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
Describe the bug
I am trying to add SwiftLint as package dependency to run it as a build plugin. It fails resolution with invalid manifest.
Environment
-
SwiftLint version (run
swiftlint versionto be sure)? Trying to pull latest -
Installation method used (Homebrew, CocoaPods, building from source, etc)? SPM
-
Which Xcode version are you using (check
xcodebuild -version)?
Build version 14B47b```
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 34 (6 by maintainers)
I’m not interested in maintaining this plugin. It’s nothing but a headache for me so far. I might remove it from the next release and folks can provide their own SwiftLint plugins if they want to deal with these issues. cc @technocidal
I have the same issue. I have cleared the package cache and told Xcode to fetch the exact version
0.50.3. And I get the same error message:Failed to resolve dependencies Dependencies could not be resolved because package ‘swiftlint’ is required using a stable-version but ‘swiftlint’ depends on an unstable-version package ‘swift-syntax’ and root depends on ‘swiftlint’ 0.50.3.
The same is true for version
0.50.1.Failed to resolve dependencies Dependencies could not be resolved because package ‘swiftlint’ is required using a stable-version but ‘swiftlint’ depends on an unstable-version package ‘swift-syntax’ and root depends on ‘swiftlint’ 0.50.1.
I also did this in a fresh project. I use Xcode build version: 14B47b
Checking on the status of this. @evfemist branch and pr seems to fix the Xcode build plugin issue when pointing to a specific commit or branch and it would be great if that could make it into the main branch.
It’s because the Package.swift targets a specific revision for swift-syntax here which is forbidden by swift package. It requires to be updated and point to a tag. Looks like swift-syntax 0.50800.0 is in pre-release. When final tag will be released it’s will work. It’s what “unstable version” in the error message reports.
@jpsim Please don’t remove the plugin, it’s nice having done it. swift-syntax pre-release is 8hours ago you’ll have a fix soon I guess.
@shnmxvi This might be related to #4628 and it seems to be a bug in Xcode.
@evfemist workaround has been merged and is available in the latest release candidate.
Any updates?
@evfemist Looks like this hasn’t been merged yet… merge conflict? Would be great to use your fix. Your fork works great.
Yeah, looks like. And even if modify plugin to define class with @main in it - then iOS app will not launch, think because of two entry points. But I have found a temporary workaround by changing
.buildCommandto.prebuildCommandfor XcodeProjectPlugin. You can check my commit here Also there I write a crunch to hide warning “no rule to process file …” that appears on Xcode 14.2.I can imagine this is getting a little maddening. I think it’s probably worth supporting with the following caveats in the
README:I think that at least gives people using it directly on Applications the ability to use it, but keeps you from having to deal with all this nonsense.
@technocidal hm, when i use
.package(url: "https://github.com/apple/swift-syntax", from: "0.50800.0-SNAPSHOT-2022-12-20-a").i have errorEntry point (_main) undefined. for architecture arm64(I’m able to add it to the project by pointing to
mainor to a commit. When I do this, after adding the Run Build Tool Plug-ins phase, SwiftLint does work and reports code violations as expected. However the build fails at the linking phase with this message:I haven’t been able to make sense why adding the plugin affects the linker.
For what it’s worth I’m also seeing this if I’ve set the version to 0.50.3 / up to next minor:
Update: I think it’s because the Package.swift file’s dependencies are still pointed at a specific commit instead of a tag, which is causing the whole thing to fail at the point of package resolution, even though SwiftLint is being included as a binary in the plugin.
SPM doesn’t even get to the point of analysis where it goes “Oh that’s a binary”, it’s just looking at the graph and refusing to proceed once it sees a commit hash rather than a tag.
I saw this a bunch of times at Apollo: There’s a bug with 0.x versions where SPM doesn’t understand that
0.50is greater than0.9. You have to manually set it to 0.50.3.@jpsim This is what I see when I tried to add it:
Not tried anything more than just add the
SwiftLintpackage dependency and it failed with the above error.