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

LLVMSwift as package dependency in Xcode #221

Open
qmathe opened this issue Dec 31, 2020 · 18 comments
Open

LLVMSwift as package dependency in Xcode #221

qmathe opened this issue Dec 31, 2020 · 18 comments

Comments

@qmathe
Copy link

qmathe commented Dec 31, 2020

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!
@matthewseaman
Copy link
Collaborator

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.

@MaxDesiatov
Copy link

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.

@matthewseaman
Copy link
Collaborator

matthewseaman commented Aug 10, 2021

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

@MaxDesiatov
Copy link

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?

@henkvanderspek
Copy link

henkvanderspek commented Jan 21, 2022

Same problem for me. Any suggestions @matthewseaman?

Screenshot 2022-01-21 at 16 37 18

@MaxDesiatov
Copy link

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

@henkvanderspek
Copy link

henkvanderspek commented Jan 21, 2022

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
Copy link

Do i need to use LLVM 11 instead?

@MaxDesiatov
Copy link

MaxDesiatov commented Jan 21, 2022

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
Copy link

MaxDesiatov commented Jan 21, 2022

master branch and 0.8.0 release need LLVM 11, while #238 somewhat works with LLVM 13, but with disabled JIT.

@henkvanderspek
Copy link

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 😄

@MaxDesiatov
Copy link

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

@henkvanderspek
Copy link

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

@henkvanderspek
Copy link

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.

@MaxDesiatov
Copy link

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 🙂

@henkvanderspek
Copy link

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
Copy link

It does give more info. But still strange.

@henkvanderspek
Copy link

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

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

4 participants