SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Swiftlint 0.39 library not loaded

Open Oliver-Kirkland-Evoke opened this issue 6 years ago • 31 comments

New Issue Checklist

Describe the bug

swiftlint always crashes after updating to version 0.39 via Homebrew. We've tried this on 3 systems and seen the same issue.

We have tried installing "Swift 5 Runtime Support for Command Line Tools" as per the known issues but the systems are too new to allow this to be installed.

We have downgraded to 0.38.2 which is working fine.

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint
dyld: Library not loaded: @rpath/lib_InternalSwiftSyntaxParser.dylib
  Referenced from: /usr/local/bin/swiftlint
  Reason: image not found
Abort trap: 6

Environment

  • SwiftLint version: 0.39

  • macOS versions: 10.15.3 && 10.14.6

  • Installation method used: Homebrew

  • Are you using nested configurations? If so, paste their relative paths and respective contents.

  • Which Xcode version are you using: 11.3

  • Do you have a sample that shows the issue? Run `swiftlint"

Oliver-Kirkland-Evoke avatar Feb 11 '20 13:02 Oliver-Kirkland-Evoke

@Oliver-Kirkland-Evoke does it work if you try brew reinstall --build-from-source swiftlint?

marcelofabri avatar Feb 11 '20 16:02 marcelofabri

Same issue, Installation method used: Cocoapods

Doxxer avatar Feb 11 '20 16:02 Doxxer

Same issue, Installation method used: Cocoapods

Can you post my details about your environment? I can image why using homebrew wouldn't work, but using CP should work fine 🤔

marcelofabri avatar Feb 11 '20 16:02 marcelofabri

We have the same problem. Integration is also via Cocoapods, Xcode 11.3.1.

PatrickGaissert avatar Feb 11 '20 16:02 PatrickGaissert

OK, so looks like the issue is that the binary is somehow hardcoding the path to the Xcode path from the machine that created the binary:

$ DYLD_PRINT_RPATHS=1 swiftlint help
RPATH failed expanding     @rpath/lib_InternalSwiftSyntaxParser.dylib to: /usr/lib/swift/lib_InternalSwiftSyntaxParser.dylib
RPATH failed expanding     @rpath/lib_InternalSwiftSyntaxParser.dylib to: /Applications/Xcode-11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/lib_InternalSwiftSyntaxParser.dylib
dyld: Library not loaded: @rpath/lib_InternalSwiftSyntaxParser.dylib
  Referenced from: /usr/local/bin/swiftlint

I'm not sure how to fix that and won't have time to look into this until later, so I recommend using 0.38.2 for now.

marcelofabri avatar Feb 11 '20 17:02 marcelofabri

@nathawes do you have any ideas on how to fix this? Ideally we'd statically link lib_InternalSwiftSyntaxParser, but maybe that's not possible?

marcelofabri avatar Feb 11 '20 17:02 marcelofabri

This update broke our CI build system. Currently it's pulling always the last version. I'm testing a fix by copying the latest Xcode and renaming it to: Xcode-11.3.1.app

RicardoKoch avatar Feb 11 '20 17:02 RicardoKoch

FYI We use autoupdate with HomeBrew to keep our development systems and CI system using the same version of SwiftLint and other tools. If using HomeBrew I recommend using:

brew uninstall swiftlint
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/203436f8567a3b6455264a1d896da5b1df1e50e6/Formula/swiftlint.rb
brew pin swiftlint

This will keep SwiftLint at version 0.38.2 until brew unpin swiftlint is run.

Oliver-Kirkland-Evoke avatar Feb 11 '20 18:02 Oliver-Kirkland-Evoke

My team is also experiencing this problem on Xcode 11.3.1. We're installing it with CocoaPods as well

rfree18 avatar Feb 11 '20 18:02 rfree18

My team as well experiencing this problem on Xcode 11.3.1. We're installing it via CocoaPods.

serges147 avatar Feb 11 '20 18:02 serges147

@nathawes do you have any ideas on how to fix this? Ideally we'd statically link lib_InternalSwiftSyntaxParser, but maybe that's not possible?

@akyrtzi what's the right thing to do here?

nathawes avatar Feb 11 '20 18:02 nathawes

I was able to temporarily fix this issue by renaming Xcode.app to Xcode-11.3.1.app (inside Applications).

RicardoKoch avatar Feb 11 '20 18:02 RicardoKoch

This broke my team's CI build. We resolved the issue for the time being by locking our Swiftlint version to 0.38.2 in our podfile.

leifktaylor avatar Feb 11 '20 18:02 leifktaylor

brew reinstall --build-from-source swiftlint built a copy of 0.39 for me that works properly, so that's a workaround.

bskendig avatar Feb 11 '20 18:02 bskendig

Ideally we'd statically link lib_InternalSwiftSyntaxParser, but maybe that's not possible?

Unfortunately not possible. In order to get a tool that is portable (working on a different machine than it was built with) you need to copy lib_InternalSwiftSyntaxParser.dylib and have it alongside the tool. And the tool's rpaths should be able to find it relative to itself.

akyrtzi avatar Feb 11 '20 18:02 akyrtzi

Ideally we'd statically link lib_InternalSwiftSyntaxParser, but maybe that's not possible?

Unfortunately not possible. In order to get a tool that is portable (working on a different machine than it was built with) you need to copy lib_InternalSwiftSyntaxParser.dylib and have it alongside the tool. And the tool's rpaths should be able to find it relative to itself.

Thanks! I'll look into that later 🙌

marcelofabri avatar Feb 11 '20 18:02 marcelofabri

@marcelofabri SourceKitten grabs clang and sourcekit dylibs dynamically here: https://github.com/jpsim/SourceKitten/blob/master/Source/SourceKittenFramework/library_wrapper.swift

We should do the same with lib_InternalSwiftSyntaxParser.dylib.

jpsim avatar Feb 11 '20 20:02 jpsim

@marcelofabri can we revert the SwiftSyntax inclusions in 0.39.0 and cut a 0.39.1 release to unblock folks who want to be on the latest bleeding edge SwiftLint version?

jpsim avatar Feb 11 '20 20:02 jpsim

@marcelofabri can we revert the SwiftSyntax inclusions in 0.39.0 and cut a 0.39.1 release to unblock folks who want to be on the latest bleeding edge SwiftLint version?

I was planning to look into fixing the issue in the evening, but if you (or any other contributor) have the time before that, feel free to revert the changes and cut a release.

marcelofabri avatar Feb 11 '20 20:02 marcelofabri

ok, I'll revert & cut a new release.

IMO we should avoid copying lib_InternalSwiftSyntaxParser.dylib and vending it with SwiftLint. We've been able to avoid doing that for SourceKit & libclang and we should be able to avoid it for SwiftSyntax too.

jpsim avatar Feb 11 '20 20:02 jpsim