Skip to content

Conversation

@rcook
Copy link
Contributor

@rcook rcook commented Aug 20, 2016

This adds setup-time auto-detection of libclang headers and libraries on Linux, Mac OS X and Windows. It also adds a new "development guide" with setup and build instructions.


getRecursiveContents :: FilePath -> IO [FilePath]
getRecursiveContents dir = do
allNames <- getDirectoryContents dir `catch` (\e -> if isPermissionError e then return [] else throw e)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getDirectoryContents also contains . and .., so this recurses forever. Also, this seems like a very expensive way to find libclang... I think it would be better to check the usual suspect locations (/usr/(local/)?lib/llvm-\d+(.\d+)*) and for other cases let the user set the environment variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code at line 60 filters out . and ... It's probably not the most efficient way to locate the libraries but it seems to work pretty well on the different Linux distros I tested against (Centos and Ubuntu) as well as on Windows and OS X without any special cases required. It also only impacts the initial configure step and, so, the overhead doesn't impact every invocation of stack build. It also has the advantage that I've already thoroughly tested it on two Linuxes, Windows and OS X!

…and extra-lib-dirs

Also updates README with setup and build instructions for Linux, OS X
and Windows platforms.
@chpatrick
Copy link
Owner

Hi Richard,

For me it uses up all my memory and freezes my computer (see attached htop). :(

clang_pure_setup

I'm not very comfortable with enumerating every file in /usr. We have a largish non-clang related project at work and the initial stack build already takes way too long. Think about continuous integration - you often have to build from scratch and if it takes minutes longer to get your results because of clang-pure, it's really annoying.

I'm glad to hear that you tested it widely, but could you tell me where Setup.hs found libclang in the tests you performed? If they were all in predictable locations then I would much rather just check those and leave unusual ones up to the user. As far as I know, that's how almost all packages do it (Haskell or otherwise).

@chpatrick
Copy link
Owner

chpatrick commented Aug 22, 2016

Ah, I have a solution! The llvm-config command prints out the relevant directories.

chpatrick@obsidian:~$ llvm-config-3.8 --prefix
/usr/lib/llvm-3.8
chpatrick@obsidian:~$ llvm-config-3.8 --includedir
/usr/lib/llvm-3.8/include

Here's how they do it with CMake: https://github.com/Andersbakken/rtags/blob/master/cmake/FindLibClang.cmake

@chpatrick
Copy link
Owner

This works for me: 17b05bf

What do you think? Does it work on Windows?

@rcook
Copy link
Contributor Author

rcook commented Aug 22, 2016

Ouch! Sorry about freezing your computer!

Here is a summary of the install locations for the libclang library and primary header Index.h:

Centos 7 (clang-devel package installed via yum)

  • /usr/lib64/llvm/libclang.so
  • /usr/include/clang-c/Index.h

Ubuntu 14.04 (libclang-dev package installed via apt-get)

  • /usr/lib/llvm-3.4/lib/libclang.so
  • /usr/lib/llvm-3.4/include/clang-c/Index.h

Windows (LLVM 3.8.1 installed using LLVM .exe installer)

  • C:\Program Files\LLVM\bin\libclang.dll
  • C:\Program Files\LLVM\include\clang-c\Index.h

Mac OS X (llvm38 package installed via Homebrew)

  • /usr/local/Cellar/llvm38/3.8.0/lib/llvm-3.8/lib/libclang.dylib
  • /usr/local/Cellar/llvm38/3.8.0/lib/llvm-3.8/include/clang-c/Index.h

I'll test your suggested fix and get back to you with more updates. I like the llvm-config approach with environment variable overrides.

@chpatrick
Copy link
Owner

Hi Richard,

I've merged the llvm-config version, since it seems to work on OSX and Linux on Travis. If there are any problems let's fix them in another PR.

Thanks for your help!

@chpatrick chpatrick closed this Aug 23, 2016
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

Successfully merging this pull request may close these issues.

2 participants