yonaskolb / Mint

A package manager that installs and runs executable Swift packages
MIT License
2.29k stars 123 forks source link

dyld: Library not loaded: libSwiftSyntax.dylib #120

Closed Jeehut closed 5 years ago

Jeehut commented 5 years ago

Currently I'm working on a new version of BartyCrouch and I'd like to release a first beta soon. But before doing that I need to test the tool, including it's installation process. I first tried swift build -c release to make sure everything works and it does. It produces a command line tool at the relative path ./.build/release/bartycrouch.

But when I try to install the same commit using Mint by running

mint install Flinesoft/BartyCrouch@work/big-refactoring

Then I get no installation errors and on re-run I get

🌱  BartyCrouch work/big-refactoring already installed
🌱  Linked bartycrouch work/big-refactoring to /usr/local/bin, replacing version big-refactoring

so everything seems to be fine. But when I try to use the command line tool (e.g. by simply running bartycrouch) I get this error:

dyld: Library not loaded: /private/var/folders/q_/_12345somePath6789/T/mint/github.com_Flinesoft_BartyCrouch/.build/x86_64-apple-macosx10.10/release/libSwiftSyntax.dylib
  Referenced from: /usr/local/bin/bartycrouch
  Reason: image not found
Abort trap: 6

Note that I'm including the [SwiftSyntax]() library from Apple exactly like documented in their README with this entry:

.package(url: "https://github.com/apple/swift-syntax.git", .exact("0.40200.0"))

It seems this is failing somehow, my first guess was that it has something to do with relative vs. absolute paths and that the directory of the bartycrouch executable is the issue. Actually when I replace my local ./.build/release/bartycrouch command with the executable installed by Mint from /usr/local/bin/bartycrouch it still fails though. When I copy the file built with swift build -c release locally to the /usr/loca/bin/bartycrouch path though, it works the other way around. So I'm not sure if that's the issue.

Any ideas what might be the issue and how to fix it? I'd like to make Mint the recommended installation option, but it doesn't seem to work right now ...

Jeehut commented 5 years ago

I just found that Mattt already covered the reason why this isn't working in his great post about how to install SwiftPM tools via Homebrew where he also has an example which is dependent on SwiftSyntax:

The install command copies the executable to /usr/local/bin, but because swift-syntax-highlighter links to libSwiftSyntax.dylib, we need to install that to /usr/local/lib and use the install_name_tool command to modify the executable and update its path to the dynamic library. If your project only links to system dynamic libraries (like @rpath/libswiftCore.dylib) then you won’t have to do any of this.

Maybe this helps to fix this more quickly?

Jeehut commented 5 years ago

Seems like the issue was the directory the build was run from. I updated my Makefile contents to the non-simplified version on NSHipster (this time properly, last time I seem to have had cached data) and it works now.

Jeehut commented 5 years ago

Okay, it actually only worked in some of my tests during development, but doesn't seem to work for the released version. Opening this again ...

Jeehut commented 5 years ago

This should not be an issue any more, now that Swift 5 already includes SwiftSyntax.