LLVMSwift icon indicating copy to clipboard operation
LLVMSwift copied to clipboard

LLVMSwift as package dependency in Xcode

Open qmathe opened this issue 4 years ago • 18 comments

I have a Xcode 12.2 project where I would like to use LLVMSwift. I installed LLVM 9 with brew and followed Installation instructions. I then added LLVMSwift to my project with File > Swift Packages > Add Package Dependency…. The dependency references the latest commit on master.

When I compile my target, I get the following error: LLVMSwift/Sources/llvmshims/src/shim.cpp:1:10: fatal error: 'llvm-c/Core.h' file not found.

From what I see in the output, flags defined in pkgconfig/cllvm.pc are missing. It's my first time using Swift Package Manager and I don't know how it interacts with pkg-config. Here is how cllvm.pc was generated:

$ swift [snip]/SourcePackages/checkouts/LLVMSwift/utils/make-pkgconfig.swift 
Running /usr/bin/which llvm-config-9...
Running /usr/bin/which llvm-config...
Found llvm-config at /usr/local/opt/llvm@9/bin/llvm-config...
Running /usr/local/opt/llvm@9/bin/llvm-config --version...
LLVM version is 9.0.1
Running /usr/local/opt/llvm@9/bin/llvm-config --ldflags --libs all --system-libs...
Running /usr/local/opt/llvm@9/bin/llvm-config --cflags...
Writing pkg-config file to /usr/local/lib/pkgconfig/cllvm.pc...

Successfully wrote pkg-config file!

qmathe avatar Dec 31 '20 11:12 qmathe

Hi @qmathe,

Try adding the dependency using "Up to Next Minor" with version 0.7. The latest commit on master is part of what will eventually become 0.8 and requires LLVM 11 rather than 9.

matthewseaman avatar Feb 18 '21 19:02 matthewseaman

I'm getting a similar error with LLVMSwift 0.8 when building with Xcode:

'llvm-c/Analysis.h' file not found

I have LLVM 11 installed with homebrew, and pkg-config script did succeed.

MaxDesiatov avatar Aug 09 '21 14:08 MaxDesiatov

Make sure the llvm files installed by brew are in your PATH. Then rerun the pkg-config. Also see #235.

matthewseaman avatar Aug 10 '21 03:08 matthewseaman

I do have export PATH="/opt/homebrew/opt/llvm@11/bin:$PATH" in my .zshrc, but that doesn't seem to have any effect on Xcode. Is there anything else that needs to be done to make Xcode aware of this LLVM installation?

MaxDesiatov avatar Aug 10 '21 08:08 MaxDesiatov

Same problem for me. Any suggestions @matthewseaman?

Screenshot 2022-01-21 at 16 37 18

henkvanderspek avatar Jan 21 '22 15:01 henkvanderspek

Somehow rerunning swift utils/make-pkgconfig.swift did help in my case after all.

MaxDesiatov avatar Jan 21 '22 15:01 MaxDesiatov

Still same problem. I must be doing something different.

Screenshot 2022-01-21 at 16 59 09 Screenshot 2022-01-21 at 16 59 28

henkvanderspek avatar Jan 21 '22 16:01 henkvanderspek

Do i need to use LLVM 11 instead?

henkvanderspek avatar Jan 21 '22 16:01 henkvanderspek

Also check that you don't have two version of LLVM installed at the same time, I guess some of my issues could've been cause by having llvm@12 and llvm@13 installed by Homebrew at the same time. Also, you have to run make-pkgconfig.swift every time after Homebrew installs or remove any of these packages, I think. I'm still not 100% sure what exactly worked in my case, but at one point I reran the script and Xcode builds started working again.

MaxDesiatov avatar Jan 21 '22 16:01 MaxDesiatov

master branch and 0.8.0 release need LLVM 11, while https://github.com/llvm-swift/LLVMSwift/pull/238 somewhat works with LLVM 13, but with disabled JIT.

MaxDesiatov avatar Jan 21 '22 16:01 MaxDesiatov

Ok thanks, Max. I didn't have LLVM installed before using this package. It's a new machine and didn't even had Homebrew on it 😄

henkvanderspek avatar Jan 21 '22 16:01 henkvanderspek

As far as I understand make-pkgconfig.swift relies on Homebrew installations, but I could be wrong.

MaxDesiatov avatar Jan 21 '22 16:01 MaxDesiatov

Ok, I need JIT. So I better use LLVM 11 then, remove 13 to make sure.

henkvanderspek avatar Jan 21 '22 16:01 henkvanderspek

As far as I understand make-pkgconfig.swift relies on Homebrew installations, but I could be wrong.

Yes, I see it uses brew. Script runs fine though. But it must be because I installed LLVM 13 instead. Still weird it complains about missing headers and doesn't even pass compilation.

henkvanderspek avatar Jan 21 '22 16:01 henkvanderspek

Good way to diagnose could be by using swift build. If swift build works, but building from Xcode doesn't, then it's the same issue I had 🙂

MaxDesiatov avatar Jan 21 '22 16:01 MaxDesiatov

Running /opt/homebrew/bin/brew --prefix...
Running /usr/bin/which llvm-config-11...
Running /usr/bin/which llvm-config...
Found llvm-config at /opt/homebrew/opt/llvm@11/bin/llvm-config...
Running /opt/homebrew/opt/llvm@11/bin/llvm-config --version...
LLVM version is 11.1.0
Running /opt/homebrew/opt/llvm@11/bin/llvm-config --ldflags --libs all --system-libs...
Running /opt/homebrew/opt/llvm@11/bin/llvm-config --cflags...
Writing pkg-config file to /opt/homebrew/lib/pkgconfig/cllvm.pc...

Successfully wrote pkg-config file!
Make sure to re-run this script when you update LLVM.
henk@Henks-MacBook-Pro LLVMSwift % swift build                     
warning: failed to retrieve search paths with pkg-config; maybe pkg-config is not installed
warning: you may be able to install cllvm using your system-packager:
    brew install llvm

/Users/henk/Library/Developer/Xcode/DerivedData/8-Bit_OS-eprcdyqouebnfjaxybvmskdpufrh/SourcePackages/checkouts/LLVMSwift/Sources/llvmshims/src/shim.cpp:1:10: fatal error: 'llvm-c/Core.h' file not found
#include "llvm-c/Core.h"
         ^~~~~~~~~~~~~~~
1 error generated.
[0/1] Compiling shim.cpp```

henkvanderspek avatar Jan 21 '22 16:01 henkvanderspek

It does give more info. But still strange.

henkvanderspek avatar Jan 21 '22 16:01 henkvanderspek

Oh wait. It said so to install pkg-config. That was it! Thanks for the help, Max!

henkvanderspek avatar Jan 21 '22 16:01 henkvanderspek