SwiftLint: Cannot add SwiftLint as package for Xcode plugin

New Issue Checklist

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 version to 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)

Most upvoted comments

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 .buildCommand to .prebuildCommand for 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:

  • You have to point to a commit or branch to use it due to these SPM “stability” requirements. If you don’t like the stability requirements, file a bug with SPM, but there’s nothing SwiftLint can do about them.
  • This means developers cannot use it on libraries/frameworks which are brought in by other applications, only directly on the applications themselves, and you should use whatever you were using before if you’re using it for a lib.

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 error Entry point (_main) undefined. for architecture arm64 (

I’m able to add it to the project by pointing to main or 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:

Entry point (_main) undefined. for architecture arm64

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: Screen Shot 2022-12-12 at 9 52 55 PM

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.50 is greater than 0.9. You have to manually set it to 0.50.3.

@jpsim This is what I see when I tried to add it: image

Not tried anything more than just add the SwiftLint package dependency and it failed with the above error.