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

lib_InternalSwiftSyntaxParser.dylib linking issue with Homebrew #108

Closed
tinder-maxwellelliott opened this issue Apr 21, 2020 · 22 comments
Closed

Comments

@tinder-maxwellelliott
Copy link
Contributor

I am having this issue with some laptops using Mockolo when running the homebrew version:

dyld: Library not loaded: @rpath/lib_InternalSwiftSyntaxParser.dylib
  Referenced from: /usr/local/bin/mockolo
  Reason: image not found

Strangely enough some laptops run this command totally fine, other break

@elsh
Copy link
Contributor

elsh commented Apr 22, 2020

Is the dylib in the same dir as the mockolo executable? If it's in a different location, it will throw the above error. Also, can you check what xcode versions are installed in the laptops that work and don't work? It shouldn't matter as the dylib is a compile time dependency, but would be good to narrow down what the differences are.

@tinder-maxwellelliott
Copy link
Contributor Author

tinder-maxwellelliott commented Apr 23, 2020 via email

@elsh
Copy link
Contributor

elsh commented Apr 23, 2020

I've attached two binaries to the release, mockolo.tar.gz built with swift 5.2 (xcode 11.4+), and mockolo-swift5.1.tar.gz built with swift 5.1 (< xcode 11.3). Can you try both and see if either one fails? thanks.

@tinder-maxwellelliott
Copy link
Contributor Author

The thing is that in Homebrew we just compile without linking to a dylib

  def install
    system "swift", "build", "-c", "release", "--disable-sandbox"
    bin.install ".build/release/mockolo"
  end

@elsh
Copy link
Contributor

elsh commented Apr 24, 2020

Looks like there's a compatibility issue between Xcode 11.4+ and 11.3- similar to realm/SwiftLint#3105. What happens if you set the depends_on :xcode version to 11.4? If that doesn't work, we might have to dynamically load it, like https://github.com/jpsim/SourceKitten/blob/master/Source/SourceKittenFramework/library_wrapper.swift.

@tinder-maxwellelliott
Copy link
Contributor Author

We can have the brew formula rely on sourcekitten from brew itself, does this solve our issue?

@elsh
Copy link
Contributor

elsh commented Apr 24, 2020 via email

@tinder-maxwellelliott
Copy link
Contributor Author

Sourcekitten can be installed via Brew

brew install sourcekitten

Can we somehow consume that binary?

@elsh
Copy link
Contributor

elsh commented Apr 24, 2020

The error is not related to sourcekitten. It's due to swiftsyntax between the xcode versions. If we set the 'depends_on xcode' version to 11.4, this error might be resolved.

@tinder-maxwellelliott
Copy link
Contributor Author

Could this approach work?

swift build --configuration release -Xlinker -weak-l_InternalSwiftSyntaxParser

@elsh
Copy link
Contributor

elsh commented Apr 25, 2020

I don't think it resolves it, as @rpath to the internal dylib still shows up if you run otool -L mockolo.
Could you try setting the version to 11.4 and see if it fixes the error? If not, either we'll have to dynamically load the dylib or see if we can use lines 72-74 from install-script.sh (mockolo) in homebrew: def install.

@tinder-maxwellelliott
Copy link
Contributor Author

Can we make another shell script that homebrew can run to do these 2 commands?

cp "$(xcode-select -p)"/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/lib_InternalSwiftSyntaxParser.dylib . 

install_name_tool -change @rpath/lib_InternalSwiftSyntaxParser.dylib @executable_path/lib_InternalSwiftSyntaxParser.dylib "$TARGET"

@elsh
Copy link
Contributor

elsh commented May 4, 2020

It will require tarballing both the mockolo executable and the dylib to run the executable. Does homebrew allow that? Also, did you happen to see if requiring Xcode 11.4 fixes the error?

@elsh
Copy link
Contributor

elsh commented Jun 5, 2020

Revisiting this; @tinder-maxwellelliott if you set the xcode version to 11.4 (now that mockolo requires 11.4+), does this error still repro?

@tinder-maxwellelliott
Copy link
Contributor Author

This has gone away! Thanks!

@tinder-maxwellelliott
Copy link
Contributor Author

tinder-maxwellelliott commented Jul 20, 2020

For people still guided here by the Google Search Gods this is the solution:

  1. Run xcode-select -p, see your current Xcode path
  2. Update the name of your current Xcode application to Xcode.app, often this name can contain numbers or other characters that cause issues. Copy this new path.
  3. Run xcode-select -s YOUR_NEW_RENAMED_XCODE_APP_PATH
  4. Mockolo will work as expected

@tinder-maxwellelliott
Copy link
Contributor Author

@elsh Is there no possible way to avoid a Dylib here at all? Can we make a static framework and avoid this all together?

@elsh
Copy link
Contributor

elsh commented Jul 20, 2020 via email

@tinder-maxwellelliott
Copy link
Contributor Author

Static? no it required building too many pieces in swift repo the last time tried. We can try dlopen. What's the main issue anyway?

On Mon, Jul 20, 2020 at 2:45 PM Maxwell Elliott @.***> wrote: @elsh https://github.com/elsh Is there no possible way to avoid a Dylib here at all? Can we make a static framework and avoid this all together? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#108 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUG5PF3CJDMGQ3P6QYGH5DR4S3GBANCNFSM4MNWJXCA .

People keep getting into issues where Xcode is not where Mockolo expects it to be

@elsh
Copy link
Contributor

elsh commented Sep 1, 2020 via email

@elsh
Copy link
Contributor

elsh commented Nov 19, 2020

Closing. Feel free to reopen if this issue arises agin.

@n-belokopytov
Copy link

The issues is back, this time on Homebrew itself - it blocks the release of Mockolo 1.8.0.
https://github.com/Homebrew/homebrew-core/actions/runs/3349028971/jobs/5548712516

I've also opened a new issue for this, since I feel like this can be fixed on the build configuration level: #206

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants